-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3403 from ipfs/feat/dg-reader-cleanup
Fix panic in dagreader with raw nodes
- Loading branch information
Showing
8 changed files
with
315 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
) | ||
|
||
type bufDagReader struct { | ||
*bytes.Reader | ||
} | ||
|
||
func NewBufDagReader(b []byte) *bufDagReader { | ||
return &bufDagReader{bytes.NewReader(b)} | ||
} | ||
|
||
var _ DagReader = (*bufDagReader)(nil) | ||
|
||
func (*bufDagReader) Close() error { | ||
return nil | ||
} | ||
|
||
func (rd *bufDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error) { | ||
return rd.Read(b) | ||
} | ||
|
||
func (rd *bufDagReader) Offset() int64 { | ||
of, err := rd.Seek(0, io.SeekCurrent) | ||
if err != nil { | ||
panic("this should never happen " + err.Error()) | ||
} | ||
return of | ||
} | ||
|
||
func (rd *bufDagReader) Size() uint64 { | ||
s := rd.Reader.Size() | ||
if s < 0 { | ||
panic("size smaller than 0 (impossible!!)") | ||
} | ||
return uint64(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.