mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 17:03:58 +08:00
Golint: unixfs/mod unixfs/test
License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
// Package mod provides DAG modification utilities to, for example,
|
||||
// insert additional nodes in a unixfs DAG or truncate them.
|
||||
package mod
|
||||
|
||||
import (
|
||||
@ -19,8 +21,12 @@ import (
|
||||
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
|
||||
)
|
||||
|
||||
var ErrSeekFail = errors.New("failed to seek properly")
|
||||
var ErrUnrecognizedWhence = errors.New("unrecognized whence")
|
||||
// Common errors
|
||||
var (
|
||||
ErrSeekFail = errors.New("failed to seek properly")
|
||||
ErrUnrecognizedWhence = errors.New("unrecognized whence")
|
||||
ErrNotUnixfs = fmt.Errorf("dagmodifier only supports unixfs nodes (proto or raw)")
|
||||
)
|
||||
|
||||
// 2MB
|
||||
var writebufferSize = 1 << 21
|
||||
@ -46,8 +52,6 @@ type DagModifier struct {
|
||||
read uio.DagReader
|
||||
}
|
||||
|
||||
var ErrNotUnixfs = fmt.Errorf("dagmodifier only supports unixfs nodes (proto or raw)")
|
||||
|
||||
// NewDagModifier returns a new DagModifier, the Cid prefix for newly
|
||||
// created nodes will be inherted from the passed in node. If the Cid
|
||||
// version if not 0 raw leaves will also be enabled. The Prefix and
|
||||
@ -412,7 +416,7 @@ func (dm *DagModifier) readPrep() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read data from this dag starting at the current offset
|
||||
// CtxReadFull reads data from this dag starting at the current offset
|
||||
func (dm *DagModifier) CtxReadFull(ctx context.Context, b []byte) (int, error) {
|
||||
err := dm.readPrep()
|
||||
if err != nil {
|
||||
@ -438,6 +442,8 @@ func (dm *DagModifier) HasChanges() bool {
|
||||
return dm.wrBuf != nil
|
||||
}
|
||||
|
||||
// Seek modifies the offset according to whence. See unixfs/io for valid whence
|
||||
// values.
|
||||
func (dm *DagModifier) Seek(offset int64, whence int) (int64, error) {
|
||||
err := dm.Sync()
|
||||
if err != nil {
|
||||
@ -479,6 +485,8 @@ func (dm *DagModifier) Seek(offset int64, whence int) (int64, error) {
|
||||
return int64(dm.curWrOff), nil
|
||||
}
|
||||
|
||||
// Truncate truncates the current Node to 'size' and replaces it with the
|
||||
// new one.
|
||||
func (dm *DagModifier) Truncate(size int64) error {
|
||||
err := dm.Sync()
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
|
||||
)
|
||||
|
||||
// SizeSplitterGen creates a generator.
|
||||
func SizeSplitterGen(size int64) chunk.SplitterGen {
|
||||
return func(r io.Reader) chunk.Splitter {
|
||||
return chunk.NewSizeSplitter(r, size)
|
||||
@ -41,10 +42,13 @@ type NodeOpts struct {
|
||||
RawLeavesUsed bool
|
||||
}
|
||||
|
||||
var UseProtoBufLeaves = NodeOpts{Prefix: mdag.V0CidPrefix()}
|
||||
var UseRawLeaves = NodeOpts{Prefix: mdag.V0CidPrefix(), ForceRawLeaves: true, RawLeavesUsed: true}
|
||||
var UseCidV1 = NodeOpts{Prefix: mdag.V1CidPrefix(), RawLeavesUsed: true}
|
||||
var UseBlake2b256 NodeOpts
|
||||
// Some shorthands for NodeOpts.
|
||||
var (
|
||||
UseProtoBufLeaves = NodeOpts{Prefix: mdag.V0CidPrefix()}
|
||||
UseRawLeaves = NodeOpts{Prefix: mdag.V0CidPrefix(), ForceRawLeaves: true, RawLeavesUsed: true}
|
||||
UseCidV1 = NodeOpts{Prefix: mdag.V1CidPrefix(), RawLeavesUsed: true}
|
||||
UseBlake2b256 NodeOpts
|
||||
)
|
||||
|
||||
func init() {
|
||||
UseBlake2b256 = UseCidV1
|
||||
@ -88,6 +92,7 @@ func GetRandomNode(t testing.TB, dserv ipld.DAGService, size int64, opts NodeOpt
|
||||
return buf, node
|
||||
}
|
||||
|
||||
// ArrComp checks if two byte slices are the same.
|
||||
func ArrComp(a, b []byte) error {
|
||||
if len(a) != len(b) {
|
||||
return fmt.Errorf("Arrays differ in length. %d != %d", len(a), len(b))
|
||||
|
Reference in New Issue
Block a user