Socket
Socket
Sign inDemoInstall

peekaboo

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    peekaboo

Peekable transform stream


Version published
Maintainers
1
Install size
4.85 kB
Created

Readme

Source

#peekaboo

A Peekable node stream.

A Peekaboo stream works just like a PassThrough stream, it can be piped to and from without any transformation of the chunks. The difference is that a Peekaboo stream will emit each chunk as a peek event on an EventEmitter of your choosing, letting you spy on stream chunks in an uninvasive way.

Build Status

Lead Maintainer - Eran Hammer

Example

We can report the download process of a request by peeking on response stream events:

'use strict';

const Events = require('events');
const Fs = require('fs');
const Https = require('https');
const Peekaboo = require('peekaboo');

const emitter = new Events.EventEmitter();
const peek = new Peekaboo(emitter);

Https.get('https://codeload.github.com/hapijs/hapi/zip/master', (res) => {

    res.pipe(peek).pipe(Fs.createWriteStream('./hapi.zip'));

    let downloaded = 0;
    emitter.on('peek', (chunk) => {

        downloaded += chunk.length;
        const pct = (downloaded / res.headers['content-length'] * 100).toFixed(1);
        process.stdout.write(pct + '% downloaded\r');
    });
});

Keywords

FAQs

Last updated on 28 Jul 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc