michaelnisi / pickup

Transform XML feeds
MIT License
21 stars 1 forks source link

In eventMode, is the 'feed' event always the last to fire? #13

Closed naxxfish closed 5 years ago

naxxfish commented 5 years ago

When consuming the stream events, in order to get a representation of a full feed and list of entries in Javascript objects, one might have code such as this:

    var returnedFeed = {
      meta: null,
      entries: []
    }
    request(feed.url)
      .pipe(pickup({ eventMode: true }))
      .on('feed', (feedMeta) => {

        returnedFeed.meta = feedMeta
        resolve(returnedFeed)
      })
      .on('entry', (entry) => {
        console.log('entry')
        returnedFeed.entries.push(entry)
      })

It appears that the 'feed' event is the last to fire when parsing a feed, therefore a good point to return a populated object. However, is that definitely always the case? Normally, I'd use the 'end' event to determine this, but it seems that in eventMode this does not get emitted.

michaelnisi commented 5 years ago

Yes, in eventMode, 'feed' is the last event, provided that the source XML contains a channel or a feed element. If not, parsing fails emitting 'error'.