aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-02-10 03:04:36 +0200
committerGravatar GitHub <noreply@github.com> 2023-02-09 17:04:36 -0800
commit2abfa8abd2ed620986c7483c3fb8cc1bd1730f4f (patch)
tree0ac0794e7898a6ee6d94a2ce4a19bbc7d01581ec /test
parentad9d4fb0c41c1fe79e29a0fff18084937b2d8a2d (diff)
downloadbun-2abfa8abd2ed620986c7483c3fb8cc1bd1730f4f.tar.gz
bun-2abfa8abd2ed620986c7483c3fb8cc1bd1730f4f.tar.zst
bun-2abfa8abd2ed620986c7483c3fb8cc1bd1730f4f.zip
[streams] fix byte accounting (#2029)
fixes #1939
Diffstat (limited to 'test')
-rw-r--r--test/bun.js/streams.test.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/bun.js/streams.test.js b/test/bun.js/streams.test.js
index 253e4d2f2..7ae49db40 100644
--- a/test/bun.js/streams.test.js
+++ b/test/bun.js/streams.test.js
@@ -1,8 +1,9 @@
import { file, readableStreamToArrayBuffer, readableStreamToArray, readableStreamToText } from "bun";
import { expect, it, beforeEach, afterEach, describe } from "bun:test";
import { mkfifo } from "mkfifo";
-import { unlinkSync, writeFileSync } from "node:fs";
+import { realpathSync, unlinkSync, writeFileSync } from "node:fs";
import { join } from "node:path";
+import { tmpdir } from "os";
import { gc } from "./gc";
beforeEach(() => gc());
@@ -610,3 +611,20 @@ it("Blob.stream() -> new Response(stream).text()", async () => {
const text = await new Response(stream).text();
expect(text).toBe("abdefgh");
});
+
+it("Bun.file().stream() read text from large file", async () => {
+ const hugely = "HELLO!".repeat(1024 * 1024 * 10);
+ const tmpfile = join(realpathSync(tmpdir()), "bun-streams-test.txt");
+ writeFileSync(tmpfile, hugely);
+ try {
+ const chunks = [];
+ for await (const chunk of Bun.file(tmpfile).stream()) {
+ chunks.push(chunk);
+ }
+ const output = Buffer.concat(chunks).toString();
+ expect(output).toHaveLength(hugely.length);
+ expect(output).toBe(hugely);
+ } finally {
+ unlinkSync(tmpfile);
+ }
+});