Files
Guangyue Xu bffee6084d npm pakage security updates
Ran the following script to update engine.io and socket.io packages
to address the security issue tracked in crbug.com/1447254:

`npm run install-deps audit fix --audit-level=critical`

Bug: 1447254
Change-Id: Ia617b76882259bdab5259855029353701ff0bc1e
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/4551951
Reviewed-by: Danil Somsikov <dsv@chromium.org>
Reviewed-by: Brandon Walderman <brwalder@microsoft.com>
Commit-Queue: Guangyue Xu <guangyue.xu@microsoft.com>
2023-05-23 16:50:12 +00:00

2.4 KiB

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)