mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 01:29:14 -05:00
57c9176b19
We need to consider the API changes here more carefully. This reverts commitda188a7d30
. and commit8569f15207
.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { assert, test } from "../testing/mod.ts";
|
|
import { MultiReader, StringReader } from "./readers.ts";
|
|
import { StringWriter } from "./writers.ts";
|
|
import { copy } from "deno";
|
|
import { copyN } from "./ioutil.ts";
|
|
import { decode } from "../strings/strings.ts";
|
|
|
|
test(async function ioStringReader() {
|
|
const r = new StringReader("abcdef");
|
|
const { nread, eof } = await r.read(new Uint8Array(6));
|
|
assert.equal(nread, 6);
|
|
assert.equal(eof, true);
|
|
});
|
|
|
|
test(async function ioStringReader() {
|
|
const r = new StringReader("abcdef");
|
|
const buf = new Uint8Array(3);
|
|
let res1 = await r.read(buf);
|
|
assert.equal(res1.nread, 3);
|
|
assert.equal(res1.eof, false);
|
|
assert.equal(decode(buf), "abc");
|
|
let res2 = await r.read(buf);
|
|
assert.equal(res2.nread, 3);
|
|
assert.equal(res2.eof, true);
|
|
assert.equal(decode(buf), "def");
|
|
});
|
|
|
|
test(async function ioMultiReader() {
|
|
const r = new MultiReader(new StringReader("abc"), new StringReader("def"));
|
|
const w = new StringWriter();
|
|
const n = await copyN(w, r, 4);
|
|
assert.equal(n, 4);
|
|
assert.equal(w.toString(), "abcd");
|
|
await copy(w, r);
|
|
assert.equal(w.toString(), "abcdef");
|
|
});
|