mirror of
https://github.com/denoland/deno.git
synced 2025-07-24 13:44:08 +00:00
fix: Remove try-catch from Buffer.readFrom, readFromSync (#6161)
This commit is contained in:
parent
54c3f8e27f
commit
be8bacaaa4
3 changed files with 23 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue