本文整理汇总了TypeScript中stream.Writable.write方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Writable.write方法的具体用法?TypeScript Writable.write怎么用?TypeScript Writable.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Writable
的用法示例。
在下文中一共展示了Writable.write方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addAll
/**
* Appends a contiguous set of bytes
* to the end of the written data
* @param buffer The bytes to add
*/
addAll(buffer: ArrayBuffer) {
assert.instanceOf(buffer, ArrayBuffer)
if (this.pauseCount) this.paused.addAll(buffer)
else this.outStream.write(Buffer.from(buffer))
this.writtenBytes += buffer.byteLength
return this
}
示例2: writeOutgoingMessages
function writeOutgoingMessages(outgoingMessages: Wrapper[], output: Writable) {
for (const outgoingMessage of outgoingMessages) {
const chunk = Wrapper.encodeDelimited(outgoingMessage).finish()
output.write(chunk)
}
output.end()
}
示例3: resume
/**
* See [[pause]].
* Flushes all paused data to the output
* and exits paused mode.
* @throws If not currently paused
*/
resume() {
if (!this.pauseCount) throw new Error('Was not paused')
this.pauseCount--
if (this.pauseCount) this.paused.resume() //still in pause stack
else { //emptied pause stack
this.outStream.write(Buffer.from(this.paused.rawBuffer, 0, this.paused.length))
this.paused = new GrowableBuffer //must use a new buffer to avoid overwriting data sent to outStream
}
return this
}
示例4: 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()
}
示例5: 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>
}
示例6: 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)
}
示例7: w
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)
}