-
Notifications
You must be signed in to change notification settings - Fork 52
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 support for reading the id3 from a stream reader #20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
It's really good PR and I will merge it after requested changes will be fixed.
Also I will appreciate it if you will point me to the real case, where it's needed.
id3v2.go
Outdated
|
||
// OpenStream parses opened stream and finds tag in it considering opts. | ||
// If there is no tag in stream, OpenStream will create new one with version ID3v2.4. | ||
// you can use WriteTo to get the metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete this line. IMHO it's confusing.
parse.go
Outdated
func parseTag(file *os.File, opts Options) (*Tag, error) { | ||
if file == nil { | ||
return nil, errors.New("file is nil") | ||
func parseTag(reader io.Reader, opts Options) (*Tag, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use rd
instead of reader
.
id3v2.go
Outdated
// OpenStream parses opened stream and finds tag in it considering opts. | ||
// If there is no tag in stream, OpenStream will create new one with version ID3v2.4. | ||
// you can use WriteTo to get the metadata | ||
func OpenStream(stream io.Reader, opts Options) (*Tag, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO It's better to name it ParseReader
.
tag.go
Outdated
@@ -263,6 +266,10 @@ func (t *Tag) SetVersion(version byte) { | |||
// Save writes t to the file. If there are no frames in tag, Save will write | |||
// only music part without any ID3v2 information. | |||
func (t *Tag) Save() error { | |||
if t.file == nil { | |||
return fmt.Errorf("Parser not inited with file, it's just a stream") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, we should create special error for it and return it:
// ErrNoFile is returned in Save and Close method, if tag was not
// initialized with file.
var ErrNoFile = errors.New('tag was not initialized with file')
And then write in docs of Save
and Close
these lines:
// If tag was initiliazed not with file but from ParseReader,
// it returns ErrNoFile.
@@ -393,5 +400,9 @@ func writeFrameHeader(bw *bufio.Writer, id string, frameSize int) error { | |||
// Close closes t's file, rendering it unusable for I/O. | |||
// It returns an error, if any. | |||
func (t *Tag) Close() error { | |||
if t.file == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in Save
.
Done I'm using this library to parse id3 from an audio received from http. |
Merged. |
Support for using a simple reader as source for the parser. The changes are backward compatible.