Skip to main content
ReadableBase.prototype.filter - Node documentation
method ReadableBase.prototype.filter

Usage in Deno

import { ReadableBase } from "node:stream";
ReadableBase.prototype.filter(
fn: (
data: any,
options?: Pick<ArrayOptions, "signal">,
) => boolean | Promise<boolean>
,
options?: ArrayOptions,
): Readable

This method allows filtering the stream. For each chunk in the stream the fn function will be called and if it returns a truthy value, the chunk will be passed to the result stream. If the fn function returns a promise - that promise will be awaited.

Parameters

fn: (
data: any,
options?: Pick<ArrayOptions, "signal">,
) => boolean | Promise<boolean>

a function to filter chunks from the stream. Async or not.

optional
options: ArrayOptions

Return Type

Readable

a stream filtered with the predicate fn.