summaryrefslogtreecommitdiff
path: root/cli/js/io.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-04-25 00:05:48 +0200
committerGitHub <noreply@github.com>2020-04-25 00:05:48 +0200
commite9fa6b87cea7f564d69f2918b4811a570a770f73 (patch)
tree9e64954b29a53bc2de1d7f95f8ba6afc7c327155 /cli/js/io.ts
parent824329f0daa4dfada11ccc4c15a7db6c1886c45f (diff)
stabilize Deno.iter() and Deno.iterSync() (#4890)
Diffstat (limited to 'cli/js/io.ts')
-rw-r--r--cli/js/io.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/cli/js/io.ts b/cli/js/io.ts
index 023718100..d41914d34 100644
--- a/cli/js/io.ts
+++ b/cli/js/io.ts
@@ -6,6 +6,8 @@
export const EOF: unique symbol = Symbol("EOF");
export type EOF = typeof EOF;
+const DEFAULT_BUFFER_SIZE = 32 * 1024;
+
// Seek whence values.
// https://golang.org/pkg/io/#pkg-constants
export enum SeekMode {
@@ -71,7 +73,7 @@ export interface ReadWriteSeeker extends Reader, Writer, Seeker {}
// https://golang.org/pkg/io/#Copy
export async function copy(dst: Writer, src: Reader): Promise<number> {
let n = 0;
- const b = new Uint8Array(32 * 1024);
+ const b = new Uint8Array(DEFAULT_BUFFER_SIZE);
let gotEOF = false;
while (gotEOF === false) {
const result = await src.read(b);
@@ -86,9 +88,12 @@ export async function copy(dst: Writer, src: Reader): Promise<number> {
export async function* iter(
r: Reader,
- bufSize?: number
+ options?: {
+ bufSize?: number;
+ }
): AsyncIterableIterator<Uint8Array> {
- const b = new Uint8Array(bufSize ?? 1024);
+ const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
+ const b = new Uint8Array(bufSize);
while (true) {
const result = await r.read(b);
if (result === EOF) {
@@ -101,9 +106,12 @@ export async function* iter(
export function* iterSync(
r: SyncReader,
- bufSize?: number
+ options?: {
+ bufSize?: number;
+ }
): IterableIterator<Uint8Array> {
- const b = new Uint8Array(bufSize ?? 1024);
+ const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
+ const b = new Uint8Array(bufSize);
while (true) {
const result = r.readSync(b);
if (result === EOF) {