Skip to content

Commit

Permalink
Gracefully handle nil stream passed to Identify
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jan 19, 2022
1 parent 3cb4ab1 commit d777df9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func Identify(filename string, stream io.ReadSeeker) (Format, error) {
}

func identifyOne(format Format, filename string, stream io.ReadSeeker, comp Compression) (MatchResult, error) {
if stream == nil {
// shimming an empty stream is easier than hoping every format's
// implementation of Match() expects and handles a nil stream
stream = strings.NewReader("")
}

// reset stream position to beginning, then restore current position when done
previousOffset, err := stream.Seek(0, io.SeekCurrent)
if err != nil {
Expand Down

0 comments on commit d777df9

Please sign in to comment.