lib/streams.js
function transform(input, process = () => undefined, finish = () => undefined) {
  if (isStream(input)) {
    return transformRaw(input, {
      async transform(value, controller) {
        try {
          const result = await process(value);
          if (result !== undefined) controller.enqueue(result);
        } catch(e) {
          controller.error(e);
        }
      },
      async flush(controller) {
        try {
          const result = await finish();
          if (result !== undefined) controller.enqueue(result);
        } catch(e) {
          controller.error(e);
        }
      }
    });
  }
  const result1 = process(input);
  const result2 = finish();
  if (result1 !== undefined && result2 !== undefined) return concat([result1, result2]);
  return result1 !== undefined ? result1 : result2;
}
function transform(input, process = () => undefined, finish = () => undefined) {
  if (isStream(input)) {
    return transformRaw(input, {
      async transform(value, controller) {
        try {
          const result = await process(value);
          if (result !== undefined) controller.enqueue(result);
        } catch(e) {
          controller.error(e);
        }
      },
      async flush(controller) {
        try {
          const result = await finish();
          if (result !== undefined) controller.enqueue(result);
        } catch(e) {
          controller.error(e);
        }
      }
    });
  }
  const result1 = process(input);
  const result2 = finish();
  if (result1 !== undefined && result2 !== undefined) return concat([result1, result2]);
  return result1 !== undefined ? result1 : result2;
}
function transform ( input , process = ( ) => undefined , finish = ( ) => undefined ) { if ( isStream ( input ) ) { return transformRaw ( input , { async transform ( value , controller ) { try { const result = await process ( value ) ; if ( result !== undefined ) controller . enqueue ( result ) ; } catch ( e ) { controller . error ( e ) ; } } , async flush ( controller ) { try { const result = await finish ( ) ; if ( result !== undefined ) controller . enqueue ( result ) ; } catch ( e ) { controller . error ( e ) ; } } } ) ; } const result1 = process ( input ) ; const result2 = finish ( ) ; if ( result1 !== undefined && result2 !== undefined ) return concat ( [ result1 , result2 ] ) ; return result1 !== undefined ? result1 : result2 ; }
Transform a stream using helper functions which are called on each chunk, and on stream close, respectively.
@param {ReadableStream|Uint8array|String} input
@param {Function} process
@param {Function} finish
@returns {ReadableStream|Uint8array|String}
Transform a stream using helper functions which are called on each chunk and on stream close respectively .