async downloadRepo() { const url = `https://github.com/${this.repo.owner}/${this.repo.name}/archive/master.tar.gz`; const writer = fs.createWriteStream(this.repoArchivePath); (await fetch(url)).body.pipe(writer); return new Promise((resolve, reject) => { writer.on('finish', resolve); writer.on('error', reject); }); }
function getFileWriter(file, callback) { if (!file || fileWriterCache[file]) { return callback(); } var execCallback = function(writer) { delete fileWriterCache[file]; callback(writer); }; fs.stat(file, function(err, stat) { if (!err) { return execCallback(); } fse.ensureFile(file, function(err) { execCallback(err ? null : fs.createWriteStream(file).on('error', logger.error)); logger.error(err); }); }); }
}); request.on('response', (res) => { if (this.showProgress) { const len = parseInt(res.headers['content-length'], 10); const bar = new ProgressBar('downloading :bar :etas', len); res.on('data', (chunk) => bar.tick(chunk.length)); res.on('end', () => console.log('\n')); file.on('finish', () => { if (isTar) { tar file.on('error', (err) => { fs.unlink(absolutePath, () => reject(err)); }); request.on('error', (err) => { fs.unlink(absolutePath, () => reject(err)); });
writeStream.on('finish', () => { setTimeout(reslove, 100); });
function downloadProject(projectUrl, callback) { ensureDirSync(tempDir); console.log("Downloading example project..."); request(projectUrl).pipe(fs.createWriteStream(tempZip)).on("close", () => { callback(); }); }
fs.createReadStream(process.argv[2]) .pipe(split()) .pipe( new ParallelStream((url, enc, push, done) => { if (!url) return done && done(); request.head(url, (err, response) => { push(`${url} is ${err ? "down" : "up"} \n`); done && done(); }); }) ) .pipe(fs.createWriteStream("results.txt")) .on("finish", () => console.log("All urls were checked"));
// Select a file over 1GB fs.createReadStream(file) .pipe(zlib.createGzip()) .pipe(fs.createWriteStream(`${file}.gz`)) .on("finish", () => console.log("Successfully compressed"));
writable.on('finish', () => { resolve() })
// read the file with the url fs.createReadStream(process.argv[2]) // ensures outputing each line on a different chunk .pipe(split()) .pipe(new LimitedParallelStream(concurrency, transformer)) .pipe(fs.createWriteStream('urlList-results.txt')) //destination stream .on('finish', () => { console.log('All urls were checked') console.log(`Execution time : ${Date.now()-startTime}(ms)`); });
// 标记文件末尾 // 处理流事件 --> finish, error writerStream2.on('finish', function() { console.log("写入完成"); });
// read the file with the url fs.createReadStream(process.argv[2]) // ensures outputing each line on a different chunk .pipe(split()) .pipe(new ParallelStream(transformer)) .pipe(fs.createWriteStream('urlList-results.txt')) //destination stream .on('finish', () => { console.log('All urls were checked'); console.log(`Execution time : ${Date.now()-startTime}(ms)`); });
// writerStream.write(data1,'UTF8'); // writerStream.end(); writerStream.on('finish', function() { console.log("Write completed."); });