deno.land / std@0.166.0 / node / _tools / test / parallel / test-stream-uint8array.js

test-stream-uint8array.js
نووسراو ببینە
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// deno-fmt-ignore-file// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.// Taken from Node 18.12.0// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
'use strict';const common = require('../common');const assert = require('assert');
const { Readable, Writable } = require('stream');
const ABC = new Uint8Array([0x41, 0x42, 0x43]);const DEF = new Uint8Array([0x44, 0x45, 0x46]);const GHI = new Uint8Array([0x47, 0x48, 0x49]);
{ // Simple Writable test.
let n = 0; const writable = new Writable({ write: common.mustCall((chunk, encoding, cb) => { assert(chunk instanceof Buffer); if (n++ === 0) { assert.strictEqual(String(chunk), 'ABC'); } else { assert.strictEqual(String(chunk), 'DEF'); }
cb(); }, 2) });
writable.write(ABC); writable.end(DEF);}
{ // Writable test, pass in Uint8Array in object mode.
const writable = new Writable({ objectMode: true, write: common.mustCall((chunk, encoding, cb) => { assert(!(chunk instanceof Buffer)); assert(chunk instanceof Uint8Array); assert.strictEqual(chunk, ABC); assert.strictEqual(encoding, 'utf8'); cb(); }) });
writable.end(ABC);}
{ // Writable test, multiple writes carried out via writev. let callback;
const writable = new Writable({ write: common.mustCall((chunk, encoding, cb) => { assert(chunk instanceof Buffer); assert.strictEqual(encoding, 'buffer'); assert.strictEqual(String(chunk), 'ABC'); callback = cb; }), writev: common.mustCall((chunks, cb) => { assert.strictEqual(chunks.length, 2); assert.strictEqual(chunks[0].encoding, 'buffer'); assert.strictEqual(chunks[1].encoding, 'buffer'); assert.strictEqual(chunks[0].chunk + chunks[1].chunk, 'DEFGHI'); }) });
writable.write(ABC); writable.write(DEF); writable.end(GHI); callback();}
{ // Simple Readable test. const readable = new Readable({ read() {} });
readable.push(DEF); readable.unshift(ABC);
const buf = readable.read(); assert(buf instanceof Buffer); assert.deepStrictEqual([...buf], [...ABC, ...DEF]);}
{ // Readable test, setEncoding. const readable = new Readable({ read() {} });
readable.setEncoding('utf8');
readable.push(DEF); readable.unshift(ABC);
const out = readable.read(); assert.strictEqual(out, 'ABCDEF');}
std

Version Info

Tagged at
a year ago