本文整理汇总了TypeScript中fs.createWriteStream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createWriteStream函数的具体用法?TypeScript createWriteStream怎么用?TypeScript createWriteStream使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createWriteStream函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
import * as Archiver from 'archiver';
import * as fs from 'fs';
const archiver = Archiver.create('zip');
const writeStream = fs.createWriteStream('./archiver.d.ts');
const readStream = fs.createReadStream('./archiver.d.ts');
archiver.abort();
archiver.pipe(writeStream);
archiver.append(readStream, { name: 'archiver.d.ts' });
archiver.append(readStream, {name: 'archiver.d.ts'})
.append(readStream, {name: 'archiver.d.ts'});
archiver.bulk({ mappaing: {} });
archiver.directory('./path', './someOtherPath');
archiver.directory('./path', { name: "testName" });
archiver.directory('./', "", {});
archiver.directory('./', { name: 'test' }, {});
archiver.append(readStream, {
name: "sub/folder.xml"
});
archiver.glob("**", {
cwd: 'path/to/files',
});
archiver.glob('./path', {}, {});
示例2: mkdirp
throw c
}
if (!i.isDirectory()) throw c
}
}
return t
}
if (~installIndex) {
console.log('DIRECTORY FOUND')
const directory = process.argv[installIndex + 1]
if (directory) {
mkdirp(path.dirname(directory))
const filename = path.join(directory, path.basename(process.execPath))
const readStream = fs.createReadStream(process.execPath)
const writeStream = fs.createWriteStream(filename)
const onError = function() {
readStream.removeAllListeners()
writeStream.removeAllListeners()
//TODO
}
readStream
.on('error', onError)
.pipe(writeStream)
.on('error', onError)
.on('close', () => {
const winsw = filename.replace('.exe', '-service.exe')
fs.writeFileSync(winsw, fs.readFileSync('./nexe/plugin/daemon/winsw.exe'))
fs.writeFileSync(
示例3:
query3.select('+path');
query3.where('tags').size(0);
query3.skip(100).limit(20);
query3.slaveOk();
query3.slaveOk(true);
query3.slaveOk(false);
query3.slice('comments', -5);
query3.slice('comments', [10, 5])
query3.where('comments').slice(5);
query3.where('comments').slice([-10, 5]);
query3.snapshot();
query3.snapshot(true);
query3.snapshot(false);
query3.sort({ field: 'asc', test: -1 });
query3.sort('field -test');
Model.find({ name: /^hello/ }).stream({ transform: JSON.stringify }).pipe(fs.createWriteStream('./test.json'));
var stream = Model.find({ name: /^hello/ }).stream();
stream
.on('data', (doc: IActor) => {})
.on('error', (err: any) => {})
.on('close', () => {});
query3.tailable();
query3.tailable(false);
var AdvQuery = query3.toConstructor();
query3.update({ title: 'words' });
query3.update({ $set: { title: 'words' }});
query3.update({ name: /^match/ }, { $set: { arr: [] }}, { multi: true }, (err: any, row: number, raw: any) => {});
query3.where('loc').within({ center: [50,50], radius: 10, unique: true, spherical: true });
query3.where('loc').within({ box: [[40.73, -73.9], [40.7, -73.988]] });
示例4: getConfigRoot
let configRoot;
try {
configRoot = getConfigRoot();
} catch (ex) {
console.log(ex.message);
// tslint:disable-next-line:max-line-length
console.log(`[ERROR] config.json was not found. The location of config.json has been changed from ./src to ./ since v2.3.0.
[ERROR] 設定ファイルconfig.jsonが見つかりませんでした。v2.3.0から設定ファイルの場所が./src/config.jsonから./config.jsonに変更されました。`);
}
// console output
process.stdin.pipe(pretty({ colorize: true, withLabel: false, debug: false })).pipe(process.stdout);
// debug.log
const debugFile = fs.createWriteStream('logs/debug.log', { flags: 'a' });
process.stdin.pipe(pretty({ colorize: false, withLabel: true, debug: true })).pipe(debugFile);
// info.log
const infoTransform = process.stdin.pipe(pretty({ colorize: false, withLabel: true, debug: false }));
const infoFile = fs.createWriteStream('logs/info.log', { flags: 'a' });
infoTransform.pipe(infoFile);
// notification integrations
if (configRoot) {
const slackConfig = _.get(configRoot, 'logging.slack');
const lineConfig = _.get(configRoot, 'logging.line');
addIntegration(SlackIntegration, slackConfig);
addIntegration(LineIntegration, lineConfig);
}
示例5:
(function() {
var stream = fs.createWriteStream('path/to/my.json');
var req = request.get('/some.json');
req.pipe(stream);
})();
示例6:
(() => {
const stream = fs.createWriteStream('path/to/my.json');
const req = request.get('/some.json');
req.pipe(stream);
})();
示例7: TO_FILE
export function TO_FILE() {
return fs.createWriteStream(PATH, { flags: 'a' });
};
示例8:
const isNative: boolean = frame.isNative();
const isConstr: boolean = frame.isConstructor();
}
}
///////////////////////////////////////////////////////////
/// Console Tests : https://nodejs.org/api/console.html ///
///////////////////////////////////////////////////////////
{
{
let _c: Console = console;
_c = console2;
}
{
const writeStream = fs.createWriteStream('./index.d.ts');
let consoleInstance: Console = new console.Console(writeStream);
consoleInstance = new console.Console(writeStream, writeStream);
consoleInstance = new console.Console(writeStream, writeStream, true);
consoleInstance = new console.Console({
stdout: writeStream,
stderr: writeStream,
colorMode: 'auto',
ignoreErrors: true
});
consoleInstance = new console.Console({
stdout: writeStream,
colorMode: false
});
consoleInstance = new console.Console({
示例9: writeFile
import * as fs from 'fs';
import * as util from 'util';
import * as snekfetch from 'snekfetch';
const writeFile = util.promisify(fs.writeFile);
snekfetch.get('https://s.gus.host/o-SNAKES-80.jpg')
.then(r => writeFile('download.jpg', r.body));
snekfetch.get('https://s.gus.host/o-SNAKES-80.jpg')
.pipe(fs.createWriteStream('download.jpg'));
snekfetch.post('https://httpbin.org/post')
.send({ meme: 'dream' })
.then(r => console.log(r.body));
示例10: crashlogger
export function crashlogger(
error: Error | string, description: string, data: AnyObject | null = null
): string | null {
const datenow = Date.now();
let stack = typeof error === 'string' ? error : error.stack;
if (data) {
stack += `\n\nAdditional information:\n`;
for (const k in data) {
stack += ` ${k} = ${data[k]}\n`;
}
}
console.error(`\nCRASH: ${stack}\n`);
const out = fs.createWriteStream(logPath, {flags: 'a'});
out.on('open', () => {
out.write(`\n${stack}\n`);
out.end();
}).on('error', (err: Error) => {
console.error(`\nSUBCRASH: ${err.stack}\n`);
});
if (Config.crashguardemail && ((datenow - lastCrashLog) > CRASH_EMAIL_THROTTLE)) {
lastCrashLog = datenow;
if (!transport) {
try {
require.resolve('nodemailer');
} catch (e) {
throw new Error(
'nodemailer is not installed, but it is required if Config.crashguardemail is configured! ' +
'Run npm install --no-save nodemailer and restart the server.'
);
}
}
let text = `${description} crashed `;
if (transport) {
text += `again with this stack trace:\n${stack}`;
} else {
try {
// tslint:disable-next-line:no-implicit-dependencies
transport = require('nodemailer').createTransport(Config.crashguardemail.options);
} catch (e) {
throw new Error("Failed to start nodemailer; are you sure you've configured Config.crashguardemail correctly?");
}
text += `with this stack trace:\n${stack}`;
}
transport.sendMail({
from: Config.crashguardemail.from,
to: Config.crashguardemail.to,
subject: Config.crashguardemail.subject,
text,
}, (err: Error | null) => {
if (err) console.error(`Error sending email: ${err}`);
});
}
if (process.uptime() * 1000 < LOCKDOWN_PERIOD) {
// lock down the server
return 'lockdown';
}
return null;
}