How to use the streamsaver.createWriteStream function in streamsaver

To help you get started, we’ve selected a few streamsaver 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 transcend-io / penumbra / index.ts View on Github external
function saveFileStream(
  rs: ReadableStream,
  fileName: string,
): Promise {
  const fileStream = createWriteStream(fileName);
  const writer = fileStream.getWriter();

  // Feature detection for pipeTo (more efficient)
  if (rs.pipeTo) {
    // like as we never did fileStream.getWriter()
    writer.releaseLock();
    return rs.pipeTo(fileStream);
  }

  const reader = rs.getReader();
  const pump = (): Promise =>
    reader.read().then(({ value, done }) =>
      done
        // Close the stream so we stop writing
        ? writer.close()
        // Write one chunk, then get the next one
github transcend-io / penumbra / util.js View on Github external
function saveFileStream(rs, fileName) {
  const fileStream = createWriteStream(fileName);
  const writer = fileStream.getWriter();

  // Feature detection for pipeTo (more efficient)
  if (rs.pipeTo) {
    // like as we never did fileStream.getWriter()
    writer.releaseLock();
    return rs.pipeTo(fileStream);
  }

  const reader = rs.getReader();
  const pump = () =>
    reader.read().then(({ value, done }) =>
      done
        ? // close the stream so we stop writing
          writer.close()
        : // Write one chunk, then get the next one
github transcend-io / penumbra / dist / index.js View on Github external
function saveFileStream(rs, fileName) {
    var fileStream = streamsaver_1.createWriteStream(fileName);
    var writer = fileStream.getWriter();
    // Feature detection for pipeTo (more efficient)
    if (rs.pipeTo) {
        // like as we never did fileStream.getWriter()
        writer.releaseLock();
        return rs.pipeTo(fileStream);
    }
    var reader = rs.getReader();
    var pump = function () {
        return reader.read().then(function (_a) {
            var value = _a.value, done = _a.done;
            return done
                // Close the stream so we stop writing
                ? writer.close()
                // Write one chunk, then get the next one
                : writer.write(value).then(pump);
github commaai / cabana / src / CanExplorer.js View on Github external
downloadLogAsCSV() {
    console.log('downloadLogAsCSV:start');
    const { dbcFilename } = this.state;
    const fileStream = createWriteStream(
      `${dbcFilename.replace(/\.dbc/g, '-')}${+new Date()}.csv`
    );
    const writer = fileStream.getWriter();
    const encoder = new TextEncoder();

    if (this.state.live) {
      return this.downloadLiveLogAsCSV(dataHandler);
    }
    return this.downloadRawLogAsCSV(dataHandler);

    function dataHandler(e) {
      const { logData, shouldClose, progress } = e.data;
      if (shouldClose) {
        console.log('downloadLogAsCSV:close');
        writer.close();
        return;
github citrusbyte / thicket / packages / thicket-webapp / src / components / Gif / index.js View on Github external
const downloadFile = gif => {
  const filename = getFilename(gif)
  const fileStream = streamSaver.createWriteStream(filename, gif.src.length)
  const writer = fileStream.getWriter()
  const data = new ImageDataConverter(gif.src).convertToTypedArray()
  writer.write(data)
  writer.close()
}

streamsaver

StreamSaver writes stream to the filesystem directly - asynchronous

MIT
Latest version published 3 years ago

Package Health Score

58 / 100
Full package analysis

Popular streamsaver functions