Skip to content

Commit

Permalink
node:zlib: move deflate and gzip into native code (#11770)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
nektro and Jarred-Sumner authored Sep 7, 2024
1 parent 1458fcc commit 8cd515f
Show file tree
Hide file tree
Showing 43 changed files with 3,954 additions and 4,785 deletions.
3 changes: 3 additions & 0 deletions packages/bun-types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1918,6 +1918,9 @@ declare global {
* closely to the `BodyMixin` API.
*/
formData(): Promise<FormData>;

arrayBuffer(): Promise<ArrayBuffer>;

/**
* Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes) its the same as `new Uint8Array(await blob.arrayBuffer())`
*/
Expand Down
2 changes: 2 additions & 0 deletions scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ async function runTests() {
reportOutputToGitHubAction("failing_tests", markdown);
}

if (!isCI) console.log("-------");
if (!isCI) console.log("passing", results.length - failedTests.length, "/", results.length);
return results;
}

Expand Down
17 changes: 14 additions & 3 deletions src/brotli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,28 @@ pub const BrotliCompressionStream = struct {
state: State = State.Inflating,
total_out: usize = 0,
total_in: usize = 0,

pub fn init() !BrotliCompressionStream {
flushOp: BrotliEncoder.Operation,
finishFlushOp: BrotliEncoder.Operation,
fullFlushOp: BrotliEncoder.Operation,

pub fn init(
flushOp: BrotliEncoder.Operation,
finishFlushOp: BrotliEncoder.Operation,
fullFlushOp: BrotliEncoder.Operation,
) !BrotliCompressionStream {
const instance = BrotliEncoder.createInstance(&BrotliAllocator.alloc, &BrotliAllocator.free, null) orelse return error.BrotliFailedToCreateInstance;

return BrotliCompressionStream{
.brotli = instance,
.flushOp = flushOp,
.finishFlushOp = finishFlushOp,
.fullFlushOp = fullFlushOp,
};
}

pub fn writeChunk(this: *BrotliCompressionStream, input: []const u8, last: bool) ![]const u8 {
const result = this.brotli.compressStream(if (last) BrotliEncoder.Operation.finish else .process, input);
this.total_in += input.len;
const result = this.brotli.compressStream(if (last) this.finishFlushOp else this.flushOp, input);

if (!result.success) {
this.state = .Error;
Expand Down
63 changes: 0 additions & 63 deletions src/bun.js/api/js_brotli.classes.ts

This file was deleted.

Loading

0 comments on commit 8cd515f

Please sign in to comment.