本文整理汇总了TypeScript中fs-extra.createWriteStream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createWriteStream函数的具体用法?TypeScript createWriteStream怎么用?TypeScript createWriteStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createWriteStream函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
.then(res => {
let resStream = res.body;
let writeStream = FS.createWriteStream(tmpPackagePath);
resStream.pipe(writeStream);
return Promise.for(writeStream, 'close', [resStream]);
})
示例2: Promise
new Promise(async (resolve, reject) => {
const content = /jsx?$/.test(path.extname(file)) ? await format(raw) : raw
const stream = fs.createWriteStream(file)
stream.write(content, 'utf-8')
stream.on('finish', () => resolve())
stream.on('error', err => reject(err))
stream.end()
})
示例3: createArchive
async function createArchive(ref: string): Promise<any> {
const tar = spawn('git', ['archive', '--format', 'tar.gz', ref])
const file = tmp.fileSync({postfix: '.tar.gz'})
const write = tar.stdout.pipe(fs.createWriteStream(file.name))
return new Promise((resolve, reject) => {
write.on('close', () => resolve(file.name))
write.on('error', reject)
})
}
示例4: Promise
.then(() => new Promise((resolve, reject) => {
const rd = fs.createReadStream(from);
rd.on('error', (err: Error) => reject(err));
const wr = fs.createWriteStream(to);
wr.on('error', (err: Error) => reject(err));
wr.on('close', () => resolve());
rd.pipe(wr);
}));
示例5:
return new Promise<void>((resolve, reject) => {
const rs = fs.createReadStream(from);
const ws = fs.createWriteStream(to);
rs.on('error', reject);
ws.on('error', reject);
ws.on('close', resolve);
rs.pipe(ws);
});
示例6: dataExport
async function dataExport() {
await db.connect()
const slugs = (await fs.readFile("/Users/mispy/tmp/urls.txt", "utf8")).split("\n").filter(s => s.trim())
const slugToId = await Chart.mapSlugsToIds()
const idsToGet = slugs.map(slug => slugToId[slug])
const variables = await db.query("SELECT v.name, v.id FROM variables v JOIN chart_dimensions cd ON cd.variableId=v.id WHERE cd.chartId IN (?)", [idsToGet])
const variableIds = variables.map((v: any) => v.id)
const stream = fs.createWriteStream("/Users/mispy/tmp/sdgs.csv")
// From dataset CSV export
const csvHeader = ["Entity", "Year"]
for (const variable of variables) {
csvHeader.push(variable.name)
}
const columnIndexByVariableId: {[key: number]: number} = {}
for (const variable of variables) {
columnIndexByVariableId[variable.id] = csvHeader.indexOf(variable.name)
}
stream.write(csvRow(csvHeader))
const data = await db.query(`
SELECT e.name AS entity, dv.year, dv.value, dv.variableId FROM data_values dv
JOIN variables v ON v.id=dv.variableId
JOIN entities e ON dv.entityId=e.id
WHERE v.id IN (?)
ORDER BY e.name ASC, dv.year ASC, dv.variableId ASC`, [variableIds])
let row: string[] = []
for (const datum of data) {
if (datum.entity !== row[0] || datum.year !== row[1]) {
// New row
if (row.length) {
stream.write(csvRow(row))
}
row = [datum.entity, datum.year]
for (const variable of variables) {
row.push("")
}
}
row[columnIndexByVariableId[datum.variableId]] = datum.value
}
// Final row
stream.write(csvRow(row))
stream.end()
await db.end()
}
示例7: download
async download(url: string, targetFilePath: string) {
await fs.mkdirp(path.dirname(targetFilePath));
const writeStream = fs.createWriteStream(targetFilePath);
await new Promise((resolve, reject) => {
const downloadStream = got.stream(url);
downloadStream.pipe(writeStream);
downloadStream.on('error', error => reject(error));
writeStream.on('error', error => reject(error));
writeStream.on('close', () => resolve());
});
}
示例8: makeArchive
function makeArchive(app: string, includeDotfiles: boolean) {
// create a file to stream archive data to.
const { name: tarPath } = tmp.fileSync({
discardDescriptor: true,
prefix: `${app}-deploy-`,
postfix: '.tar.gz'
});
const output = fs.createWriteStream(tarPath);
const archive = archiver('tar', {
gzip: true
});
// listen for all archive data to be written
output.on('close', () => {
// print something?
});
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
// log warning
} else {
// throw error
throw err;
}
});
// good practice to catch this error explicitly
archive.on('error', (err) => {
throw err;
});
// pipe archive data to the file
archive.pipe(output);
return globby('**', {
dot: includeDotfiles,
gitignore: true,
gitignoreName: '.skyignore'
})
.then((paths: [string]) => {
paths.forEach((path) => {
archive.file(path, {
name: path
});
});
// finalize the archive (ie we are done appending files but streams have to finish yet)
return archive.finalize();
})
.then(() => {
return tarPath;
});
}
示例9: logError
function logError(err: Error) {
let p = path.join(cacheDir, 'weather.log')
let log = fs.createWriteStream(p)
log.write(new Date() + '\n')
log.write(err.stack + '\n')
console.log(`#[fg=red]${p.replace(os.homedir(), '~')}`)
try {
fs.removeSync(path.join(cacheDir, 'weather.json'))
} catch (err) {
console.error(err)
notify(err.stack)
}
}
示例10: Promise
return new Promise((resolve, reject) => {
const writeStream = createWriteStream(destPath);
writeStream.on('error', (err: Error) => {
reject(err);
});
writeStream.on('close', () => {
resolve();
});
createReadStream(srcPath).pipe(writeStream);
});