Skip to content

Path.iterdirStream() method

pathlib-ts > Path > iterdirStream

Streams directory entries lazily using async iteration without materialising the entire directory listing.

Signature:

iterdirStream(options?: {
extra?: {
withFileTypes?: false;
};
}): AsyncIterable<Path>;

Parameter

Type

Description

options

{ extra?: { withFileTypes?: false; }; }

(Optional) Optional flags controlling the yielded value type.

Returns:

AsyncIterable<Path>

An async iterable yielding Path objects or Dirents.

The UnsupportedOperation When requesting withFileTypes without runtime support.

Shares the same extra.withFileTypes behaviour as Path.iterdir(). Uses fs.opendir when available to avoid materialising the whole directory; otherwise falls back to buffered reads. Throws UnsupportedOperation when withFileTypes is requested but not supported.

Streaming a large media folder

import { Path } from "pathlib-ts";
const media = new Path("/var/media");
for await (const entry of media.iterdirStream()) {
if (await entry.isFile()) {
console.log(entry.name);
}
}