function parquetStream(rs, name, task, pipeline, done) { const filename = task.basedir + 'import/' + name.replace(/\//g, '-'); const ws = fs.createWriteStream(filename, {highWaterMark: 1 << 16}); log('Download ', filename); rs.pipe(ws); ws.once('close', function () { parquetIterate(filename, task, pipeline, done); }); }
async write ( data ) { const token = await this.queue.acquire() const startPosition = this.position this.position += BigInt( data.length ) const saturated = ! this.stream.write( data ) if ( saturated ) { this.stream.once( 'drain', () => this.queue.release( token )) } else { this.queue.release( token ) } return startPosition }
srcStream.on('data', data => { const canContinue = destStream.write(data) if (!canContinue) { // we are overflowing the destination, we should pause srcStream.pause() // we will resume when the destination stream is drained destStream.once('drain', () => srcStream.resume()) } })
writeStreamToFile(readableStream, filePath) { let writableStream = fs.createWriteStream(filePath, this.options); readableStream.pipe(writableStream); return new Promise(function(resolve, reject) { readableStream.once('error', reject); writableStream.once('error', reject); writableStream.once('finish', resolve); }).catch(function(err) { readableStream = null; // Explicitly null because of v8 bug 6512. writableStream.end(); throw err; }); }
stream.once('close', function(){ if(opt.InterfaceResult && opt.InterfaceResult.ContentLength !== undefined && fs.existsSync(dstFile)){ let fstat = fs.statSync(dstFile); if(fstat.size !== parseInt(opt.InterfaceResult.ContentLength)){ return bc(new Error('premature end of Content-Length delimiter message body (expected:' + opt.InterfaceResult.ContentLength + '; received:' + fstat.size + ')'), 'PREMATURE_END'); } } doLog(); }).once('error', function(err){ if(log.isLevelEnabled('error')){ log.runLog('error', methodName, 'get response stream error [' + headerTostring(err) + ']'); } bc(err, null); });
constructor ( path ) { this.position = BigInt( 0 ) this.stream = fs.createWriteStream( path, { highWaterMark: 1024*1024*10 }) this.stream.once( 'open', fd => { }) this.stream.on( 'error', err => { fatal( 'Writer error', this.stream.path, err ) }) this.queue = genericPool.createPool( { async create () { return Symbol() }, async destroy ( resource ) { return true }, }, {} ) }
async close () { await this.queue.drain() return await new Promise( resolve => { this.queue.clear() this.stream.once( 'close', () => { log( this.stream.path, 'closed', this.position, this.stream.bytesWritten ) resolve( this.position ) }) log( 'closing', this.stream.path ) this.stream.end() }) }
const save = (vpns) => { return new Promise((resolve, reject) => { const writer = fs.createWriteStream(filePath, { overwrite: true }); writer .on('open', () => { vpns = vpns.sort((a, b) => (b.score - a.score)); const chain = vpns.slice(0, 2).map((vpn) => { return new Promise(resolve => writer.write(vpn.config, resolve)); }); Promise.all(chain) .then(() => writer.close()); }) .on('error', reject) .once('close', resolve); }); }
device.getAllDevices() .then(function(devices){ var header = 'id,server_id,org_name,device_type,jss_id,jss_name,jss_serial,jss_last_inventory,jss_udid,jss_os_version,jss_managed,jss_Model'; var stream = fs.createWriteStream("./reports/all_devices_"+Date.now()+".txt"); stream.once('open', function(fd) { stream.write(header); for (i = 0; i < devices.length; i++){ stream.write(deviceRowToCSV(devices[i])); } stream.end(); }); resolve(stream); }) .catch(error => { reject(error); })
fs.move(oldpath, newpath, () => { let puploadKey if(fields.pupload === '*random*') { puploadKey = altKey; } else { puploadKey = fields.pupload; } this.db.get('passwordUploads') .push({ fileName: `${fileName}.${fileExt}`, key: puploadKey, }) .write(); fs.readFile(newpath, 'utf-8', () => { const stream = fs.createWriteStream(`${__dirname}/../uploads/${fileName}.html`); stream.once('open', () => { ejs.renderFile(`${__dirname}/../views/puploadAuth.ejs`, { fileName: `${fileName}.${fileExt}`, }, {}, (_err, str) => { stream.write(str); }); stream.end(); }); }); });
fs.move(oldpath, newpath, () => { if (fileExt.toLowerCase() === 'md' && this.c.markdown) { fs.readFile(newpath, 'utf-8', (_readErr, data) => { const stream = fs.createWriteStream(`${__dirname}/../uploads/${this.c.dateURLPath === true ? `${getDate('year')}/${getDate('month')}/${getDate('day')}/`: ""}${fileName}.html`); stream.once('open', () => { ejs.renderFile(`${__dirname}/../views/md.ejs`, { ogDesc: data.match(/.{1,297}/g)[0], mdRender: md.render(data), }, {}, (_renderErr, str) => { stream.write(str); }); stream.end(); fs.unlink(newpath, delErr => { if (delErr) return this.log.warning(delErr); }); }); }); } if (this.monitorChannel !== null) this.bot.createMessage(this.monitorChannel, `\`\`\`MARKDOWN\n[NEW UPLOAD][USER]\n[SIZE](${Math.round(files.fdata.size / 1024)}KB)\n[TYPE](${files.fdata.type})\n[IP](${userIP})\n[KEY](${authKey})\n\`\`\`\n${protocol}://${req.headers.host}/${this.c.dateURLPath === true ? `${getDate('year')}/${getDate('month')}/${getDate('day')}/`: ""}${returnedFileName}`); if (err) return res.write(err); this.log.verbose(`New File Upload: ${protocol}://${req.headers.host}/${this.c.dateURLPath === true ? `${getDate('year')}/${getDate('month')}/${getDate('day')}/`: ""}${returnedFileName} | IP: ${userIP} | KEY: ${authKey}`); if (usingUploader === true) { res.redirect(`/?success=${protocol}://${req.headers.host}/${this.c.dateURLPath === true ? `${getDate('year')}/${getDate('month')}/${getDate('day')}/`: ""}${returnedFileName}`); return res.end(); } res.write(`${protocol}://${req.headers.host}/${this.c.dateURLPath === true ? `${getDate('year')}/${getDate('month')}/${getDate('day')}/`: ""}${returnedFileName}`); return res.end(); });
async function post(req, res) { const userIP = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress; res.setHeader('Content-Type', 'text/text'); if (!this.auth(this.c.key, req.body.password, this.c) && !this.c.public) { res.statusCode = 401; res.redirect('/short?error=Incorrect_Password'); res.end(); return this.log.warning(`Unauthorized User | URL Shorten | ${userIP}`); } const protocol = this.protocol(); const fileName = this.randomToken(this.c.shortUrlLength); if (req.body.URL === '' || req.body.URL === null) { res.redirect('/short?error=No URL Input'); return res.end(); } const stream = fs.createWriteStream(`${__dirname}/../uploads/${fileName}.html`); stream.once('open', () => { stream.write(`<meta http-equiv="refresh" content="0;URL='${req.body.URL}'" />`); stream.end(); if (this.monitorChannel !== null) this.bot.createMessage(this.monitorChannel, `\`\`\`MARKDOWN\n[NEW][SHORT URL]\n[URL](${req.body.URL})\n[NEW](${req.headers.host}/${fileName})\n[IP](${userIP})\n\`\`\``); this.log.verbose(`New Short URL: ${protocol}://${req.headers.host}/${fileName} | IP: ${userIP}`); res.redirect(`/short?success=${protocol}://${req.headers.host}/${fileName}`); this.db.get('files') .push({ path: `/${fileName}`, ip: userIP, views: 0 }) .write(); return res.end(); }); }
const downloadAndSetWallpaper = uri => process.platform !== 'win32' ? null : new Promise((resolve, reject) => { const savePath = join(tempFolder, 'bg.jpg'); const file = createWriteStream(savePath); const request = get(uri, res => { res.pipe(file); res.once('end', () => { if (res.statusCode !== 200) { file.destroy(new Error(`Server returned status code ${res.statusCode}`)); } else file.close(); }); }); const onError = err => { file.removeAllListeners(); request.removeAllListeners(); reject(err); }; file.once('close', () => { file.removeAllListeners(); resolve(wallpaper.set(savePath)); }); file.once('error', onError); request.once('error', onError); })
function Stream(sc, stream, type) { // type = 'line' ou 'object' const id = uuid.v4(); const tmpFile = sc.basedir + 'tmp/' + id; const targetFile = sc.basedir + 'stream/' + id; const out = fs.createWriteStream(tmpFile); const dataset = sc.textFile(targetFile); dataset.watched = true; // notify skale to wait for file before launching dataset.parse = type === 'object'; out.once('close', function () { fs.renameSync(tmpFile, targetFile); dataset.watched = false; }); if (type === 'object') stream.pipe(new Obj2line()).pipe(out); else stream.pipe(out); return dataset; }
gzipStream.on('data', data => { const canContinue = destStream.write(data) if (!canContinue) { gzipStream.pause() destStream.once('drain', () => { gzipStream.resume() }) } })