app.get('/', function( req, res ) { res.writeHead( 200, { 'Content-Type': 'text/html' } ); fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res ); });
async topicThumbAction() { const imageFile = this.file('scene_pic_url'); if (think.isEmpty(imageFile)) { return this.fail('保存失败'); } const that = this; const filename = '/static/upload/topic/' + think.uuid(32) + '.jpg'; const is = fs.createReadStream(imageFile.path); const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename); is.pipe(os); return that.success({ name: 'scene_pic_url', fileUrl: 'http://127.0.0.1:8360' + filename }); }
pdf.create(html,{ border: { "top": "0.3in", "right": "0.2in", "left": "0.2in", "bottom":"0in" }, footer: { height:"15mm", "contents": "<div style='color: gray;border-top: 1px lightgray solid;font-size: 13px;padding-top: 10px'>本pdf由<a href='http://doclever.cn'>DOClever</a>生成</div>" }, }).toStream(function (err,stream) { stream.pipe(res); })
downloadBackup: (backupUrl, writeStream) => { const readStream = fs.createReadStream(backupUrl); readStream.pipe(writeStream); return new Promise((resolve, reject) => { writeStream.on('finish', resolve);
mkdir(dirPath).then(function () { return when.promise(function (res, rej) { var read = fs.createReadStream(packagePath); var write = fs.createWriteStream(path.join(dirPath, 'package.json')); read.pipe(write); read.on('error', rej); write.on('error', rej); write.on('close', res); }); })
/** * Copy file via streams * @param {string} src - Path to the source file * @param {string} dst - Path to the destination file. */ const copyFile = (src, dst, callback) => { // cbCalled flag and runCb helps to run cb only once. let cbCalled = false; let runCb = (err) => { if (cbCalled) return; cbCalled = true; callback(err); }; // Create read stream let readable = fs.createReadStream(src); readable.on('error', runCb); // Create write stream let writable = fs.createWriteStream(dst); writable.on('error', (err)=>{ readable.destroy(); runCb(err); }); writable.on('close', () => runCb()); // Copy file via piping streams. readable.pipe(writable); }
app.get("/", function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); fs.createReadStream(opts.baseDir + '/index.html').pipe(res); });
async brandPicAction() { const brandFile = this.file('brand_pic'); if (think.isEmpty(brandFile)) { return this.fail('保存失败'); } const that = this; const filename = '/static/upload/brand/' + think.uuid(32) + '.jpg'; const is = fs.createReadStream(brandFile.path); const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename); is.pipe(os); return that.success({ name: 'brand_pic', fileUrl: 'http://127.0.0.1:8360' + filename }); }
async brandNewPicAction() { const brandFile = this.file('brand_new_pic'); if (think.isEmpty(brandFile)) { return this.fail('保存失败'); } const that = this; const filename = '/static/upload/brand/' + think.uuid(32) + '.jpg'; const is = fs.createReadStream(brandFile.path); const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename); is.pipe(os); return that.success({ name: 'brand_new_pic', fileUrl: 'http://127.0.0.1:8360' + filename }); }
async categoryWapBannerPicAction() { const imageFile = this.file('wap_banner_pic'); if (think.isEmpty(imageFile)) { return this.fail('保存失败'); } const that = this; const filename = '/static/upload/category/' + think.uuid(32) + '.jpg'; const is = fs.createReadStream(imageFile.path); const os = fs.createWriteStream(think.ROOT_PATH + '/www' + filename); is.pipe(os); return that.success({ name: 'wap_banner_url', fileUrl: 'http://127.0.0.1:8360' + filename }); }
downloadBackup: (backupUrl, writeStream) => { const readStream = fs.createReadStream(backupUrl); readStream.pipe(writeStream); return new Promise((resolve, reject) => { writeStream.on('finish', resolve);