temkin
temkin

Reputation: 355

Node.js - How to pass a stream from request to xml-stream

I'm trying to download a large XML file and parse it using xml-stream library. I'm using request to download the file and it's capable of streaming the content of the file. Ideally, I'd like to pass that stream directly to xml-stream and have it parsed. But I can't figure out how to connect those two.

Here is the code a have so far:

request('http://example.com/data.xml').pipe(fs.createWriteStream('data.xml'));
...
var stream = fs.createReadStream('data.xml');
var xml = new XmlStream(stream);

Is it possible to connect them directly without a temp data.xml file?

Upvotes: 1

Views: 874

Answers (1)

mscdex
mscdex

Reputation: 106746

request() returns a Readable stream, so just pass that return value to XmlStream():

var xml = new XmlStream(request('http://example.com/data.xml'));

Upvotes: 2

Related Questions