
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
@isaacs/fs-minipass
Advanced tools
@isaacs/fs-minipass is a minimalistic file system streaming library for Node.js. It provides a simplified interface for reading and writing files using streams, making it easier to handle file operations in an efficient and non-blocking manner.
Reading Files
This feature allows you to read files using a stream. The code sample demonstrates how to create a ReadStream to read the contents of 'example.txt' and log each chunk of data to the console.
const { ReadStream } = require('@isaacs/fs-minipass');
const fs = require('fs');
const readStream = new ReadStream('example.txt');
readStream.on('data', (chunk) => {
console.log('Read chunk:', chunk.toString());
});
readStream.on('end', () => {
console.log('Finished reading file');
});
Writing Files
This feature allows you to write data to files using a stream. The code sample demonstrates how to create a WriteStream to write 'Hello, world!' to 'output.txt' and log a message when the writing is finished.
const { WriteStream } = require('@isaacs/fs-minipass');
const fs = require('fs');
const writeStream = new WriteStream('output.txt');
writeStream.write('Hello, world!');
writeStream.end();
writeStream.on('finish', () => {
console.log('Finished writing to file');
});
Piping Streams
This feature allows you to pipe data from a read stream to a write stream, effectively copying the contents of one file to another. The code sample demonstrates how to read from 'example.txt' and write to 'copy.txt' using streams.
const { ReadStream, WriteStream } = require('@isaacs/fs-minipass');
const fs = require('fs');
const readStream = new ReadStream('example.txt');
const writeStream = new WriteStream('copy.txt');
readStream.pipe(writeStream);
writeStream.on('finish', () => {
console.log('Finished copying file');
});
fs-extra is a popular library that extends the native Node.js fs module with additional methods and promises support. It provides a higher-level API for file system operations, including copying, moving, and removing files and directories. Compared to @isaacs/fs-minipass, fs-extra offers a broader range of file system utilities but does not focus specifically on streaming.
The stream module is a core Node.js module that provides a foundation for working with streaming data. It includes classes for readable, writable, duplex, and transform streams. While @isaacs/fs-minipass is built on top of the stream module and offers a simplified interface for file system streams, the stream module itself provides more general-purpose streaming capabilities.
through2 is a small and simple utility for creating transform streams in Node.js. It allows you to easily create streams that can modify or transform data as it passes through. While @isaacs/fs-minipass focuses on file system streams, through2 is more general-purpose and can be used for a variety of streaming data transformations.
Filesystem streams based on minipass.
4 classes are exported:
When using ReadStreamSync
, all of the data is made available
immediately upon consuming the stream. Nothing is buffered in memory
when the stream is constructed. If the stream is piped to a writer,
then it will synchronously read()
and emit data into the writer as
fast as the writer can consume it. (That is, it will respect
backpressure.) If you call stream.read()
then it will read the
entire file and return the contents.
When using WriteStreamSync
, every write is flushed to the file
synchronously. If your writes all come in a single tick, then it'll
write it all out in a single tick. It's as synchronous as you are.
The async versions work much like their node builtin counterparts, with the exception of introducing significantly less Stream machinery overhead.
It's just streams, you pipe them or read() them or write() to them.
import { ReadStream, WriteStream } from 'fs-minipass'
// or: const { ReadStream, WriteStream } = require('fs-minipass')
const readStream = new ReadStream('file.txt')
const writeStream = new WriteStream('output.txt')
writeStream.write('some file header or whatever\n')
readStream.pipe(writeStream)
Path string is required, but somewhat irrelevant if an open file descriptor is passed in as an option.
Options:
fd
Pass in a numeric file descriptor, if the file is already open.readSize
The size of reads to do, defaults to 16MBsize
The size of the file, if known. Prevents zero-byte read()
call at the end.autoClose
Set to false
to prevent the file descriptor from being
closed when the file is done being read.Path string is required, but somewhat irrelevant if an open file descriptor is passed in as an option.
Options:
fd
Pass in a numeric file descriptor, if the file is already open.mode
The mode to create the file with. Defaults to 0o666
.start
The position in the file to start reading. If not
specified, then the file will start writing at position zero, and be
truncated by default.autoClose
Set to false
to prevent the file descriptor from being
closed when the stream is ended.flags
Flags to use when opening the file. Irrelevant if fd
is
passed in, since file won't be opened in that case. Defaults to
'a'
if a pos
is specified, or 'w'
otherwise.FAQs
fs read and write streams based on minipass
The npm package @isaacs/fs-minipass receives a total of 3,840,921 weekly downloads. As such, @isaacs/fs-minipass popularity was classified as popular.
We found that @isaacs/fs-minipass demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.