How to use the multistream function in multistream

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 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 Shopify / quilt / packages / react-html / src / server / stream.ts View on Github external
export default function stream(tree: ReactElement) {
  const doctype = new Readable();
  doctype.push('');
  doctype.push(null);

  return multistream([doctype, renderToStaticNodeStream(tree)]);
}
github zeit / pkg / lib / producer.js View on Github external
count += 1;
      return pipeToNewMeter(s);
    }

    const binaryBuffer = fs.readFileSync(target.binaryPath);
    const placeholders = discoverPlaceholders(binaryBuffer);

    let track = 0;
    let prevStripe;

    let payloadPosition;
    let payloadSize;
    let preludePosition;
    let preludeSize;

    new Multistream((cb) => {
      if (count === 0) {
        return cb(undefined, next(
          intoStream(binaryBuffer)
        ));
      } else
      if (count === 1) {
        payloadPosition = meter.bytes;
        return cb(undefined, next(
          intoStream(Buffer.alloc(0))
        ));
      } else
      if (count === 2) {
        if (prevStripe && !prevStripe.skip) {
          let { snap, store } = prevStripe;
          snap = snapshotify(snap, slash);
          vfs[snap][store] = [ track, meter.bytes ];

multistream

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

MIT
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis