How to use the got.stream function in got

To help you get started, we’ve selected a few got 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 iguntur / administratif-indonesia / scripts / download.js View on Github external
paths('.tmp', 'pdf', filename).then(filepath => {
		if (filepath.endsWith('.pdf')) {
			got.stream(opts.url)
				.pipe(fs.createWriteStream(filepath));
		}

		if (filepath.endsWith('.zip')) {
			got.stream(opts.url)
				.pipe(unzip.Extract({path: path.dirname(filepath)})); // eslint-disable-line new-cap
		}
	});
}
github googleapis / cloud-trace-nodejs / system-test / trace-express.js View on Github external
const server = app.listen(8080, () => {
      console.log('server started');
      got.stream(`http://localhost:8080${testPath}`).pipe(process.stdout);
      setTimeout(() => {
        listTraces(testPath).then(verifyTraces);
      }, WRITE_CONSISTENCY_DELAY_MS);
    });
github iteufel / nwjs-ffmpeg-prebuilt / build.js View on Github external
zipName = `${version.version}-linux-${program.arch}.zip`.slice(1);
    } else {
        console.error('Platform not supported');
        process.exit(1);
    }
    const downloadUrl = `https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases/download/${version.version.slice(1)}/${zipName}`;
    if (program.getDownloadUrl) {
        process.stdout.write(downloadUrl);
        process.exit(0);
    }

    await fs.ensureDir(outDir);
    if (program.download) {
        console.log(`Downloading NW.js ${version.version} - FFmpeg - (Chromium ${chromiumVersion})`);
        await pipeline(
            got.stream(downloadUrl),
            fs.createWriteStream(path.join(outDir, zipName))
        );
        return;
    }
    console.log(`Building NW.js ${version.version} - FFmpeg - (Chromium ${chromiumVersion})`);
    await fs.ensureDir('./build');
    if (program.clean) {
        console.log('Cleaning build Directory');
        await fs.emptyDir('./build');
    }
    process.chdir('./build');
    if (!(await fs.pathExists('./depot_tools'))) {
        await execAsync('git', 'clone', 'https://chromium.googlesource.com/chromium/tools/depot_tools.git');
    }
    if (platform === 'win32' || platform === 'win') {
        process.env.DEPOT_TOOLS_WIN_TOOLCHAIN = '0';
github signalapp / Signal-Desktop / ts / updater / common.ts View on Github external
let tempDir;
  try {
    tempDir = await createTempDir();
    const targetUpdatePath = join(tempDir, fileName);
    const targetSignaturePath = join(tempDir, getSignatureFileName(fileName));

    validatePath(tempDir, targetUpdatePath);
    validatePath(tempDir, targetSignaturePath);

    logger.info(`downloadUpdate: Downloading ${signatureUrl}`);
    const { body } = await get(signatureUrl, getGotOptions());
    await writeFile(targetSignaturePath, body);

    logger.info(`downloadUpdate: Downloading ${updateFileUrl}`);
    const downloadStream = stream(updateFileUrl, getGotOptions());
    const writeStream = createWriteStream(targetUpdatePath);

    await new Promise((resolve, reject) => {
      downloadStream.on('error', error => {
        reject(error);
      });
      downloadStream.on('end', () => {
        resolve();
      });

      writeStream.on('error', error => {
        reject(error);
      });

      downloadStream.pipe(writeStream);
    });
github nodegui / qode / npm / install.js View on Github external
return await new Promise((resolve, reject) => {
    const downloadStream = got.stream(url, options);
    downloadStream.pipe(writeStream);
    const bar = new ProgressBar(
      "downloading [:bar] :percent of :size Mb :etas",
      {
        total: 100
      }
    );
    downloadStream.on("error", reject);
    downloadStream.on("downloadProgress", progress => {
      bar.total = progress.total;
      bar.curr = progress.transferred;
      bar.tick(0, { size: (progress.total / 1024 / 1024).toFixed(1) });
    });
    writeStream.on("error", reject);
    writeStream.on("close", () => resolve());
  });
github develar / electron-updater / lib / cache.js View on Github external
function download(next) {
	var fileStream = fs.createWriteStream(next.cachePath);
	var error = null;
	fileStream.on('error', function (err) {
		error = err;
		next.logger.error('error downloading:');
		next.logger.error(err);
	});
	fileStream.on('finish', function () {
		if(error) return next.callback(error);
		checkCache(next);
	});

	got.stream(next.url).pipe(fileStream);
}
github hello-efficiency-inc / raven-reader / src / renderer / parsers / feed.js View on Github external
export async function parseFeed (feedUrl, faviconUrl = null) {
  let feed
  const feeditem = {
    meta: '',
    posts: []
  }
  try {
    feed = await parser.parseURL(feedUrl)
  } catch (e) {
    const stream = await got.stream(feedUrl, { retries: 0 })
    feed = await parseFeedParser(stream)
  }

  feeditem.meta = {
    link: feed.link,
    xmlurl: feed.feedUrl ? feed.feedUrl : feedUrl,
    favicon: typeof faviconUrl !== 'undefined' ? faviconUrl : null,
    description: feed.description ? feed.description : null,
    title: feed.title
  }
  feeditem.posts = feed.items
  const response = await ParseFeedPost(feeditem)
  return response
}
github telekits / teleapi / index.js View on Github external
getFile(id) {
        return got.stream(`${API_FILE + this.token}/${id}`);
    }
}