diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 54696495a0..547dc73f15 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -1177,6 +1177,22 @@ pub const Blob = struct { return; } + if (@hasField(This, "file_store")) { + const pathlike = this.file_store.pathlike; + if (pathlike == .fd) { + this.opened_fd = pathlike.fd; + Callback(this, this.opened_fd); + return; + } + } else { + const pathlike = this.file_blob.store.?.data.file.pathlike; + if (pathlike == .fd) { + this.opened_fd = pathlike.fd; + Callback(this, this.opened_fd); + return; + } + } + if (comptime Environment.isMac) { Callback(this, this.getFdMac()); } else { diff --git a/test/js/bun/io/big-stdout.js b/test/js/bun/io/big-stdout.js new file mode 100644 index 0000000000..4719580e42 --- /dev/null +++ b/test/js/bun/io/big-stdout.js @@ -0,0 +1,2 @@ +const str = "a".repeat(300000); +await Bun.write(Bun.stdout, str); diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js index ab8063f161..120ba396d2 100644 --- a/test/js/bun/io/bun-write.test.js +++ b/test/js/bun/io/bun-write.test.js @@ -1,7 +1,7 @@ import fs from "fs"; import { it, expect, describe } from "bun:test"; import path from "path"; -import { gcTick, withoutAggressiveGC } from "harness"; +import { gcTick, withoutAggressiveGC, bunExe, bunEnv } from "harness"; import { tmpdir } from "os"; it("Bun.write blob", async () => { @@ -290,3 +290,20 @@ it.skip("Bun.write('output.html', HTMLRewriter.transform(Bun.file)))", async don expect(await Bun.file(outpath).text()).toBe("
"); done(); }); + +it("#2674", async () => { + const file = path.join(import.meta.dir, "big-stdout.js"); + + const { stderr, stdout, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "run", file], + env: bunEnv, + stderr: "pipe", + stdout: "pipe", + }); + console.log(stderr?.toString()); + const text = stdout?.toString(); + expect(text?.length).toBe(300000); + const error = stderr?.toString(); + expect(error?.length).toBeFalsy(); + expect(exitCode).toBe(0); +});