Skip to content

Commit

Permalink
flac: use io.ReadSeeker as parameter of NewSeek
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Jan 23, 2021
1 parent b8e364a commit bb157a5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/go-metaflac/metaflac.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func listStreamInfo(si *meta.StreamInfo) {
// data contents:
// Medieval CUE Splitter (www.medieval.it)
func listApplication(app *meta.Application) {
fmt.Printf(" application ID: %x\n", string(app.ID))
fmt.Printf(" application ID: %d\n", app.ID)
fmt.Println(" data contents:")
if len(app.Data) > 0 {
fmt.Println(string(app.Data))
Expand Down
11 changes: 3 additions & 8 deletions flac.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ func New(r io.Reader) (stream *Stream, err error) {
// NewSeek returns a Stream that has seeking enabled. The incoming
// io.ReadSeeker will not be buffered, which might result in performance issues.
// Using an in-memory buffer like *bytes.Reader should work well.
func NewSeek(r io.Reader) (stream *Stream, err error) {
rs, ok := r.(io.ReadSeeker)
if !ok {
return stream, ErrNoSeeker
}

func NewSeek(rs io.ReadSeeker) (stream *Stream, err error) {
stream = &Stream{r: rs, seekTableSize: defaultSeekTableSize}

// Verify FLAC signature and parse the StreamInfo metadata block.
Expand Down Expand Up @@ -139,8 +134,8 @@ 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: not a Seeker")
ErrInvalidSeek = errors.New("stream.Seek: invalid seek out of stream")
ErrNoSeeker = errors.New("stream.Seek: reader does not implement io.Seeker")
)

const (
Expand Down
2 changes: 1 addition & 1 deletion flac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestDecode(t *testing.T) {

funcs := map[string]func(io.Reader) (*flac.Stream, error){
"new": flac.New,
"newSeek": flac.NewSeek,
"newSeek": func(r io.Reader) (*flac.Stream, error) { return flac.NewSeek(r.(io.ReadSeeker)) },
"parse": flac.Parse,
}

Expand Down

0 comments on commit bb157a5

Please sign in to comment.