Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Dec 28, 2024
1 parent 75e5036 commit 2576008
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/bun.js/webcore/streams.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4762,6 +4762,9 @@ pub const ByteStream = struct {
size_hint: Blob.SizeType = 0,
buffer_action: ?BufferAction = null,


const log = Output.scoped(.ByteStream, false);

const BufferAction = union(BufferedReadableStreamAction) {
text: JSC.JSPromise.Strong,
arrayBuffer: JSC.JSPromise.Strong,
Expand Down Expand Up @@ -4867,6 +4870,9 @@ pub const ByteStream = struct {
if (stream == .owned_and_done) allocator.free(stream.owned_and_done.slice());
}
this.has_received_last_chunk = stream.isDone();

log("ByteStream.onData already done... do nothing", .{});

return;
}

Expand All @@ -4889,6 +4895,9 @@ pub const ByteStream = struct {
this.buffer_action = null;
}

log("ByteStream.onData err action.reject()", .{});


action.reject(stream.err);
return;
}
Expand All @@ -4899,11 +4908,15 @@ pub const ByteStream = struct {
}

if (this.buffer.capacity == 0 and stream == .done) {
log("ByteStream.onData done and action.fulfill()", .{});

var blob = this.toAnyBlob().?;
action.fulfill(&blob);
return;
}
if (this.buffer.capacity == 0 and stream == .owned_and_done) {
log("ByteStream.onData owned_and_done and action.fulfill()", .{});

this.buffer = std.ArrayList(u8).fromOwnedSlice(bun.default_allocator, @constCast(chunk));
var blob = this.toAnyBlob().?;
action.fulfill(&blob);
Expand All @@ -4914,10 +4927,12 @@ pub const ByteStream = struct {
allocator.free(stream.slice());
}
}
log("ByteStream.onData appendSlice and action.fulfill()", .{});

this.buffer.appendSlice(chunk) catch bun.outOfMemory();
var blob = this.toAnyBlob().?;
action.fulfill(&blob);

return;
} else {
this.buffer.appendSlice(chunk) catch bun.outOfMemory();
Expand Down Expand Up @@ -4974,10 +4989,16 @@ pub const ByteStream = struct {
if (remaining.len > 0 and chunk.len > 0)
this.append(stream, to_copy.len, chunk, allocator) catch @panic("Out of memory while copying request body");

log("ByteStream.onData pending.run()", .{});

this.pending.run();

return;
}

log("ByteStream.onData no action just append", .{});


this.append(stream, 0, chunk, allocator) catch @panic("Out of memory while copying request body");
}

Expand Down
3 changes: 1 addition & 2 deletions test/js/bun/s3/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ describe.skipIf(!s3Options.accessKeyId)("s3", () => {
expect(bytes).toBe(10);
expect(Buffer.concat(chunks)).toEqual(Buffer.from("Hello Bun!"));
});

it("should work with large files", async () => {
it("should work with large files ", async () => {
const s3file = s3(tmp_filename + "-readable-stream-big", options);
await s3file.write(bigishPayload);
const stream = s3file.stream();
Expand Down

0 comments on commit 2576008

Please sign in to comment.