Skip to content

Commit

Permalink
Add the ability to acces the raw feed data
Browse files Browse the repository at this point in the history
  • Loading branch information
zeGrandpa authored and NDagestad committed Jun 5, 2020
1 parent 0e68bea commit 9b88c0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions feed.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gofeed

import (
"bytes"
"encoding/json"
"time"

Expand All @@ -11,6 +12,7 @@ import (
// and rss.Feed gets translated to. It represents
// a web feed.
type Feed struct {
RawFeed bytes.Buffer `json:"-"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Link string `json:"link,omitempty"`
Expand Down
16 changes: 12 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,27 @@ func (f *Parser) Parse(feed io.Reader) (*Feed, error) {
// DetectFeedType function and construct a new
// reader with those bytes intact for when we
// attempt to parse the feeds.
var buf bytes.Buffer
var buf, copyBuffer bytes.Buffer
tee := io.TeeReader(feed, &buf)
feedType := DetectFeedType(tee)

// Glue the read bytes from the detect function
// back into a new reader
r := io.MultiReader(&buf, feed)

r := io.TeeReader(io.MultiReader(&buf, feed), &copyBuffer)
switch feedType {
case FeedTypeAtom:
return f.parseAtomFeed(r)
atomFeed, err := f.parseAtomFeed(r)
if atomFeed != nil {
atomFeed.RawFeed = copyBuffer
}
return atomFeed, err
case FeedTypeRSS:
return f.parseRSSFeed(r)
rssFeed, err := f.parseRSSFeed(r)
if rssFeed != nil {
rssFeed.RawFeed = copyBuffer
}
return rssFeed, err
}

return nil, ErrFeedTypeNotDetected
Expand Down

0 comments on commit 9b88c0b

Please sign in to comment.