destroy

中文文档
1.2.0发布于 2022/03/21MIT零依赖近 30 天下载 2.9亿

destroy a stream if possible

原始使用文档
文档目录3 节
  1. API
  2. destroy(stream [, suppress])
  3. Example

destroy

NPM version Build Status Test coverage License Downloads

Destroy a stream.

This module is meant to ensure a stream gets destroyed, handling different APIs and Node.js bugs.

API

var destroy = require('destroy')

destroy(stream [, suppress])

Destroy the given stream, and optionally suppress any future error events.

In most cases, this is identical to a simple stream.destroy() call. The rules are as follows for a given stream:

  1. If the stream is an instance of ReadStream, then call stream.destroy() and add a listener to the open event to call stream.close() if it is fired. This is for a Node.js bug that will leak a file descriptor if .destroy() is called before open.
  2. If the stream is an instance of a zlib stream, then call stream.destroy() and close the underlying zlib handle if open, otherwise call stream.close(). This is for consistency across Node.js versions and a Node.js bug that will leak a native zlib handle.
  3. If the stream is not an instance of Stream, then nothing happens.
  4. If the stream has a .destroy() method, then call it.

The function returns the stream passed in as the argument.

Example

var destroy = require('destroy')

var fs = require('fs')
var stream = fs.createReadStream('package.json')

// ... and later
destroy(stream)

版本与发布记录

destroy 共发布 6 个版本,首次发布于 2013/10/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2022/03/214 年前
1.1.12022/03/014 年前
1.1.02022/01/264 年前
1.0.42016/01/1610 年前
1.0.32014/08/1512 年前
0.0.02013/10/0413 年前

关于 destroy 的常见问题

destroy 是什么?

destroy a stream if possible

如何安装 destroy?

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

destroy 支持 TypeScript 吗?

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

destroy 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 0.8。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

destroy 可以商用吗?

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

destroy 的下载量有多少?

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

destroy 还在维护吗?

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