How to use multistream - 10 common examples

To help you get started, we’ve selected a few multistream 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 Fitbit / fitbit-sdk-toolchain / src / index.ts View on Github external
buildId: string;
  onDiagnostic?: DiagnosticHandler;
}) {
  const deviceJSPipeline: Stream[] = [
    // TODO: remove is-defined assertion ('!')
    buildComponent({
      projectConfig,
      onDiagnostic,
      component: ComponentType.DEVICE,
    })!,
  ];

  const processedJS = new playbackStream({ objectMode: true });
  deviceJSPipeline.push(processedJS);

  return multistream.obj([
    // Sequence the build process: wait until compilation finishes
    // before building the resources for each component.
    new pumpify.obj(
      ...deviceJSPipeline,
      // We don't want to send the JS file downstream directly. It will
      // be played back into the individual device component pipelines.
      dropStream.obj(),
    ),
    ...projectConfig.buildTargets.map((family) =>
      lazyObjectReadable(() => {
        const { platform, displayName, maxDeviceBundleSize } = buildTargets[
          family
        ];
        onDiagnostic({
          messageText: `Building app for ${displayName}`,
          category: DiagnosticCategory.Message,
github kartotherian / kartotherian / packages / cassandra / CassandraStore.js View on Github external
}
        // options.zoom===0 is a temp workaround because the info data used to be stored in the zoom=0,idx=1
        if (end < blockEnd || options.zoom === 0) {
            conds += ' AND idx < ?';
            params.push(end);
        }
        let query = 'SELECT ' + fields + ' FROM ' + self.table + ' WHERE ' + conds;
        return self.client.stream(query, params, {prepare: true, autoPage: true});
    };

    let ms;
    if (self.blocksize) {
        let blockIdx = Math.floor(start / self.blocksize),
            toBlockIdx = Math.floor((end - 1) / self.blocksize);

        ms = multistream.obj(cb => {
            if (blockIdx > toBlockIdx) {
                cb();
            } else {
                try {
                    let bi = blockIdx++;
                    cb(null, createStream(bi * self.blocksize, Math.min(maxEnd, (bi + 1) * self.blocksize)));
                } catch (err) {
                    cb(err);
                }
            }
        });
    } else {
        ms = createStream(0, maxEnd);
    }

    return promistreamus(ms, value => {
github theKashey / react-imported-component / examples / SSR / parcel-react-ssr / stream-server / interleaved-middleware.js View on Github external
const styledStream = createStyleStream(projectStyles, (style) => (
    // just return it
    createLink(`dist/${style}`)
  ));

  // allow client to start loading js bundle
  res.write(`<div id="app">`);

  const endStream = readableString('');

  const streams = [
    styledStream,
    endStream,
  ];

  MultiStream(streams).pipe(res);

  // start by piping react and styled transform stream
  htmlStream.pipe(styledStream);
  styledStream.on('end', () =&gt; {
    res.write('</div>');
    // push loaded chunks information
    res.write(printDrainHydrateMarks(streamUID));
    res.write('');
    res.end();
  });
}
github zeit / now / packages / now-build-utils / src / file-ref.ts View on Github external
toStream(): NodeJS.ReadableStream {
    let flag = false;

    // eslint-disable-next-line consistent-return
    return multiStream(cb => {
      if (flag) return cb(null, null);
      flag = true;

      this.toStreamAsync()
        .then(stream => {
          cb(null, stream);
        })
        .catch(error => {
          cb(error, null);
        });
    });
  }
}
github catamphetamine / react-pages / source / server / render.js View on Github external
createStringStream(beforeContent),
		createStringStream(afterContent)
	]

	if (renderContent !== false) {
		// Render page content to a `Stream`
		// inserting this stream in the middle of `streams` array.
		// `array.splice(index, 0, element)` inserts `element` at `index`.
		const pageElement = React.createElement(container, containerProps, content)
		streams.splice(streams.length / 2, 0, ReactDOM.renderToNodeStream(pageElement))
	}

	return {
		route,
		status,
		content: combineStreams(streams),
		time,
		cookies: newCookies
	}
}
github elastic / kibana / src / legacy / core_plugins / tests_bundle / index.js View on Github external
async handler(_, h) {
            const cssFiles = await globby(
              testingPluginIds
                ? testingPluginIds.split(',').map((id) => `built_assets/css/plugins/${id}/**/*.css`)
                : `built_assets/css/**/*.css`,
              { cwd: fromRoot('.'), absolute: true }
            );

            const stream = replacePlaceholder(
              new MultiStream(cssFiles.map(path => createReadStream(path))),
              '/built_assets/css/'
            );

            return h.response(stream).code(200).type('text/css');
          }
        });
github Nexusoft / NexusInterface / app / nxs_modules / api / modules.js View on Github external
return new Promise((resolve, reject) => {
    try {
      const nxsPackagePath = join(dirPath, 'nxs_package.json');
      const filePaths = module.files.sort().map(file => join(dirPath, file));
      const streams = [
        normalizeFile(nxsPackagePath),
        ...filePaths.map(normalizeFile),
      ];

      const hash = crypto.createHash('sha256');
      hash.setEncoding('base64');
      hash.on('readable', () => {
        resolve(hash.read());
      });
      new Multistream(streams).pipe(hash);
    } catch (err) {
      console.error(err);
      reject(err);
    }
  });
}
github Nexusoft / NexusInterface / src / shared / lib / modules / repo.js View on Github external
if (!module) {
        const nxsPackageContent = await fs.promises.readFile(nxsPackagePath);
        module = JSON.parse(nxsPackageContent);
      }
      const filePaths = module.files.sort().map(file => join(dirPath, file));
      const streams = [
        normalizeFile(nxsPackagePath),
        ...filePaths.map(normalizeFile),
      ];

      const hash = crypto.createHash('sha256');
      hash.setEncoding('base64');
      hash.on('readable', () => {
        resolve(hash.read());
      });
      new Multistream(streams).pipe(hash);
    } catch (err) {
      console.error(err);
      reject(err);
    }
  });
}
github digidem / mosaic-image-stream / lib / pixel-multi-stream.js View on Github external
PixelMultiStream.prototype._gotNextStream = function (stream) {
  if (stream) {
    if (stream.format && stream.format.height) {
      onFormat.call(this, stream.format)
    } else {
      stream.on('format', onFormat.bind(this))
    }
  } else if (this._actualHeight !== this.format.height) {
    this.emit('error', new Error('Total height of mosaiced images (' + this._actualHeight +
      'px) did not match specified height (' + this.format.height + 'px)'))
  }
  MultiStream.prototype._gotNextStream.call(this, stream)
}
github beautifulinteractions / node-quadstore / lib / getstream / index.js View on Github external
const executeStrategy = (strategy, opts, store) => {
  const streamFactories = strategy.paths.map(
    (path) => generateStreamFactoryForPath(store, strategy, path),
  );
  let multiStream = multistream.obj(streamFactories);
  if (opts.offset || opts.limit) {
    let multiIterator = AsyncIterator.wrap(multiStream);
    if (opts.offset) {
      multiIterator = multiIterator.skip(opts.offset);
    }
    if (opts.limit) {
      multiIterator = multiIterator.take(opts.limit);
    }
    multiStream = utils.createIteratorStream(multiIterator);
  }
  return multiStream;
};

multistream

A stream that emits multiple other streams one after another (streams3)

MIT
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis