Open lostfictions opened 3 years ago
I think Webpack and Browserify already shim the streams module
Webpack recently dropped support for that in 5+, but the general recommendation is that you're supposed to polyfill it yourself with resolve.fallback
and a webpack.ProvidePlugin
(for global process
object).
There shouldn't be any specific need to support browser except to interop using the browser's version of Readable and Writeable streams, which are making their way into all browsers.
Currently I'm making this work in the browser using something like:
// Eventually, we will want to use .pipeTo or .pipeThrough in browsers when
// they implement that, for now we have to kind of do it ourselves
const readable = resp.body as any;
if (!readable.pipe) {
async function pipePolyfill(writable: Writable) {
const lockedReader = this.getReader();
let chunk;
while (chunk = await lockedReader.read()) {
const { value, done } = chunk;
console.log('piping chunk', chunk);
if (done) {
break;
}
writable.write(value);
}
}
readable.pipe = pipePolyfill;
}
readable.pipe(feedParser);
Hi there, thanks for this library! It seems to work great so far.
One small issue I'm having is that I'd rather write code using some of the more ergonomic APIs that have been introduced into Node over the past few years. This includes async iteration support for readable streams, which has been available in Node experimentally since 10.0.0 and as stable since 11.14.0. (Incidentally, that means it's now available in all non-EOL versions of Node.)
Here's a short example of using feedparser with async iteration support:
Pretty nice! Unfortunately, this library's use of the userland readable streams implementation prevents this, since it doesn't seem to support async iteration. Trying to run the above sample will fail with an obscure error.
However, if I patch feedparser to require
stream
instead ofreadable-stream
:The above sample works fine!
Is
readable-stream
being used to facilitate browser usage of this library? I think Webpack and Browserify already shim the streams module when bundling for browser environments, so it might not be necessary. Alternately, this library could maybe offer an alternatebrowser
entrypoint inpackage.json
(or maybe there's a polyfill package that already does this).feedparser version: 2.2.10 Node version: 16.6.2