当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Writable.write方法代码示例

本文整理汇总了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
	}
开发者ID:calebsander,项目名称:structure-bytes,代码行数:12,代码来源:appendable-stream.ts

示例2: writeOutgoingMessages

 function writeOutgoingMessages(outgoingMessages: Wrapper[], output: Writable) {
   for (const outgoingMessage of outgoingMessages) {
     const chunk = Wrapper.encodeDelimited(outgoingMessage).finish()
     output.write(chunk)
   }
   output.end()
 }
开发者ID:cucumber,项目名称:cucumber,代码行数:7,代码来源:message_serialization_test.ts

示例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
	}
开发者ID:calebsander,项目名称:structure-bytes,代码行数:16,代码来源:appendable-stream.ts

示例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()
    }
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:44,代码来源:Dataset.ts

示例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>
}
开发者ID:josephg,项目名称:statecraft,代码行数:16,代码来源:tinystream.ts

示例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)
  }
开发者ID:electron-userland,项目名称:electron-builder,代码行数:17,代码来源:multipleRangeDownloader.ts

示例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)
  }
开发者ID:ledinhphuong,项目名称:electron-builder,代码行数:17,代码来源:multipleRangeDownloader.ts


注:本文中的stream.Writable.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。