mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
feat: expose writeAll() and writeAllSync() (#2298)
Symmetric with `readAll()` and `readAllSync()`. Also used in `xeval`. Also correct usage in `writeFile()`/`writeFileSync()`.
This commit is contained in:
parent
70de8dd51d
commit
e49d1e16ca
5 changed files with 46 additions and 17 deletions
18
js/buffer.ts
18
js/buffer.ts
|
@ -274,3 +274,21 @@ export function readAllSync(r: SyncReader): Uint8Array {
|
|||
buf.readFromSync(r);
|
||||
return buf.bytes();
|
||||
}
|
||||
|
||||
/** Write all the content of `arr` to `w`.
|
||||
*/
|
||||
export async function writeAll(w: Writer, arr: Uint8Array): Promise<void> {
|
||||
let nwritten = 0;
|
||||
while (nwritten < arr.length) {
|
||||
nwritten += await w.write(arr.subarray(nwritten));
|
||||
}
|
||||
}
|
||||
|
||||
/** Write synchronously all the content of `arr` to `w`.
|
||||
*/
|
||||
export function writeAllSync(w: SyncWriter, arr: Uint8Array): void {
|
||||
let nwritten = 0;
|
||||
while (nwritten < arr.length) {
|
||||
nwritten += w.writeSync(arr.subarray(nwritten));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue