Skip to content

Commit

Permalink
Fix import reader
Browse files Browse the repository at this point in the history
  • Loading branch information
arturalbov committed Jan 31, 2019
1 parent 64e5516 commit 3b57173
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ func RootifyPath(path string) string {

func ReadExactlyNBytes(reader io.Reader, n uint64) ([]byte, error) {
data := make([]byte, n)
bytesReaded, err := reader.Read(data)
if err != nil {
return nil, err
}
if uint64(bytesReaded) != n {
return nil, errors.New("not enough bytes tor read")
currentlyReadedBytes := uint64(0)
for currentlyReadedBytes < n {
readedBytes, err := reader.Read(data[currentlyReadedBytes:n])
if err != nil {
return nil, err
}
if readedBytes == 0 {
return nil, errors.New("not enough bytes tor read")
}
currentlyReadedBytes += uint64(readedBytes)
}

return data, nil
}

0 comments on commit 3b57173

Please sign in to comment.