test('throws if not supplied logger with pino.destination instance with sync false', async ({ throws, doesNotThrow }) => { throws(() => { pino.final(pino(fs.createWriteStream(getPathToNull())), () => {}) }, Error('final requires a stream that has a flushSync method, such as pino.destination')) doesNotThrow(() => { pino.final(pino(pino.destination({ sync: false })), () => {}) }) doesNotThrow(() => { pino.final(pino(pino.destination({ sync: false })), () => {}) }) })
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 }); }
function getPipInstaller() { // install pip return new Promise((resolve, reject) => { const pipFilePath = path.join(__dirname, "get-pip.py"); if (fs.existsSync(pipFilePath)) return resolve(pipFilePath); const file = fs.createWriteStream(pipFilePath); const request = https.get(pipUrl, function(response) { response.pipe(file); file.on("finish", function() { file.close(() => { resolve(pipFilePath); }); }); file.on("error", function(err) { fs.unlink(pipFilePath); reject(err); }); }); }); }
async setOutputStream(outputPath) { const ConsoleStream = require('console-stream'); const stream = outputPath ? fs.createWriteStream(outputPath) : ConsoleStream(); const streamPromise = new Promise((resolve) => { if (stream instanceof fs.WriteStream) { stream.once('ready', (_fd) => { this.outputStream = stream; resolve(); }); } else { this.outputStream = stream; resolve(); } }); const timeoutPromise = new Promise((resolve) => { setTimeout(resolve, 2000); this.outputStream = stream; }); return Promise.race([streamPromise, timeoutPromise]).then(() => { }); }
function callAES() { const startTime = Date.now(); const stream = fs.createReadStream(fileName); broker1.call("aes.encrypt", stream) .then(stream => broker1.call("aes.decrypt", stream)) .then(stream => { const s = fs.createWriteStream(fileName2); stream.pipe(s); s.on("close", () => { const duration = Date.now() - startTime; getSHA(fileName2).then(hash => { if (hash != origHash) { broker1.logger.error(count, kleur.red().bold("Hash mismatch!"), "Time:", duration, "ms. Received SHA:", hash); } else { broker1.logger.info(count, kleur.green().bold("Hash OK!"), "Time:", duration, "ms. Received SHA:", hash); } if (++count < 10) setTimeout(() => callAES(), 100); else { broker1.stop(); broker2.stop(); } }); }); }) .catch(err => broker1.logger.error(err)); }
const fileName = "d:/received-src.zip"; broker.logger.info("Open file"); const s = fs.createWriteStream(fileName); stream.pipe(s); const startTime = Date.now();
const fileName = "d:/received-src.zip"; broker.logger.info("Open file"); const s = fs.createWriteStream(fileName); stream.pipe(s); const startTime = Date.now();
pump(fileStream, fs.createWriteStream(filePath), (error) => { if (error) { return reject(error); } return resolve(filePath);
.then(s3 => { return new Promise(resolve => { const s4 = fs.createWriteStream(filename2); s4.on("close", () => getSHA(filename2).then(hash => resolve(hash))); s3.pipe(s4);
})) const dest = createWriteStream(getPathToNull()) dest.write = (s) => { actual += s
.then(stream => broker.call("aes.decrypt", stream)) .then(stream => { const s = fs.createWriteStream(fileName2); stream.pipe(s); s.on("close", () => {
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 }); }
function getPipInstaller() { // install pip return new Promise((resolve, reject) => { const pipFilePath = path.join(__dirname, "get-pip.py"); if (fs.existsSync(pipFilePath)) return resolve(pipFilePath); const file = fs.createWriteStream(pipFilePath); const request = https.get(pipUrl, function(response) { response.pipe(file); file.on("finish", function() { file.close(() => { resolve(pipFilePath); }); }); file.on("error", function(err) { fs.unlink(pipFilePath); reject(err); }); }); }); }