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

Adding the possibility to parse web streams (instead of nodestreams) #269

Open
ecofi opened this issue Mar 2, 2024 · 2 comments
Open

Adding the possibility to parse web streams (instead of nodestreams) #269

ecofi opened this issue Mar 2, 2024 · 2 comments

Comments

@ecofi
Copy link

ecofi commented Mar 2, 2024

Is there an chance to implement web streams so that we can use sax.js in browser with fetch response directly? This would be really awesome and because nodejs is now also implementing web stream API it could be the approach for having a single stream implementation.
I'm looking for something like this:

fetch("very-large.xml").then((response) => response.body.pipeThrough(saxWebStream))

@linnhtun
Copy link

linnhtun commented Jun 26, 2024

you can use this way

import { Readable } from "node:stream";
import sax from "sax";

const xmlParser = sax.createStream(true, {
trim: true,
lowercase: true,
});
const res = await fetch(url.url);
const s = Readable.fromWeb(res.body).pipe(xmlParser);

@ecofi
Copy link
Author

ecofi commented Jun 26, 2024

Thank you, but this would not work in a browser. I cloned and adjusted the saxparser to get it working with native fetch API webstream. Another alternative would be to use a js lib that converts webstream into nodestreams in a browser.

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

2 participants