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
92c7f967
Commit
92c7f967
authored
Jan 26, 2015
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #673 from jbenet/fix/seek
off by one error seeking to end of single block file
parents
b16adfea
2eca66e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
importer/importer_test.go
importer/importer_test.go
+52
-0
unixfs/io/dagreader.go
unixfs/io/dagreader.go
+1
-1
No files found.
importer/importer_test.go
View file @
92c7f967
...
...
@@ -308,6 +308,58 @@ func TestSeekToAlmostBegin(t *testing.T) {
}
}
func
TestSeekEnd
(
t
*
testing
.
T
)
{
nbytes
:=
int64
(
50
*
1024
)
should
:=
make
([]
byte
,
nbytes
)
u
.
NewTimeSeededRand
()
.
Read
(
should
)
read
:=
bytes
.
NewReader
(
should
)
dnp
:=
getDagservAndPinner
(
t
)
nd
,
err
:=
BuildDagFromReader
(
read
,
dnp
.
ds
,
dnp
.
mp
,
&
chunk
.
SizeSplitter
{
500
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
rs
,
err
:=
uio
.
NewDagReader
(
context
.
Background
(),
nd
,
dnp
.
ds
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
seeked
,
err
:=
rs
.
Seek
(
0
,
os
.
SEEK_END
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
seeked
!=
nbytes
{
t
.
Fatal
(
"Failed to seek to end"
)
}
}
func
TestSeekEndSingleBlockFile
(
t
*
testing
.
T
)
{
nbytes
:=
int64
(
100
)
should
:=
make
([]
byte
,
nbytes
)
u
.
NewTimeSeededRand
()
.
Read
(
should
)
read
:=
bytes
.
NewReader
(
should
)
dnp
:=
getDagservAndPinner
(
t
)
nd
,
err
:=
BuildDagFromReader
(
read
,
dnp
.
ds
,
dnp
.
mp
,
&
chunk
.
SizeSplitter
{
5000
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
rs
,
err
:=
uio
.
NewDagReader
(
context
.
Background
(),
nd
,
dnp
.
ds
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
seeked
,
err
:=
rs
.
Seek
(
0
,
os
.
SEEK_END
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
seeked
!=
nbytes
{
t
.
Fatal
(
"Failed to seek to end"
)
}
}
func
TestSeekingStress
(
t
*
testing
.
T
)
{
nbytes
:=
int64
(
1024
*
1024
)
should
:=
make
([]
byte
,
nbytes
)
...
...
unixfs/io/dagreader.go
View file @
92c7f967
...
...
@@ -171,7 +171,7 @@ func (dr *DagReader) Seek(offset int64, whence int) (int64, error) {
// left represents the number of bytes remaining to seek to (from beginning)
left
:=
offset
if
int64
(
len
(
pb
.
Data
))
>
offset
{
if
int64
(
len
(
pb
.
Data
))
>
=
offset
{
// Close current buf to close potential child dagreader
dr
.
buf
.
Close
()
dr
.
buf
=
NewRSNCFromBytes
(
pb
.
GetData
()[
offset
:
])
...
...
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