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 support for reading the id3 from a stream reader #20

Merged
merged 3 commits into from
May 12, 2017
Merged

Add support for reading the id3 from a stream reader #20

merged 3 commits into from
May 12, 2017

Conversation

corneldamian
Copy link
Contributor

Support for using a simple reader as source for the parser. The changes are backward compatible.

Copy link
Owner

@n10v n10v left a 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
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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")
Copy link
Owner

@n10v n10v May 11, 2017

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as in Save.

@corneldamian
Copy link
Contributor Author

Done

I'm using this library to parse id3 from an audio received from http.

@n10v n10v merged commit fa069d1 into n10v:master May 12, 2017
@n10v
Copy link
Owner

n10v commented May 12, 2017

Merged.
Thank you for it! I'm glad to see new contributions, feature requests and bug reports from you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants