From 0703431ec23efbde59669cc0568ec740909e47d7 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Wed, 29 Apr 2020 03:30:48 +0200 Subject: fix: bug in Deno.copy (#4977) --- cli/js/tests/io_test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cli/js/tests') diff --git a/cli/js/tests/io_test.ts b/cli/js/tests/io_test.ts index d6d6e35d1..0ccd83ea2 100644 --- a/cli/js/tests/io_test.ts +++ b/cli/js/tests/io_test.ts @@ -55,3 +55,19 @@ unitTest(async function copyWithCustomBufferSize() { assertEquals(write.length, xBytes.length); assertEquals(readSpy.calls, DEFAULT_BUF_SIZE / bufSize + 1); }); + +unitTest({ perms: { write: true } }, async function copyBufferToFile() { + const filePath = "test-file.txt"; + // bigger than max File possible buffer 16kb + const bufSize = 32 * 1024; + const xBytes = repeat("b", bufSize); + const reader = new Deno.Buffer(xBytes.buffer as ArrayBuffer); + const write = await Deno.open(filePath, { write: true, create: true }); + + const n = await Deno.copy(reader, write, { bufSize }); + + assertEquals(n, xBytes.length); + + write.close(); + await Deno.remove(filePath); +}); -- cgit v1.2.3