diff options
author | 2023-02-10 03:04:36 +0200 | |
---|---|---|
committer | 2023-02-09 17:04:36 -0800 | |
commit | 2abfa8abd2ed620986c7483c3fb8cc1bd1730f4f (patch) | |
tree | 0ac0794e7898a6ee6d94a2ce4a19bbc7d01581ec /test | |
parent | ad9d4fb0c41c1fe79e29a0fff18084937b2d8a2d (diff) | |
download | bun-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.js | 20 |
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); + } +}); |