Skip to content

Commit

Permalink
Closing the Chunker file in the end of a read. (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Rozenfeld authored Nov 18, 2020
1 parent 0150fc2 commit b732553
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions go/pkg/chunker/chunker.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ func (c *Chunker) FullData() ([]byte, error) {
err = c.r.Initialize()
}
if err != nil {
c.r.Close() // Free file handle in case of error.
return nil, err
}
// Cache contents so that the next call to FullData() doesn't result in file read.
c.contents, err = ioutil.ReadAll(c.r)
c.r.Close()
return c.contents, err
}

Expand Down Expand Up @@ -191,7 +193,9 @@ func (c *Chunker) Next() (*Chunk, error) {
c.contents = data
}
c.reachedEOF = true
c.r.Close()
} else if err != nil {
c.r.Close() // Free the file handle in case of error.
return nil, err
}
}
Expand Down

0 comments on commit b732553

Please sign in to comment.