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-unixfs
Commits
f68d79f5
Commit
f68d79f5
authored
Mar 09, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address comments from @cryptix in PR
parent
00efa963
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
25 deletions
+10
-25
mod/dagmodifier.go
mod/dagmodifier.go
+10
-25
No files found.
mod/dagmodifier.go
View file @
f68d79f5
...
...
@@ -20,6 +20,10 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
var
ErrSeekFail
=
errors
.
New
(
"failed to seek properly"
)
var
ErrSeekEndNotImpl
=
errors
.
New
(
"SEEK_END currently not implemented"
)
var
ErrUnrecognizedWhence
=
errors
.
New
(
"unrecognized whence"
)
// 2MB
var
writebufferSize
=
1
<<
21
...
...
@@ -199,6 +203,8 @@ func (dm *DagModifier) Flush() error {
}
// modifyDag writes the data in 'data' over the data in 'node' starting at 'offset'
// returns the new key of the passed in node and whether or not all the data in the reader
// has been consumed.
func
(
dm
*
DagModifier
)
modifyDag
(
node
*
mdag
.
Node
,
offset
uint64
,
data
io
.
Reader
)
(
u
.
Key
,
bool
,
error
)
{
f
,
err
:=
ft
.
FromBytes
(
node
.
Data
)
if
err
!=
nil
{
...
...
@@ -291,7 +297,7 @@ func (dm *DagModifier) Read(b []byte) (int, error) {
}
if
i
!=
int64
(
dm
.
curWrOff
)
{
return
0
,
e
rr
ors
.
New
(
"failed to seek properly"
)
return
0
,
E
rr
SeekFail
}
dm
.
read
=
dr
...
...
@@ -302,28 +308,6 @@ func (dm *DagModifier) Read(b []byte) (int, error) {
return
n
,
err
}
// splitBytes uses a splitterFunc to turn a large array of bytes
// into many smaller arrays of bytes
func
(
dm
*
DagModifier
)
splitBytes
(
in
io
.
Reader
)
([]
u
.
Key
,
error
)
{
var
out
[]
u
.
Key
blks
:=
dm
.
splitter
.
Split
(
in
)
for
blk
:=
range
blks
{
nd
:=
help
.
NewUnixfsNode
()
nd
.
SetData
(
blk
)
dagnd
,
err
:=
nd
.
GetDagNode
()
if
err
!=
nil
{
return
nil
,
err
}
k
,
err
:=
dm
.
dagserv
.
Add
(
dagnd
)
if
err
!=
nil
{
return
nil
,
err
}
out
=
append
(
out
,
k
)
}
return
out
,
nil
}
// GetNode gets the modified DAG Node
func
(
dm
*
DagModifier
)
GetNode
()
(
*
mdag
.
Node
,
error
)
{
err
:=
dm
.
Flush
()
...
...
@@ -352,9 +336,9 @@ func (dm *DagModifier) Seek(offset int64, whence int) (int64, error) {
dm
.
curWrOff
=
uint64
(
offset
)
dm
.
writeStart
=
uint64
(
offset
)
case
os
.
SEEK_END
:
return
0
,
e
rr
ors
.
New
(
"SEEK_END currently not implemented"
)
return
0
,
E
rr
SeekEndNotImpl
default
:
return
0
,
e
rr
ors
.
New
(
"u
nrecognized
w
hence
"
)
return
0
,
E
rr
U
nrecognized
W
hence
}
if
dm
.
read
!=
nil
{
...
...
@@ -425,6 +409,7 @@ func dagTruncate(nd *mdag.Node, size uint64, ds mdag.DAGService) (*mdag.Node, er
return
nil
,
err
}
// found the child we want to cut
if
size
<
cur
+
childsize
{
nchild
,
err
:=
dagTruncate
(
child
,
size
-
cur
,
ds
)
if
err
!=
nil
{
...
...
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