11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst { Readable } = require('stream'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// Make sure that readable completes 61cb0ef41Sopenharmony_ci// even when reading larger buffer. 71cb0ef41Sopenharmony_ciconst bufferSize = 10 * 1024 * 1024; 81cb0ef41Sopenharmony_cilet n = 0; 91cb0ef41Sopenharmony_ciconst r = new Readable({ 101cb0ef41Sopenharmony_ci read() { 111cb0ef41Sopenharmony_ci // Try to fill readable buffer piece by piece. 121cb0ef41Sopenharmony_ci r.push(Buffer.alloc(bufferSize / 10)); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci if (n++ > 10) { 151cb0ef41Sopenharmony_ci r.push(null); 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci}); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cir.on('readable', () => { 211cb0ef41Sopenharmony_ci while (true) { 221cb0ef41Sopenharmony_ci const ret = r.read(bufferSize); 231cb0ef41Sopenharmony_ci if (ret === null) 241cb0ef41Sopenharmony_ci break; 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci}); 271cb0ef41Sopenharmony_cir.on('end', common.mustCall()); 28