How to use the mz/fs.createWriteStream function in mz

To help you get started, we’ve selected a few mz 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 eggjs / examples / multipart-file-mode / app / controller / multiple.js View on Github external
async upload() {
    const { ctx } = this;
    const files = ctx.request.files;
    ctx.logger.warn('files: %j', files);

    try {
      for (const file of files) {
        const filename = file.filename.toLowerCase();
        const targetPath = path.join(this.config.baseDir, 'app/public', filename);
        const source = fs.createReadStream(file.filepath);
        const target = fs.createWriteStream(targetPath);
        await pump(source, target);
        ctx.logger.warn('save %s to %s', file.filepath, targetPath);
      }
    } finally {
      // delete those request tmp files
      await ctx.cleanupRequestFiles();
    }

    const fields = [];
    for (const k in ctx.request.body) {
      fields.push({
        key: k,
        value: ctx.request.body[k],
      });
    }
github cnpm / npminstall / test / fixtures / high-speed-store / store.js View on Github external
exports.getStream = async url => {
  const dir = path.join(__dirname, 'tmp');
  await mkdirp(dir);
  const file = path.join(dir, utility.md5(url) + path.extname(url));
  if (await fs.exists(file)) {
    return fs.createReadStream(file);
  }

  const writeStream = fs.createWriteStream(file);
  await urllib.request(url, {
    writeStream,
    timeout: 10000,
    followRedirect: true,
  });
  return fs.createReadStream(file);
};
github appirio-tech / tc-common-tutorials / submission-system / docker / s3_mock_api / src / routes.js View on Github external
yield new Promise((resolve, reject) => {
    const path = Path.join(config.UPLOAD_PATH, _encodePath(data.filePath));
    console.log('saving file to', path);
    const stream = fs.createWriteStream(path);
    this.req.pipe(stream);
    this.req.on('end', () => {
      files[data.filePath] = data;
      resolve();
    });
    this.req.on('error', reject);
  });
  this.body = 'fake s3 upload ok';
github stryker-mutator / stryker / packages / stryker / src / utils / StrykerTempFolder.ts View on Github external
function writeFile(fileName: string, data: string | Buffer, instrumenter: NodeJS.ReadWriteStream | null = null): Promise {
  if (Buffer.isBuffer(data)) {
    return fs.writeFile(fileName, data);
  } else if (instrumenter) {
    instrumenter.pipe(fs.createWriteStream(fileName, 'utf8'));
    return writeToStream(data, instrumenter);
  } else {
    return fs.writeFile(fileName, data, 'utf8');
  }
}
github jordwalke / esy-issues / src / installCommand / index.js View on Github external
return new Promise((resolve, reject) => {
    let out = fs.createWriteStream(filename);
    stream
      .on('data', chunk => {
        if (md5checksum != null) {
          hasher.update(chunk);
        }
      })
      .pipe(out)
      .on('error', err => {
        reject(err);
      })
      .on('finish', () => {
        let actualChecksum = hasher.digest('hex');
        if (md5checksum != null) {
          if (actualChecksum !== md5checksum) {
            reject(new Error(`Incorrect md5sum (expected ${md5checksum}, got ${actualChecksum})`))
            return;
github pedromsilvapt / unicast / src / Subtitles / SubtitlesRepository.ts View on Github external
await new Promise( ( resolve, reject ) =>
                data.pipe( fs.createWriteStream( file ) ).on( 'error', reject ).on( 'finish', resolve )
            );
github InfiniteLibrary / infinite-electron / app / streamer / index.js View on Github external
.then(res => {
        const stream = fs.createWriteStream(destination);
        res.body.pipe(stream);
        return new Promise((resolve, reject) => {
          res.body.on('end', () => resolve(destination));
          res.body.on('error', err => reject(err));
        });
      });
  }
github tedivm / ec2details / bin / instance_details.js View on Github external
async function downloadFile (forceDownload = false) {
  if (forceDownload || !await fs.existsSync(productsFile) || !await fs.existsSync(termsFile)) {
    if (forceDownload || !await fs.existsSync(offersFile)) {
      const stream = fs.createWriteStream(offersFile)
      request.get(offers).pipe(stream)
      await new Promise(fulfill => stream.on('finish', fulfill))
    }
    await exec(`cat ${offersFile} | npx JSONStream 'products.*' > ${productsFile}`)
    await exec(`cat ${offersFile} | npx JSONStream 'terms.OnDemand.*' > ${termsFile}`)
  }
  return true
}
github koajs / file-server / index.js View on Github external
yield function (done) {
      fs.createReadStream(path)
      .on('error', done)
      .pipe(zlib.createGzip())
      .on('error', done)
      .pipe(fs.createWriteStream(tmp))
      .on('error', done)
      .on('finish', done)
    }