GithubHelp home page GithubHelp logo

isabella232 / fs-minipass Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/fs-minipass

0.0 0.0 0.0 222 KB

fs read and write streams based on minipass

License: ISC License

JavaScript 100.00%

fs-minipass's Introduction

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.

fs-minipass's People

Contributors

addaleax avatar iarna avatar isaacs avatar ruyadorno avatar trott avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.