through

中文文档
2.3.8发布于 2015/07/03MITCommonJS零依赖近 30 天下载 1.8亿

simplified stream construction

原始使用文档
文档目录3 节
  1. Extended Options
  2. autoDestroy=false
  3. License

#through

build status testling badge

Easy way to create a Stream that is both readable and writable.

  • Pass in optional write and end methods.
  • through takes care of pause/resume logic if you use this.queue(data) instead of this.emit('data', data).
  • Use this.pause() and this.resume() to manage flow.
  • Check this.paused to see current flow state. (write always returns !this.paused).

This function is the basis for most of the synchronous streams in event-stream.

var through = require('through')

through(function write(data) {
    this.queue(data) //data *must* not be null
  },
  function end () { //optional
    this.queue(null)
  })

Or, can also be used without buffering on pause, use this.emit('data', data), and this.emit('end')

var through = require('through')

through(function write(data) {
    this.emit('data', data)
    //this.pause() 
  },
  function end () { //optional
    this.emit('end')
  })

Extended Options

You will probably not need these 99% of the time.

autoDestroy=false

By default, through emits close when the writable and readable side of the stream has ended. If that is not desired, set autoDestroy=false.

var through = require('through')

//like this
var ts = through(write, end, {autoDestroy: false})
//or like this
var ts = through(write, end)
ts.autoDestroy = false

License

MIT / Apache2

版本与发布记录

through 共发布 29 个版本,首次发布于 2012/07/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.3.8latest2015/07/0311 年前
2.3.72015/04/0611 年前
2.3.62014/09/1612 年前
2.3.42013/04/2913 年前
2.3.32013/04/2513 年前
2.3.22013/04/2413 年前

关于 through 的常见问题

through 是什么?

simplified stream construction

如何安装 through?

在项目目录运行 npm install through,或使用 pnpm add / yarn add / bun add。

through 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/through 是否存在。

through 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

through 可以商用吗?

through 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

through 的下载量有多少?

根据 npm 官方下载统计,through 在 2026/10/05 – 2026/11/03 这 30 天内被下载 183,656,968 次,日均约 6,121,899 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

through 还在维护吗?

最新版本 2.3.8 发布于 2015/07/03(11 年前);至今共发布 29 个版本,其中过去 12 个月发布了 0 个;首次发布于 2012/07/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。