Skip to content

Commit

Permalink
pbreader: use ReadFull instead of reimplementing it
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu committed Mar 8, 2018
1 parent 1b96ad7 commit 8a60be0
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions unixfs/io/pbdagreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,20 @@ func (dr *PBDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error) {
total := 0
for {
// Attempt to fill bytes from cached buffer
n, err := dr.buf.Read(b[total:])
n, err := io.ReadFull(dr.buf, b[total:])
total += n
dr.offset += int64(n)
if err != nil {
// EOF is expected
if err != io.EOF {
return total, err
}
}

// If weve read enough bytes, return
if total == len(b) {
switch err {
// io.EOF will happen is dr.bug had noting more to read (n == 0)
case io.EOF, io.ErrUnexpectedEOF:
// do nothing
case nil:
return total, nil
default:
return total, err
}

// Otherwise, load up the next block
// if we are not done with the output buffer load next block
err = dr.precalcNextBuf(ctx)
if err != nil {
return total, err
Expand Down

0 comments on commit 8a60be0

Please sign in to comment.