summaryrefslogtreecommitdiff
path: root/std/io/writers.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-06-12 21:15:29 +0200
committerGitHub <noreply@github.com>2020-06-12 15:15:29 -0400
commit26bf56afdaf16634ffbaa23684faf3a44cc10f62 (patch)
tree25265007d7b09bd4580659ae34d833759df745d2 /std/io/writers.ts
parent7d41bacfba6a3557066345ecd282f0d83e4a4381 (diff)
fix(std/io): BufWriter/StringWriter bug (#6247)
Diffstat (limited to 'std/io/writers.ts')
-rw-r--r--std/io/writers.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/std/io/writers.ts b/std/io/writers.ts
index 8e085c84b..d42f552e8 100644
--- a/std/io/writers.ts
+++ b/std/io/writers.ts
@@ -1,9 +1,10 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
type Writer = Deno.Writer;
+type WriterSync = Deno.WriterSync;
import { decode, encode } from "../encoding/utf8.ts";
/** Writer utility for buffering string chunks */
-export class StringWriter implements Writer {
+export class StringWriter implements Writer, WriterSync {
private chunks: Uint8Array[] = [];
private byteLength = 0;
private cache: string | undefined;
@@ -15,10 +16,14 @@ export class StringWriter implements Writer {
}
write(p: Uint8Array): Promise<number> {
+ return Promise.resolve(this.writeSync(p));
+ }
+
+ writeSync(p: Uint8Array): number {
this.chunks.push(p);
this.byteLength += p.byteLength;
this.cache = undefined;
- return Promise.resolve(p.byteLength);
+ return p.byteLength;
}
toString(): string {