summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-06-10 23:54:54 +0800
committerGitHub <noreply@github.com>2020-06-10 11:54:54 -0400
commitbe8bacaaa4258089e5a0cf4f1d8f53db8e534d4b (patch)
tree46a0729ad95cbb5b6f7aab4c6008adde257c2451 /cli/js
parent54c3f8e27fa1f38a3e2d65c2b297c415062d01c8 (diff)
fix: Remove try-catch from Buffer.readFrom, readFromSync (#6161)
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/buffer.ts36
1 files changed, 14 insertions, 22 deletions
diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts
index 8389db4f9..473affe3d 100644
--- a/cli/js/buffer.ts
+++ b/cli/js/buffer.ts
@@ -158,38 +158,30 @@ export class Buffer implements Reader, ReaderSync, Writer, WriterSync {
async readFrom(r: Reader): Promise<number> {
let n = 0;
while (true) {
- try {
- const i = this.#grow(MIN_READ);
- this.#reslice(i);
- const fub = new Uint8Array(this.#buf.buffer, i);
- const nread = await r.read(fub);
- if (nread === null) {
- return n;
- }
- this.#reslice(i + nread);
- n += nread;
- } catch (e) {
+ const i = this.#grow(MIN_READ);
+ this.#reslice(i);
+ const fub = new Uint8Array(this.#buf.buffer, i);
+ const nread = await r.read(fub);
+ if (nread === null) {
return n;
}
+ this.#reslice(i + nread);
+ n += nread;
}
}
readFromSync(r: ReaderSync): number {
let n = 0;
while (true) {
- try {
- const i = this.#grow(MIN_READ);
- this.#reslice(i);
- const fub = new Uint8Array(this.#buf.buffer, i);
- const nread = r.readSync(fub);
- if (nread === null) {
- return n;
- }
- this.#reslice(i + nread);
- n += nread;
- } catch (e) {
+ const i = this.#grow(MIN_READ);
+ this.#reslice(i);
+ const fub = new Uint8Array(this.#buf.buffer, i);
+ const nread = r.readSync(fub);
+ if (nread === null) {
return n;
}
+ this.#reslice(i + nread);
+ n += nread;
}
}
}