11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst { Readable } = require('stream');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst { strictEqual } = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci{
81cb0ef41Sopenharmony_ci  // Strategy 2
91cb0ef41Sopenharmony_ci  const streamData = ['a', 'b', 'c', null];
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci  // Fulfill a Readable object
121cb0ef41Sopenharmony_ci  const readable = new Readable({
131cb0ef41Sopenharmony_ci    read: common.mustCall(() => {
141cb0ef41Sopenharmony_ci      process.nextTick(() => {
151cb0ef41Sopenharmony_ci        readable.push(streamData.shift());
161cb0ef41Sopenharmony_ci      });
171cb0ef41Sopenharmony_ci    }, streamData.length),
181cb0ef41Sopenharmony_ci  });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  // Use helper to convert it to a Web ReadableStream using ByteLength strategy
211cb0ef41Sopenharmony_ci  const readableStream = Readable.toWeb(readable, {
221cb0ef41Sopenharmony_ci    strategy: new ByteLengthQueuingStrategy({ highWaterMark: 1 }),
231cb0ef41Sopenharmony_ci  });
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  assert(!readableStream.locked);
261cb0ef41Sopenharmony_ci  readableStream.getReader().read().then(common.mustCall());
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci{
301cb0ef41Sopenharmony_ci  // Strategy 2
311cb0ef41Sopenharmony_ci  const streamData = ['a', 'b', 'c', null];
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  // Fulfill a Readable object
341cb0ef41Sopenharmony_ci  const readable = new Readable({
351cb0ef41Sopenharmony_ci    read: common.mustCall(() => {
361cb0ef41Sopenharmony_ci      process.nextTick(() => {
371cb0ef41Sopenharmony_ci        readable.push(streamData.shift());
381cb0ef41Sopenharmony_ci      });
391cb0ef41Sopenharmony_ci    }, streamData.length),
401cb0ef41Sopenharmony_ci  });
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  // Use helper to convert it to a Web ReadableStream using Count strategy
431cb0ef41Sopenharmony_ci  const readableStream = Readable.toWeb(readable, {
441cb0ef41Sopenharmony_ci    strategy: new CountQueuingStrategy({ highWaterMark: 1 }),
451cb0ef41Sopenharmony_ci  });
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  assert(!readableStream.locked);
481cb0ef41Sopenharmony_ci  readableStream.getReader().read().then(common.mustCall());
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci{
521cb0ef41Sopenharmony_ci  const desireSizeExpected = 2;
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  const stringStream = new ReadableStream(
551cb0ef41Sopenharmony_ci    {
561cb0ef41Sopenharmony_ci      start(controller) {
571cb0ef41Sopenharmony_ci        // Check if the strategy is being assigned on the init of the ReadableStream
581cb0ef41Sopenharmony_ci        strictEqual(controller.desiredSize, desireSizeExpected);
591cb0ef41Sopenharmony_ci        controller.enqueue('a');
601cb0ef41Sopenharmony_ci        controller.enqueue('b');
611cb0ef41Sopenharmony_ci        controller.close();
621cb0ef41Sopenharmony_ci      },
631cb0ef41Sopenharmony_ci    },
641cb0ef41Sopenharmony_ci    new CountQueuingStrategy({ highWaterMark: desireSizeExpected })
651cb0ef41Sopenharmony_ci  );
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  const reader = stringStream.getReader();
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci  reader.read().then(common.mustCall());
701cb0ef41Sopenharmony_ci  reader.read().then(common.mustCall());
711cb0ef41Sopenharmony_ci  reader.read().then(({ value, done }) => {
721cb0ef41Sopenharmony_ci    strictEqual(value, undefined);
731cb0ef41Sopenharmony_ci    strictEqual(done, true);
741cb0ef41Sopenharmony_ci  });
751cb0ef41Sopenharmony_ci}
76