11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { Readable, Writable } = require('stream'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// This test ensures that if have 'readable' listener 81cb0ef41Sopenharmony_ci// on Readable instance it will not disrupt the pipe. 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci{ 111cb0ef41Sopenharmony_ci let receivedData = ''; 121cb0ef41Sopenharmony_ci const w = new Writable({ 131cb0ef41Sopenharmony_ci write: (chunk, env, callback) => { 141cb0ef41Sopenharmony_ci receivedData += chunk; 151cb0ef41Sopenharmony_ci callback(); 161cb0ef41Sopenharmony_ci }, 171cb0ef41Sopenharmony_ci }); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci const data = ['foo', 'bar', 'baz']; 201cb0ef41Sopenharmony_ci const r = new Readable({ 211cb0ef41Sopenharmony_ci read: () => {}, 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci r.once('readable', common.mustCall()); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci r.pipe(w); 271cb0ef41Sopenharmony_ci r.push(data[0]); 281cb0ef41Sopenharmony_ci r.push(data[1]); 291cb0ef41Sopenharmony_ci r.push(data[2]); 301cb0ef41Sopenharmony_ci r.push(null); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci w.on('finish', common.mustCall(() => { 331cb0ef41Sopenharmony_ci assert.strictEqual(receivedData, data.join('')); 341cb0ef41Sopenharmony_ci })); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci{ 381cb0ef41Sopenharmony_ci let receivedData = ''; 391cb0ef41Sopenharmony_ci const w = new Writable({ 401cb0ef41Sopenharmony_ci write: (chunk, env, callback) => { 411cb0ef41Sopenharmony_ci receivedData += chunk; 421cb0ef41Sopenharmony_ci callback(); 431cb0ef41Sopenharmony_ci }, 441cb0ef41Sopenharmony_ci }); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci const data = ['foo', 'bar', 'baz']; 471cb0ef41Sopenharmony_ci const r = new Readable({ 481cb0ef41Sopenharmony_ci read: () => {}, 491cb0ef41Sopenharmony_ci }); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci r.pipe(w); 521cb0ef41Sopenharmony_ci r.push(data[0]); 531cb0ef41Sopenharmony_ci r.push(data[1]); 541cb0ef41Sopenharmony_ci r.push(data[2]); 551cb0ef41Sopenharmony_ci r.push(null); 561cb0ef41Sopenharmony_ci r.once('readable', common.mustCall()); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci w.on('finish', common.mustCall(() => { 591cb0ef41Sopenharmony_ci assert.strictEqual(receivedData, data.join('')); 601cb0ef41Sopenharmony_ci })); 611cb0ef41Sopenharmony_ci} 62