diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-05-30 14:59:30 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-05-30 08:59:30 -0400 |
| commit | 50a79584cb12129b3db1ef3e0eb9d0c8b9f20b62 (patch) | |
| tree | ee9a90a8b8018c03b1e1a6ace07abdaa494ea90d /io | |
| parent | 80b3c486f6222f65b52eb2eca903b67312e8ce0c (diff) | |
chore: Implement strict mode (denoland/deno_std#453)
Original: https://github.com/denoland/deno_std/commit/be24677d15494e83eea2e99bfc5ccfdde31cb892
Diffstat (limited to 'io')
| -rw-r--r-- | io/bufio.ts | 10 | ||||
| -rw-r--r-- | io/writers.ts | 7 |
2 files changed, 8 insertions, 9 deletions
diff --git a/io/bufio.ts b/io/bufio.ts index 815c94eed..99b563816 100644 --- a/io/bufio.ts +++ b/io/bufio.ts @@ -40,8 +40,8 @@ export interface ReadLineResult { /** BufReader implements buffering for a Reader object. */ export class BufReader implements Reader { - private buf: Uint8Array; - private rd: Reader; // Reader provided by caller. + private buf!: Uint8Array; + private rd!: Reader; // Reader provided by caller. private r = 0; // buf read position. private w = 0; // buf write position. private eof = false; @@ -342,7 +342,7 @@ export class BufReader implements Reader { try { await this._fill(); } catch (err) { - err.partial = slice; + err.partial = slice!; throw err; } } @@ -439,7 +439,7 @@ export class BufWriter implements Writer { if (this.err !== null) throw this.err; if (this.n === 0) return; - let n: number; + let n = 0; try { n = await this.wr.write(this.buf.subarray(0, this.n)); } catch (e) { @@ -479,7 +479,7 @@ export class BufWriter implements Writer { if (p.length === 0) return 0; let nn = 0; - let n: number; + let n = 0; while (p.byteLength > this.available()) { if (this.buffered() === 0) { // Large write, empty buffer. diff --git a/io/writers.ts b/io/writers.ts index 869018728..de070d48a 100644 --- a/io/writers.ts +++ b/io/writers.ts @@ -6,6 +6,7 @@ import { decode, encode } from "../strings/mod.ts"; export class StringWriter implements Writer { private chunks: Uint8Array[] = []; private byteLength: number = 0; + private cache: string | undefined; constructor(private base: string = "") { const c = encode(base); @@ -16,12 +17,10 @@ export class StringWriter implements Writer { async write(p: Uint8Array): Promise<number> { this.chunks.push(p); this.byteLength += p.byteLength; - this.cache = null; + this.cache = undefined; return p.byteLength; } - private cache: string; - toString(): string { if (this.cache) { return this.cache; @@ -33,6 +32,6 @@ export class StringWriter implements Writer { offs += chunk.byteLength; } this.cache = decode(buf); - return this.cache; + return this.cache!; } } |
