npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shutterstock/chunker

v1.0.11

Published

Calls a callback before size would be exceeded or when count limit is reached

Downloads

12

Readme

License: MIT API Docs Build - CI Package and Publish Publish Docs

Overview

@shutterstock/chunker calls a blocking async callback before adding an item that would exceed a user-defined size limit OR when the count of items limit is reached.

A common use case for @shutterstock/chunker is as a "batch accumulator" that gathers up items to be processed in a batch where the batch has specific count and size constraints that must be followed. For example, sending batches to an AWS Kinesis Data Stream requires that there be 500 or less records totalling 5 MB or less in size (see AWS Kinesis PutRecords) . The record count part is easy, but the record size check and handling both is more difficult.

Getting Started

Installation

The package is available on npm as @shutterstock/chunker

npm i @shutterstock/chunker

Importing

import { Chunker } from '@shutterstock/chunker';

API Documentation

After installing the package, you might want to look at our API Documentation to learn about all the features available.

Chunker

Chunker has a BlockingQueue that it uses to store items until the size or count limits are reached. When the limits are reached, the Chunker calls the user-provided callback with the items in the queue. The callback is expected to return a Promise that resolves when the items have been processed. The Chunker will wait for the Promise to resolve before continuing.

See below for an example of using Chunker to write batches of records to an AWS Kinesis Data Stream.

Contributing

Setting up Build Environment

  • nvm use
  • npm i
  • npm run build
  • npm run lint
  • npm run test

Running Examples

aws-kinesis-writer

  1. Create Kinesis Data Stream using AWS Console or any other method
    1. Default name is chunker-test-stream
    2. 1 shard is sufficient
    3. 1 day retention is sufficient
    4. No encryption is sufficient
    5. On-demand throughput is sufficient
  2. npm run example:aws-kinesis-writer
    1. If the stream name was changed: KINESIS_STREAM_NAME=my-stream-name npm run example:aws-kinesis-writer
  3. Observe in the log output that the enqueue method intermittently blocks when the count or size constraints would be breached. During the block the records are written to the Kinesis Data Stream, after which the block is released and the new item is added to the next batch.