Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to acces the raw feed data #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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