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
fdcebc5a
Commit
fdcebc5a
authored
Jul 05, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
importer
parent
1d3e72a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
importer/importer.go
importer/importer.go
+40
-0
No files found.
importer/importer.go
0 → 100644
View file @
fdcebc5a
package
importer
import
(
"fmt"
dag
"github.com/jbenet/go-ipfs/merkledag"
"io"
"io/ioutil"
)
var
BlockSizeLimit
=
int64
(
1048576
)
// 1 MB
var
SizeLimitExceeded
=
fmt
.
Errorf
(
"object size limit exceeded"
)
// todo: incremental construction with an ipfs node. dumping constructed
// objects into the datastore, to avoid buffering all in memory
// size required for block construction
func
NewDagFromReader
(
r
io
.
Reader
,
size
int64
)
(
*
dag
.
Node
,
error
)
{
// todo: block-splitting based on rabin fingerprinting
// todo: block-splitting with user-defined function
// todo: block-splitting at all. :P
// totally just trusts the reported size. fix later.
if
size
>
BlockSizeLimit
{
// 1 MB limit for now.
return
nil
,
SizeLimitExceeded
}
// we're doing it live!
buf
,
err
:=
ioutil
.
ReadAll
(
r
)
if
err
!=
nil
{
return
nil
,
err
}
if
int64
(
len
(
buf
))
>
BlockSizeLimit
{
return
nil
,
SizeLimitExceeded
// lying punk.
}
root
:=
&
dag
.
Node
{
Data
:
buf
}
// no children for now because not block splitting yet
return
root
,
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