From f184332c09c851faac50f598d29ebe4426e05464 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 9 May 2020 13:34:47 +0100 Subject: BREAKING(std): reorganization (#5087) * Prepend underscores to private modules * Remove collectUint8Arrays() It would be a misuse of Deno.iter()'s result. * Move std/_util/async.ts to std/async * Move std/util/sha*.ts to std/hash --- std/io/_iotest.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ std/io/bufio_test.ts | 2 +- std/io/iotest.ts | 53 ---------------------------------------------------- 3 files changed, 54 insertions(+), 54 deletions(-) create mode 100644 std/io/_iotest.ts delete mode 100644 std/io/iotest.ts (limited to 'std/io') diff --git a/std/io/_iotest.ts b/std/io/_iotest.ts new file mode 100644 index 000000000..a309fb5e1 --- /dev/null +++ b/std/io/_iotest.ts @@ -0,0 +1,53 @@ +// Ported to Deno from +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +type Reader = Deno.Reader; + +/** OneByteReader returns a Reader that implements + * each non-empty Read by reading one byte from r. + */ +export class OneByteReader implements Reader { + constructor(readonly r: Reader) {} + + read(p: Uint8Array): Promise { + if (p.byteLength === 0) { + return Promise.resolve(0); + } + if (!(p instanceof Uint8Array)) { + throw Error("expected Uint8Array"); + } + return Promise.resolve(this.r.read(p.subarray(0, 1))); + } +} + +/** HalfReader returns a Reader that implements Read + * by reading half as many requested bytes from r. + */ +export class HalfReader implements Reader { + constructor(readonly r: Reader) {} + + read(p: Uint8Array): Promise { + if (!(p instanceof Uint8Array)) { + throw Error("expected Uint8Array"); + } + const half = Math.floor((p.byteLength + 1) / 2); + return Promise.resolve(this.r.read(p.subarray(0, half))); + } +} + +/** TimeoutReader returns `Deno.errors.TimedOut` on the second read + * with no data. Subsequent calls to read succeed. + */ +export class TimeoutReader implements Reader { + count = 0; + constructor(readonly r: Reader) {} + + read(p: Uint8Array): Promise { + this.count++; + if (this.count === 2) { + throw new Deno.errors.TimedOut(); + } + return Promise.resolve(this.r.read(p)); + } +} diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index 17cc873fd..c49023814 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -15,7 +15,7 @@ import { readStringDelim, readLines, } from "./bufio.ts"; -import * as iotest from "./iotest.ts"; +import * as iotest from "./_iotest.ts"; import { charCode, copyBytes, stringsReader } from "./util.ts"; const encoder = new TextEncoder(); diff --git a/std/io/iotest.ts b/std/io/iotest.ts deleted file mode 100644 index a309fb5e1..000000000 --- a/std/io/iotest.ts +++ /dev/null @@ -1,53 +0,0 @@ -// Ported to Deno from -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. -type Reader = Deno.Reader; - -/** OneByteReader returns a Reader that implements - * each non-empty Read by reading one byte from r. - */ -export class OneByteReader implements Reader { - constructor(readonly r: Reader) {} - - read(p: Uint8Array): Promise { - if (p.byteLength === 0) { - return Promise.resolve(0); - } - if (!(p instanceof Uint8Array)) { - throw Error("expected Uint8Array"); - } - return Promise.resolve(this.r.read(p.subarray(0, 1))); - } -} - -/** HalfReader returns a Reader that implements Read - * by reading half as many requested bytes from r. - */ -export class HalfReader implements Reader { - constructor(readonly r: Reader) {} - - read(p: Uint8Array): Promise { - if (!(p instanceof Uint8Array)) { - throw Error("expected Uint8Array"); - } - const half = Math.floor((p.byteLength + 1) / 2); - return Promise.resolve(this.r.read(p.subarray(0, half))); - } -} - -/** TimeoutReader returns `Deno.errors.TimedOut` on the second read - * with no data. Subsequent calls to read succeed. - */ -export class TimeoutReader implements Reader { - count = 0; - constructor(readonly r: Reader) {} - - read(p: Uint8Array): Promise { - this.count++; - if (this.count === 2) { - throw new Deno.errors.TimedOut(); - } - return Promise.resolve(this.r.read(p)); - } -} -- cgit v1.2.3