lib/streams.js
function passiveClone(input) {
  if (isStream(input)) {
    return new ReadableStream({
      start(controller) {
        const transformed = transformPair(input, async (readable, writable) => {
          const reader = getReader(readable);
          const writer = getWriter(writable);
          try {
            while (true) {
              await writer.ready;
              const { done, value } = await reader.read();
              if (done) {
                try { controller.close(); } catch(e) {}
                await writer.close();
                return;
              }
              try { controller.enqueue(value); } catch(e) {}
              await writer.write(value);
            }
          } catch(e) {
            controller.error(e);
            await writer.abort(e);
          }
        });
        overwrite(input, transformed);
      }
    });
  }
  return slice(input);
}
function passiveClone(input) {
  if (isStream(input)) {
    return new ReadableStream({
      start(controller) {
        const transformed = transformPair(input, async (readable, writable) => {
          const reader = getReader(readable);
          const writer = getWriter(writable);
          try {
            while (true) {
              await writer.ready;
              const { done, value } = await reader.read();
              if (done) {
                try { controller.close(); } catch(e) {}
                await writer.close();
                return;
              }
              try { controller.enqueue(value); } catch(e) {}
              await writer.write(value);
            }
          } catch(e) {
            controller.error(e);
            await writer.abort(e);
          }
        });
        overwrite(input, transformed);
      }
    });
  }
  return slice(input);
}
function passiveClone ( input ) { if ( isStream ( input ) ) { return new ReadableStream ( { start ( controller ) { const transformed = transformPair ( input , async ( readable , writable ) => { const reader = getReader ( readable ) ; const writer = getWriter ( writable ) ; try { while ( true ) { await writer . ready ; const { done , value } = await reader . read ( ) ; if ( done ) { try { controller . close ( ) ; } catch ( e ) { } await writer . close ( ) ; return ; } try { controller . enqueue ( value ) ; } catch ( e ) { } await writer . write ( value ) ; } } catch ( e ) { controller . error ( e ) ; await writer . abort ( e ) ; } } ) ; overwrite ( input , transformed ) ; } } ) ; } return slice ( input ) ; }
Clone a Stream for reading it twice. Data will arrive at the same rate as the input stream is being read.
Reading from the clone will NOT pull from the input stream. Data only arrives when reading the input stream.
The input stream will NOT be canceled if the clone is canceled, only if the input stream are canceled.
If the input stream is canceled, the clone will be errored.
@param {ReadableStream|Uint8array|String} input
@returns {ReadableStream|Uint8array|String} cloned input
Clone a Stream for reading it twice . Data will arrive at the same rate as the input stream is being read . Reading from the clone will NOT pull from the input stream . Data only arrives when reading the input stream . The input stream will NOT be canceled if the clone is canceled only if the input stream are canceled . If the input stream is canceled the clone will be errored .