diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-06-06 10:37:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-06 10:37:52 -0400 |
commit | 1a2f88609b3e1bc27790c77331ac96b423625eb6 (patch) | |
tree | d950e2cb4aaafc459b16d4f9333b2c29d7adbcc4 /std/io/readers.ts | |
parent | 78333f0ab3614e8dbd3dfdc95e9dbb53f80ffe5d (diff) |
fix(std/io): StringReader implementation (#6148)
Diffstat (limited to 'std/io/readers.ts')
-rw-r--r-- | std/io/readers.ts | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/std/io/readers.ts b/std/io/readers.ts index 201b87cd8..d43655263 100644 --- a/std/io/readers.ts +++ b/std/io/readers.ts @@ -7,22 +7,12 @@ type Reader = Deno.Reader; import { encode } from "../encoding/utf8.ts"; +const { Buffer } = Deno; /** Reader utility for strings */ -export class StringReader implements Reader { - private offs = 0; - private buf = new Uint8Array(encode(this.s)); - - constructor(private readonly s: string) {} - - read(p: Uint8Array): Promise<number | null> { - const n = Math.min(p.byteLength, this.buf.byteLength - this.offs); - p.set(this.buf.slice(this.offs, this.offs + n)); - this.offs += n; - if (n === 0) { - return Promise.resolve(null); - } - return Promise.resolve(n); +export class StringReader extends Buffer { + constructor(private readonly s: string) { + super(encode(s).buffer); } } |