Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

it-reader

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

it-reader

Read an exact number of bytes from a binary (async) iterable

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29K
increased by15%
Maintainers
1
Weekly downloads
 
Created
Source

it-reader

Build Status dependencies Status JavaScript Style Guide

Read an exact number of bytes from a binary (async) iterable

Install

npm install it-reader

Usage

const Reader = require('it-reader')

const reader = Reader(source) // source is any iterable or async iterable
const { value, done } = await reader.next(8)

// NOTE: value is a BufferList (https://npm.im/bl)
console.log(value.toString())

// Now read 16 more bytes:
await reader.next(16)

// or...
// Consume the rest of the stream

for await (const chunk of reader) {
  console.log(chunk.toString())
}

API

const Reader = require('it-reader')

Reader(source)

Create and return a new reader.

Parameters
Returns

An async iterator that yields BufferList objects.

The iterator's next method takes an optional parameter - the number of bytes to read from the source.

If the number of bytes to read are not specified, the iterator will yield any bytes remaining in the internal buffer or the next available chunk.

If the number of bytes to read exceeds the number of bytes available in the source the iterator will throw and error with a code property set to 'ERR_UNDER_READ' and a buffer property (the bytes read so far, if any), which is a BufferList instance.

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

Keywords

FAQs

Package last updated on 08 Apr 2021

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc