Skip to content

Commit

Permalink
check for parsing of the headers so it's not attempted again
Browse files Browse the repository at this point in the history
  • Loading branch information
cswank committed Jan 19, 2021
1 parent e0927f4 commit 768ed1b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type (
c io.Closer
}

// Option is a func that modifies Stream and allows detail of the Stream's behaivor to be set.
// Option is a func that modifies Stream and allows details of the Stream's behaivor to be set.
Option func(s *Stream, r io.Reader) error
)

Expand All @@ -91,6 +91,11 @@ func New(r io.Reader, opts ...Option) (stream *Stream, err error) {
}

func Buffered(stream *Stream, r io.Reader) error {
if stream.r != nil {
// The initial parsing has already happened
return ErrInvalidOption
}

stream.r = bufio.NewReader(r)

// Verify FLAC signature and parse the StreamInfo metadata block.
Expand All @@ -114,12 +119,17 @@ func Buffered(stream *Stream, r io.Reader) error {
}

func EnableSeek(stream *Stream, r io.Reader) error {
if stream.r != nil {
// The initial parsing has already happened
return ErrInvalidOption
}

rs, ok := r.(io.ReadSeeker)
if !ok {
return ErrNoSeeker
}

stream.r = rs
stream.r = r

// Verify FLAC signature and parse the StreamInfo metadata block.
block, err := stream.parseStreamInfo()
Expand Down Expand Up @@ -159,8 +169,9 @@ var (
// id3Signature marks the beginning of an ID3 stream, used to skip over ID3 data.
id3Signature = []byte("ID3")

ErrInvalidSeek = errors.New("stream.Seek: out of stream seek")
ErrNoSeeker = errors.New("stream.Seek: no a Seeker")
ErrInvalidSeek = errors.New("stream.Seek: out of stream seek")
ErrNoSeeker = errors.New("stream.Seek: no a Seeker")
ErrInvalidOption = errors.New("stream.New: invalid Option")
)

// parseStreamInfo verifies the signature which marks the beginning of a FLAC
Expand Down

0 comments on commit 768ed1b

Please sign in to comment.