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

Function testWritev

test/parallel/test-stream-iter-writable-interop.js:286–311  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

284// =============================================================================
285
286async function testWritev() {
287 const chunks = [];
288 const writable = new Writable({
289 highWaterMark: 1024,
290 write(chunk, encoding, cb) {
291 chunks.push(Buffer.from(chunk));
292 cb();
293 },
294 writev(entries, cb) {
295 for (const { chunk } of entries) {
296 chunks.push(Buffer.from(chunk));
297 }
298 cb();
299 },
300 });
301
302 const writer = fromWritable(writable, { backpressure: 'block' });
303 await writer.writev([
304 new TextEncoder().encode('hello'),
305 new TextEncoder().encode(' '),
306 new TextEncoder().encode('world'),
307 ]);
308 await writer.end();
309
310 assert.strictEqual(Buffer.concat(chunks).toString(), 'hello world');
311}
312
313// =============================================================================
314// writeSync / writevSync always return false

Calls 6

fromWritableFunction · 0.85
encodeMethod · 0.80
concatMethod · 0.80
writevMethod · 0.45
endMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected