Skip to content

Commit

Permalink
ReadOrErr 读取文件后,关闭流 (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghx-git committed Oct 13, 2023
1 parent 081b02c commit d10983d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fsutil/opread.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func MustRead(in any) []byte {
// ReadOrErr read contents from path or io.Reader, will panic on in type error
func ReadOrErr(in any) ([]byte, error) {
r, err := NewIOReader(in)
defer func() {
if r != nil {
file, ok := r.(*os.File)
if ok {
err = file.Close()
}
}
}()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d10983d

Please sign in to comment.