本文整理汇总了TypeScript中stream.Writable.end方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Writable.end方法的具体用法?TypeScript Writable.end怎么用?TypeScript Writable.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Writable
的用法示例。
在下文中一共展示了Writable.end方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: writeOutgoingMessages
function writeOutgoingMessages(outgoingMessages: Wrapper[], output: Writable) {
for (const outgoingMessage of outgoingMessages) {
const chunk = Wrapper.encodeDelimited(outgoingMessage).finish()
output.write(chunk)
}
output.end()
}
示例2: write
export const wrapWriter = <Msg>(w: Writable, encode?: (msg: Msg) => any) => {
return {
write(data) {
if (w.writable) {
w.write(encode ? encode(data) : data)
// Work around this bug:
// https://github.com/kawanet/msgpack-lite/issues/80
if ((w as any).encoder) (w as any).encoder.flush()
}
},
close() {
w.end()
}
} as TinyWriter<Msg>
}
示例3: doExecuteTasks
const w = (taskOffset: number) => {
if (taskOffset >= tasks.length) {
if (differentialDownloader.fileMetadataBuffer != null) {
out.write(differentialDownloader.fileMetadataBuffer)
}
out.end()
return
}
const nextOffset = taskOffset + 1000
doExecuteTasks(differentialDownloader, {
tasks,
start: taskOffset,
end: Math.min(tasks.length, nextOffset),
oldFileFd,
}, out, () => w(nextOffset), reject)
}
示例4: _executeTasks
const w = (taskOffset: number) => {
if (taskOffset >= tasks.length) {
if (differentialDownloader.fileMetadataBuffer != null) {
out.write(differentialDownloader.fileMetadataBuffer)
}
out.end()
return
}
const nextOffset = taskOffset + (differentialDownloader.options.useMultipleRangeRequest === false ? 1 : 1000)
_executeTasks(differentialDownloader, {
tasks,
start: taskOffset,
end: Math.min(tasks.length, nextOffset),
oldFileFd,
}, out, () => w(nextOffset), reject)
}
示例5: writeCSV
// Export dataset variables to CSV (not including metadata)
static async writeCSV(datasetId: number, stream: Writable) {
const csvHeader = ["Entity", "Year"]
const variables = await db.query(`SELECT name, id FROM variables v WHERE v.datasetId=? ORDER BY v.columnOrder ASC, v.id ASC`, [datasetId])
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 datasets d ON v.datasetId=d.id
JOIN entities e ON dv.entityId=e.id
WHERE d.id=?
ORDER BY e.name ASC, dv.year ASC, v.columnOrder ASC, dv.variableId ASC`, [datasetId])
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()
}
示例6: setImmediate
setImmediate(() => dst.end(src)) // string or Buffer
示例7: end
/**
* Closes the underlying stream
*/
end(): void {
this.outStream.end()
}
示例8:
socket.on('close', () => {
writer.end() // Does this help??
reader.isClosed = true
reader.onClose && reader.onClose()
})
示例9: Error
process.nextTick(() => {
const err = new Error(SourceError[401]);
err.stack = option.path;
writer.emit("error", err, option);
writer.end();
});