• Convert a Stream to an async iterator

    Type Parameters

    • Data = any

    Parameters

    • stream: Readable | ReadableStream<Data>

    Returns AsyncIterable<Data>

    Example

    import { stream } from "@rjweb/utils"
    import * as fs from "fs"

    const readStream = fs.createReadStream('./file.txt')

    for await (const chunk of stream.iterator<Buffer>(readStream)) {
    console.log(chunk.toString())
    }

    Since

    1.9.0

    Supports

    nodejs, browser