You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

fs-minipass

Package Overview
Dependencies
Maintainers
5
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-minipass

fs read and write streams based on minipass


Version published
Weekly downloads
33M
increased by0.29%
Maintainers
5
Install size
292 kB
Created
Weekly downloads
 

Package description

What is fs-minipass?

The fs-minipass npm package is a minimalistic implementation of a readable and writable stream for file system operations. It is designed to be lightweight and efficient, making it suitable for scenarios where you need to handle file streams with minimal overhead.

What are fs-minipass's main functionalities?

Reading from a file

This feature allows you to read data from a file using a Minipass stream. The code demonstrates how to create a readable stream from a file and pipe it through a Minipass instance to handle the data chunks.

const fs = require('fs');
const Minipass = require('fs-minipass');

const mp = new Minipass();
const readStream = fs.createReadStream('example.txt');

readStream.pipe(mp).on('data', (chunk) => {
  console.log('Read chunk:', chunk.toString());
});

Writing to a file

This feature allows you to write data to a file using a Minipass stream. The code demonstrates how to create a writable stream to a file and pipe data through a Minipass instance to write to the file.

const fs = require('fs');
const Minipass = require('fs-minipass');

const mp = new Minipass();
const writeStream = fs.createWriteStream('output.txt');

mp.pipe(writeStream);
mp.write('Hello, world!');
mp.end();

Transforming data

This feature allows you to transform data as it passes through a Minipass stream. The code demonstrates how to create a custom transform stream that converts data to uppercase before passing it along.

const Minipass = require('fs-minipass');

class UpperCaseTransform extends Minipass {
  write(chunk) {
    super.write(chunk.toString().toUpperCase());
  }
}

const mp = new UpperCaseTransform();
mp.on('data', (chunk) => {
  console.log('Transformed chunk:', chunk.toString());
});

mp.write('hello');
mp.write('world');
mp.end();

Other packages similar to fs-minipass

Changelog

Source

3.0.3 (2023-08-14)

Dependencies

  • f112e83 #43 bump minipass from 5.0.0 to 7.0.3

Readme

Source

fs-minipass

Filesystem streams based on minipass.

4 classes are exported:

  • ReadStream
  • ReadStreamSync
  • WriteStream
  • WriteStreamSync

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.

USAGE

It's just streams, you pipe them or read() them or write() to them.

const fsm = require('fs-minipass')
const readStream = new fsm.ReadStream('file.txt')
const writeStream = new fsm.WriteStream('output.txt')
writeStream.write('some file header or whatever\n')
readStream.pipe(writeStream)

ReadStream(path, options)

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 16MB
  • size 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.

WriteStream(path, options)

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

Package last updated on 14 Aug 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc