Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
The 'destroy' npm package is used to destroy a stream, such as a request or response, ensuring that it cannot be used anymore. It is particularly useful for ensuring that file descriptors are closed and memory usage is cleaned up after streams are no longer needed.
Destroy a stream
This code sample demonstrates how to destroy a readable stream using the 'destroy' package. Once the stream is destroyed, it cannot emit any more events or be used to read data.
const destroy = require('destroy');
const fs = require('fs');
const stream = fs.createReadStream('file.txt');
stream.on('data', (chunk) => {
console.log(chunk);
});
// Destroy the stream
destroy(stream);
The 'pump' package is similar to 'destroy' in that it helps manage stream lifecycle. It pipes streams together and destroys all of them if one of them closes. Compared to 'destroy', 'pump' is more about connecting streams and handling their collective destruction.
The 'end-of-stream' package is used to call a callback when a stream has finished or failed, which is somewhat similar to 'destroy' in managing stream end lifecycle. Unlike 'destroy', it does not destroy the stream but rather provides a way to detect the end of a stream.
The 'through2' package is a tiny wrapper around Node.js streams.Transform, making it easier to create transform streams. While it does not directly destroy streams like 'destroy', it can be used to manage stream transformations and can be combined with stream destruction for cleanup purposes.
Destroy a stream.
This module is meant to ensure a stream gets destroyed, handling different APIs and Node.js bugs.
var destroy = require('destroy')
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:
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
.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.stream
is not an instance of Stream
, then nothing happens.stream
has a .destroy()
method, then call it.The function returns the stream
passed in as the argument.
var destroy = require('destroy')
var fs = require('fs')
var stream = fs.createReadStream('package.json')
// ... and later
destroy(stream)
FAQs
destroy a stream if possible
The npm package destroy receives a total of 26,889,787 weekly downloads. As such, destroy popularity was classified as popular.
We found that destroy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.