MCPcopy Index your code
hub / github.com/nodejs/node / testWithTransform

Function testWithTransform

test/parallel/test-stream-iter-readable-interop.js:191–213  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

189// =============================================================================
190
191async function testWithTransform() {
192 const readable = new Readable({
193 read() {
194 this.push(Buffer.from('hello'));
195 this.push(null);
196 },
197 });
198
199 // Uppercase transform
200 function uppercase(chunks) {
201 if (chunks === null) return null;
202 return chunks.map((c) => {
203 const buf = Buffer.from(c);
204 for (let i = 0; i < buf.length; i++) {
205 if (buf[i] >= 97 && buf[i] <= 122) buf[i] -= 32;
206 }
207 return buf;
208 });
209 }
210
211 const result = await text(pull(readable, uppercase));
212 assert.strictEqual(result, 'HELLO');
213}
214
215// =============================================================================
216// Object-mode Readable: strings are normalized to Uint8Array

Calls 2

pullFunction · 0.70
textFunction · 0.50

Tested by

no test coverage detected