Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
f074292e
Commit
f074292e
authored
Feb 06, 2018
by
Hector Sanjuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Golint: unixfs/mod unixfs/test
License: MIT Signed-off-by:
Hector Sanjuan
<
hector@protocol.ai
>
parent
16934b9c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
+22
-9
unixfs/mod/dagmodifier.go
unixfs/mod/dagmodifier.go
+13
-5
unixfs/test/utils.go
unixfs/test/utils.go
+9
-4
No files found.
unixfs/mod/dagmodifier.go
View file @
f074292e
// 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
//
Ctx
Read
Full 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
{
...
...
unixfs/test/utils.go
View file @
f074292e
...
...
@@ -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
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment