Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream is not async iterable (DuplexWrapper) #282

Open
lapo-luchini opened this issue Jun 25, 2023 · 0 comments
Open

stream is not async iterable (DuplexWrapper) #282

lapo-luchini opened this issue Jun 25, 2023 · 0 comments

Comments

@lapo-luchini
Copy link

I'm trying to decode a single file content to string using async iterators:

async function streamToString(stream) {
    // https://stackoverflow.com/a/63361543/166524
    const chunks = [];
    for await (const chunk of stream) {
        chunks.push(Buffer.from(chunk));
    }
    return Buffer.concat(chunks).toString("utf8");
}

const stream = fs.createReadStream(proj)
    .pipe(unzipper.ParseOne(reFile));
const data = await streamToString(stream);

but it fails like this:

TypeError: stream is not async iterable

OTOH this works fine:

function streamToString(stream) {
    const chunks = [];
    return new Promise((resolve, reject) => {
        stream.on('data', chunk => chunks.push(chunk));
        stream.on('error', err => reject(err));
        stream.on('end', () => resolve(Buffer.concat(chunks).toString("utf8")));
    });
}

I see that nodejs' Duplex itself had this bug two years ago, might this be related?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant