Socket
Socket
Sign inDemoInstall

block-iterator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

block-iterator

Transform input into equally-sized blocks of output


Version published
Weekly downloads
2.5K
decreased by-20.63%
Maintainers
1
Weekly downloads
 
Created
Source

block-iterator

Transform input into equally-sized chunks as output.

A majorly simplified version of block-stream2. Dependency free and very fast.

Usage

import blockIterator from 'block-iterator'
import { Readable } from 'streamx'

const stream = fs.createReadStream(__dirname + '/letters.txt')

const asyncIterator = blockIterator(stream, 16, { zeroPadding: true })
const stream = Readable.from(asyncIterator)

stream.pipe(process.stdout)

// or

for await (const letters of blockIterator(stream, { size: 16, zeroPadding: true })) { // top level await
  console.log(letters)
}

Yields:

cat cag car cet
ceg cer cit cig
cir cot cog cor
cut cug cur dat
dag dar det deg
der dit dig dir
dot dog dor dut
dug dur fat fag
far fet feg fer
fit fig fir fot
fog for fut fug
fur\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00

Methods

import blockIterator from 'block-iterator'

const b = blockIterator(opts)

const b = blockIterator(size, opts)

Create a new async iterator b that outputs chunks of length size or opts.size.

When opts.zeroPadding is false, do not zero-pad the last chunk.

Install

With npm do:

npm install block-iterator

License

MIT

Keywords

FAQs

Package last updated on 25 Nov 2022

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