Coder Social home page Coder Social logo

mwizeman / node-buffer-peek-stream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from seangarner/node-buffer-peek-stream

0.0 0.0 0.0 48 KB

Node Transform stream that lets you inspect the start of a ReadStream before deciding what to do with it

License: MIT License

JavaScript 100.00%

node-buffer-peek-stream's Introduction

node-buffer-peek-stream

Build Status

Take a peek at the start of a stream and get back a new stream rewound from the start without buffering the entire stream. Useful when you need to inspect the start of the stream before deciding what to do with the stream.

npm install buffer-peek-stream

Useful if you want to inspect the start of a stream before deciding what to do with it.

This works with buffers and does no string decoding. If you know you have a string and already know its encoding then checkout peek-stream.

Usage

As a promise (with await)...

const peek = require('buffer-peek-stream').promise;
const readstream = fs.createReadStream('package.json');

const [data, outputStream] = await peek(readstream, 65536);

// outputStream is ready to be piped somewhere else
outputStream.pipe(somewhere_else);

As a callback...

var peek = require('buffer-peek-stream');
var readstream = fs.createReadStream('package.json');

peek(readstream, 65536, function (err, data, outputStream) {
  if (err) throw err;

  // outputStream is ready to be piped somewhere else
  outputStream.pipe(somewhere_else);
});

As a stream...

var PeekStream = require('buffer-peek-stream').BufferPeekStream;

var peek = new PeekStream(65536);
var readstream = fs.createReadStream('package.json');

// peek will only emit the peek event once
peek.once('peek', function (buf) {

  // readstream is ready to be piped somewhere else
  peek.pipe(somewhere_else);
});

readstream.pipe(peek);

// alternatively pipe `peek` here instead of in `data` callback

Licence

MIT

node-buffer-peek-stream's People

Contributors

dependabot[bot] avatar salketer avatar seangarner 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.