mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix: bug in Deno.copy (#4977)
This commit is contained in:
parent
640f6878f6
commit
0703431ec2
2 changed files with 21 additions and 1 deletions
|
@ -65,7 +65,11 @@ export async function copy(
|
|||
if (result === null) {
|
||||
gotEOF = true;
|
||||
} else {
|
||||
n += await dst.write(b.subarray(0, result));
|
||||
let nwritten = 0;
|
||||
while (nwritten < result) {
|
||||
nwritten += await dst.write(b.subarray(nwritten, result));
|
||||
}
|
||||
n += nwritten;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue