From 2abfa8abd2ed620986c7483c3fb8cc1bd1730f4f Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 10 Feb 2023 03:04:36 +0200 Subject: [streams] fix byte accounting (#2029) fixes #1939 --- test/bun.js/streams.test.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'test/bun.js/streams.test.js') 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); + } +}); -- cgit v1.2.3