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
|
@ -5,7 +5,7 @@
|
|||
// https://github.com/golang/go/blob/master/LICENSE
|
||||
import { assertEquals, test } from "./test_util.ts";
|
||||
|
||||
const { Buffer, readAll, readAllSync } = Deno;
|
||||
const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;
|
||||
type Buffer = Deno.Buffer;
|
||||
|
||||
// N controls how many iterations of certain checks are performed.
|
||||
|
@ -253,3 +253,25 @@ test(function testReadAllSync(): void {
|
|||
assertEquals(testBytes[i], actualBytes[i]);
|
||||
}
|
||||
});
|
||||
|
||||
test(async function testWriteAll(): Promise<void> {
|
||||
init();
|
||||
const writer = new Buffer();
|
||||
await writeAll(writer, testBytes);
|
||||
const actualBytes = writer.bytes();
|
||||
assertEquals(testBytes.byteLength, actualBytes.byteLength);
|
||||
for (let i = 0; i < testBytes.length; ++i) {
|
||||
assertEquals(testBytes[i], actualBytes[i]);
|
||||
}
|
||||
});
|
||||
|
||||
test(function testWriteAllSync(): void {
|
||||
init();
|
||||
const writer = new Buffer();
|
||||
writeAllSync(writer, testBytes);
|
||||
const actualBytes = writer.bytes();
|
||||
assertEquals(testBytes.byteLength, actualBytes.byteLength);
|
||||
for (let i = 0; i < testBytes.length; ++i) {
|
||||
assertEquals(testBytes[i], actualBytes[i]);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue