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 🙏

© 2025 – Pkg Stats / Ryan Hefner

s3-bucket-stream

v1.3.2

Published

Readable stream of the Body of every object in an S3 bucket.

Downloads

8

Readme

s3-bucket-stream

Usage

You must provide aws credentials using a credentials file or another method

const { BatchStream } = require("s3-bucket-stream")

const readableStream = BatchStream("BucketNameGoesHere")

const read = () => {
  let batch = readableStream.read()
  if (batch) {
    console.log(`Fetched batch of size ${batch.length}`)
    process.nextTick(() => {
      readableStream.once("readable", read)
    })
  }
}

readableStream.once("readable", read)

Using Generators

const { generateBatch } = require("s3-bucket-stream")

const main = async () => {
  let generator = generateBatch("BucketNameGoesHere", /* MaxKeys = 1000 */)
  for await (let item of gen) {
    console.log(item)
  }
}
main()

What is s3-bucket-stream?

s3-bucket-stream contains methods to retrieve the contents of every file in an S3 bucket in lexicographical order. It exposes stream and generator APIs for retrieving a list of all Keys in a bucket and for retrieving the Body of every Key in a bucket. It is useful for running a batch process on an EC2 instance that pulls files from S3.

Note that making LIST and GET request to S3 buckets will incur a cost on your account. See S3 Pricing for your region's costs.

Data transfer out of S3 buckets will also incur a cost on your account. See S3 Pricing for details. Note that data transfer from S3 to EC2 is free.

Local Testing

To eliminate costs while testing your batch process, you can use the library's built-in local filesystem reader. Create a folder at path ./s4 and the library will treat each subfolder of ./s4 as a bucket. You can then fill these folders with a small subset of files from your S3 buckets for testing locally. This local API is identical to the S3 API but will never make any requests to S3, only to your local filesystem.

Usage

Streams

const { localBatchStream } = require("s3-bucket-stream")
const readableStream = localBatchStream("FolderNameGoesHere")
// Use it the same way as BatchStream
const read = () => {
  let batch = readableStream.read()
  if (batch) {
    console.log("Fetched batch of size", batch.length)
    process.nextTick(() => {
      readableStream.once("readable", read)
    })
  }
}

readableStream.once("readable", read)

Generators

const { localGenerateBatch } = require("s3-bucket-stream")

const main = async () => {
  let gen = localGenerateBatch("listings0", 1)
  for await (let item of gen) {
    console.log(item)
  }
}
main()

API Reference

Batch

BatchStream and generateBatch will return the following object:

{
  Key: string
  Bucket: String
  Body: string
}

Key

KeyStream and generateKeys will return the following object

{
  Bucket: string
  Keys: string[]
}

Note that use of capitalization in the field names to match the aws-sdk interface.