How to use the streams.TransformStream function in streams

To help you get started, we’ve selected a few streams examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla-b2g / gaia-email-libs-and-more / js / search / filtering_stream.js View on Github external
enqueue({ change, gather: null });
      } else {
        // (avoid gathering data for already-removed items)
        if (queuedSet.has(change.id)) {
          logic(ctx, 'gathering', { id: change.id });
          let gatherInto = inputToGatherInto(change);
          enqueue({ change, gather: rootGatherer.gather(gatherInto) });
        }
      }
      done();
    },
    writableStrategy: new CountQueuingStrategy({ highWaterMark: 1 }),
    readableStrategy: new CountQueuingStrategy({ highWaterMark: 1 })
  });

  let filterStream = new TransformStream({
    flush(enqueue, close) {
      close();
    },
    transform({ change, gather }, enqueue, done) {
      if (!gather) {
        // This is a deletion.  And we care about it or we wouldn't be here.
        enqueue(change);
        done();
      } else {
        logic(ctx, 'gatherWait', { id: change.id });
        gather.then((gathered) => {
          logic(ctx, 'gathered', { id: change.id });
          // It's possible the item got removed after we kicked off the gather.
          // Don't report the item in that case.  (Note that explicit deletion
          // of things already reported triggered the first branch of this if,
          // so we don't need to be worrying about that here.)
github mozilla-b2g / gaia-email-libs-and-more / js / search / filtering_stream.js View on Github external
* stream for consistency/sanity purposes, and that has a memory cost.  Also,
   * the TOC maintains an ordered array which is O(log N) to check, so that
   * would be bad that way too.
   */
  let knownFilteredSet = new Set();

  /**
   * Stream that allows us to keep some number of gathers in flight for pipeline
   * throughput optimization.  This stream takes in the change requests that
   * contain the id we need to gather and immediately returns a Promise.  This
   * allows us to get the requests in flight despite the transform stream only
   * allowing for one active transform at a time.  The filter stream in turn
   * then waits for the promises in its transform stage since it has a direct
   * data dependency and we do want to maintain ordering.
   */
  let gatherStream = new TransformStream({
    flush(enqueue, close) {
      close();
    },
    transform(change, enqueue, done) {
      if (isDeletion(change)) {
        enqueue({ change, gather: null });
      } else {
        // (avoid gathering data for already-removed items)
        if (queuedSet.has(change.id)) {
          logic(ctx, 'gathering', { id: change.id });
          let gatherInto = inputToGatherInto(change);
          enqueue({ change, gather: rootGatherer.gather(gatherInto) });
        }
      }
      done();
    },
github mozilla-b2g / gaia-email-libs-and-more / js / mime-streams.js View on Github external
exports.ByteCounterTransformStream = function() {
  var self = this;
  var ts = new streams.TransformStream({
    transform(chunk, enqueue, done) {
      self.totalBytesRead += chunk.byteLength;
      enqueue(chunk);
      done();
    }
  });

  this.writable = ts.writable;
  this.readable = ts.readable;

  /** @member {number} */
  this.totalBytesRead = 0;
}

streams

A lazy streams library for functional composition in JavaScript.

MIT
Latest version published 2 months ago

Package Health Score

68 / 100
Full package analysis