1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

Increase copyN buffer size to match go implementation (#4904)

This commit is contained in:
Marcos Casagrande 2020-04-26 22:29:51 +02:00 committed by GitHub
parent 49cad79fb1
commit 128dce0d8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,8 @@ type Reader = Deno.Reader;
type Writer = Deno.Writer;
import { assert } from "../testing/asserts.ts";
const DEFAULT_BUFFER_SIZE = 32 * 1024;
/** copy N size at the most.
* If read size is lesser than N, then returns nread
* */
@ -13,9 +15,9 @@ export async function copyN(
size: number
): Promise<number> {
let bytesRead = 0;
let buf = new Uint8Array(1024);
let buf = new Uint8Array(DEFAULT_BUFFER_SIZE);
while (bytesRead < size) {
if (size - bytesRead < 1024) {
if (size - bytesRead < DEFAULT_BUFFER_SIZE) {
buf = new Uint8Array(size - bytesRead);
}
const result = await r.read(buf);