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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rcompat/stream

v0.5.0

Published

Standard library streams

Readme

@rcompat/stream

Stream utilities for JavaScript runtimes.

What is @rcompat/stream?

A cross-runtime module providing utilities for working with Web Streams. Convert ReadableStream to strings and other common stream operations. Works consistently across Node, Deno, and Bun.

Installation

npm install @rcompat/stream
pnpm add @rcompat/stream
yarn add @rcompat/stream
bun add @rcompat/stream

Usage

Convert stream to string

import stream from "@rcompat/stream";

// From a ReadableStream
const readable = new ReadableStream({
  start(controller) {
    controller.enqueue(new TextEncoder().encode("Hello, "));
    controller.enqueue(new TextEncoder().encode("World!"));
    controller.close();
  }
});

const text = await stream.stringify(readable);
console.log(text); // "Hello, World!"

With fetch response

import stream from "@rcompat/stream";

const response = await fetch("https://example.com/data.txt");
const text = await stream.stringify(response.body);
console.log(text);

With file streams

import stream from "@rcompat/stream";
import FileRef from "@rcompat/fs/FileRef";

const file = new FileRef("./data.txt");
const content = await stream.stringify(await file.stream());
console.log(content);

API Reference

stringify

import stream from "@rcompat/stream";

stream.stringify(readable: ReadableStream): Promise<string>;

Reads all chunks from a ReadableStream, decodes them as UTF-8 text, and concatenates them into a single string.

| Parameter | Type | Description | |-----------|------------------|---------------------------| | stream | ReadableStream | The stream to read from |

Returns: Promise<string> — The complete stream content as a string.

Throws: If the input is not a ReadableStream instance.

How It Works

The stringify function:

  1. Gets a reader from the stream via getReader()
  2. Recursively reads chunks until done is true
  3. Decodes each chunk using TextDecoder (UTF-8)
  4. Filters out any undefined values
  5. Joins all decoded chunks into a single string
// Simplified implementation
const decoder = new TextDecoder();

async function stringify(stream) {
  const reader = stream.getReader();
  const chunks = [];

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;
    chunks.push(decoder.decode(value));
  }

  return chunks.join("");
}

Examples

Process streaming API response

import stream from "@rcompat/stream";

async function fetchJSON(url) {
  const response = await fetch(url);
  const text = await stream.stringify(response.body);
  return JSON.parse(text);
}

const data = await fetchJSON("https://api.example.com/users");

Read subprocess output

import stream from "@rcompat/stream";
import spawn from "@rcompat/io/spawn";

const { stdout } = spawn("ls -la", { cwd: "." });
const output = await stream.stringify(stdout);
console.log(output);

Collect streaming chunks

import stream from "@rcompat/stream";

async function collectSSE(url) {
  const response = await fetch(url);
  // note: For actual SSE, you'd process chunks individually
  // this example just collects everything
  return await stream.stringify(response.body);
}

Transform and stringify

import stream from "@rcompat/stream";

const source = new ReadableStream({
  start(controller) {
    controller.enqueue(new TextEncoder().encode("line1\n"));
    controller.enqueue(new TextEncoder().encode("line2\n"));
    controller.close();
  }
});

// transform stream (uppercase)
const transformed = source.pipeThrough(new TransformStream({
  transform(chunk, controller) {
    const text = new TextDecoder().decode(chunk);
    controller.enqueue(new TextEncoder().encode(text.toUpperCase()));
  }
}));

const result = await stream.stringify(transformed);
console.log(result); // "LINE1\nLINE2\n"

Cross-Runtime Compatibility

| Runtime | Supported | |---------|-----------| | Node.js | ✓ | | Deno | ✓ | | Bun | ✓ |

No configuration required — just import and use.

License

MIT

Contributing

See CONTRIBUTING.md in the repository root.