Skip to main content

@std/io@0.225.0

UNSTABLE: The utilities for advanced I/O operations using Reader and Writer interfaces.

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
88%
Published
a month ago (0.225.0)
function iterateReaderSync
iterateReaderSync(
reader: ReaderSync,
options?: { bufSize?: number; },
): IterableIterator<Uint8Array>

Turns a ReaderSync into an iterator.

Examples

Usage

import { iterateReaderSync } from "@std/io/iterate-reader";
import { assert } from "@std/assert/assert"

using file = Deno.openSync("README.md");
for (const chunk of iterateReaderSync(file)) {
  assert(chunk instanceof Uint8Array);
}

Second argument can be used to tune size of a buffer. Default size of the buffer is 32kB.

Usage with buffer size

import { iterateReaderSync } from "@std/io/iterate-reader";
import { assert } from "@std/assert/assert"

using file = await Deno.open("README.md");
const iter = iterateReaderSync(file, {
  bufSize: 1024 * 1024
});
for (const chunk of iter) {
  assert(chunk instanceof Uint8Array);
}

Iterator uses an internal buffer of fixed size for efficiency; it returns a view on that buffer on each iteration. It is therefore caller's responsibility to copy contents of the buffer if needed; otherwise the next iteration will overwrite contents of previously returned chunk.

Parameters

reader: ReaderSync

The reader to read from

optional
options: { bufSize?: number; }

The options

Return Type

IterableIterator<Uint8Array>

The iterator of Uint8Array chunks

Add Package

deno add jsr:@std/io

Import symbol

import { iterateReaderSync } from "@std/io/iterate-reader";

---- OR ----

Import directly with a jsr specifier

import { iterateReaderSync } from "jsr:@std/io/iterate-reader";

Add Package

npx jsr add @std/io

Import symbol

import { iterateReaderSync } from "@std/io/iterate-reader";

Add Package

yarn dlx jsr add @std/io

Import symbol

import { iterateReaderSync } from "@std/io/iterate-reader";

Add Package

pnpm dlx jsr add @std/io

Import symbol

import { iterateReaderSync } from "@std/io/iterate-reader";

Add Package

bunx jsr add @std/io

Import symbol

import { iterateReaderSync } from "@std/io/iterate-reader";