diff options
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); } } |