mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 11:59:00 +00:00
fix large stdout output (#2850)
* fix large stdout output * remove skip from #2674 for testing * add big stdout test using spawnSync * add bunEnv on big stdout test
This commit is contained in:
@@ -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 {
|
||||
|
||||
2
test/js/bun/io/big-stdout.js
Normal file
2
test/js/bun/io/big-stdout.js
Normal file
@@ -0,0 +1,2 @@
|
||||
const str = "a".repeat(300000);
|
||||
await Bun.write(Bun.stdout, str);
|
||||
@@ -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("<div><blink>it worked!</blink></div>");
|
||||
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user