Open ecofi opened 4 months ago
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);
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.
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))