deno.land / std@0.224.0 / io / copy_n_test.ts

copy_n_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { copyN } from "./copy_n.ts";import { Buffer } from "./buffer.ts";import { StringReader } from "./string_reader.ts";
Deno.test("testCopyN1", async function () { const w = new Buffer(); const r = new StringReader("abcdefghij"); const n = await copyN(r, w, 3); assertEquals(n, 3); assertEquals(new TextDecoder().decode(w.bytes()), "abc");});
Deno.test("testCopyN2", async function () { const w = new Buffer(); const r = new StringReader("abcdefghij"); const n = await copyN(r, w, 11); assertEquals(n, 10); assertEquals(new TextDecoder().decode(w.bytes()), "abcdefghij");});
Deno.test("copyNWriteAllData", async function () { const tmpDir = await Deno.makeTempDir(); const filepath = `${tmpDir}/data`; using file = await Deno.open(filepath, { create: true, write: true });
const size = 16 * 1024 + 1; const data = "a".repeat(32 * 1024); const r = new StringReader(data); const n = await copyN(r, file, size); // Over max file possible buffer await Deno.remove(filepath);
assertEquals(n, size);});
std

Version Info

Tagged at
6 months ago