Add buffer size argument to copy (#4907)

This commit is contained in:
Marcos Casagrande 2020-04-26 22:25:24 +02:00 committed by GitHub
parent f7d1f82796
commit 26dfd3c110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 3 deletions

View file

@ -70,9 +70,16 @@ export interface ReadWriteCloser extends Reader, Writer, Closer {}
// https://golang.org/pkg/io/#ReadWriteSeeker
export interface ReadWriteSeeker extends Reader, Writer, Seeker {}
export async function copy(src: Reader, dst: Writer): Promise<number> {
export async function copy(
src: Reader,
dst: Writer,
options?: {
bufSize?: number;
}
): Promise<number> {
let n = 0;
const b = new Uint8Array(DEFAULT_BUFFER_SIZE);
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
const b = new Uint8Array(bufSize);
let gotEOF = false;
while (gotEOF === false) {
const result = await src.read(b);