Skip to main content
On this page

@std/streams

Overview Jump to heading

Utilities for working with the Streams API.

Includes buffering and conversion.

import { toText } from "@std/streams";
import { assertEquals } from "@std/assert";

const stream = ReadableStream.from(["Hello, world!"]);
const text = await toText(stream);

assertEquals(text, "Hello, world!");

Add to your project Jump to heading

deno add jsr:@std/streams

See all symbols in @std/streams on

What are Web Streams? Jump to heading

Web Streams provide a standard way to handle streaming data in JavaScript. They allow you to process data piece by piece as it arrives, rather than waiting for the entire dataset to be available. This is particularly useful for handling large files, network requests, or any situation where data is produced over time.

Why use @std/streams? Jump to heading

Use for buffering, converting, and composing Web Streams efficiently.

Examples Jump to heading

import { copy, readerFromStreamReader, writeAll } from "@std/streams";

// Copy from a file to another file via streams
const r = await Deno.open("input.txt");
const w = await Deno.open("output.txt", {
  create: true,
  write: true,
  truncate: true,
});
await copy(r, w);
r.close();
w.close();

// Convert a ReadableStreamDefaultReader to a Deno.Reader
const res = await fetch("https://deno.land");
const denoReader = readerFromStreamReader(res.body!.getReader());
await writeAll(
  Deno.stdout,
  new Uint8Array(await new Response(denoReader).arrayBuffer()),
);

Tips Jump to heading

  • Prefer streaming for large payloads to reduce memory pressure.
  • Use helpers like toText, toArrayBuffer, and iterateReader for conversions.

Did you find what you needed?

Privacy policy