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
069b4b5c
Commit
069b4b5c
authored
10 years ago
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rm util.NewByteChanReader()
parent
90d2113f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
72 deletions
+0
-72
util/util.go
util/util.go
+0
-34
util/util_test.go
util/util_test.go
+0
-38
No files found.
util/util.go
View file @
069b4b5c
...
...
@@ -62,40 +62,6 @@ func ExpandPathnames(paths []string) ([]string, error) {
return
out
,
nil
}
// byteChanReader wraps a byte chan in a reader
type
byteChanReader
struct
{
in
chan
[]
byte
buf
[]
byte
}
func
NewByteChanReader
(
in
chan
[]
byte
)
io
.
Reader
{
return
&
byteChanReader
{
in
:
in
}
}
func
(
bcr
*
byteChanReader
)
Read
(
output
[]
byte
)
(
int
,
error
)
{
remain
:=
output
remainLen
:=
len
(
output
)
outputLen
:=
0
more
:=
false
next
:=
bcr
.
buf
for
{
n
:=
copy
(
remain
,
next
)
remainLen
-=
n
outputLen
+=
n
if
remainLen
==
0
{
bcr
.
buf
=
next
[
n
:
]
return
outputLen
,
nil
}
remain
=
remain
[
n
:
]
next
,
more
=
<-
bcr
.
in
if
!
more
{
return
outputLen
,
io
.
EOF
}
}
}
type
randGen
struct
{
rand
.
Rand
}
...
...
This diff is collapsed.
Click to expand it.
util/util_test.go
View file @
069b4b5c
...
...
@@ -2,7 +2,6 @@ package util
import
(
"bytes"
"math/rand"
"testing"
mh
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
...
...
@@ -28,43 +27,6 @@ func TestKey(t *testing.T) {
}
}
func
TestByteChanReader
(
t
*
testing
.
T
)
{
if
testing
.
Short
()
{
t
.
SkipNow
()
}
var
data
bytes
.
Buffer
var
data2
bytes
.
Buffer
dch
:=
make
(
chan
[]
byte
,
8
)
randr
:=
NewTimeSeededRand
()
go
func
()
{
defer
close
(
dch
)
for
i
:=
0
;
i
<
rand
.
Intn
(
100
)
+
100
;
i
++
{
chunk
:=
make
([]
byte
,
rand
.
Intn
(
100000
)
+
10
)
randr
.
Read
(
chunk
)
data
.
Write
(
chunk
)
dch
<-
chunk
}
}()
read
:=
NewByteChanReader
(
dch
)
// read in random, weird sizes to exercise saving buffer.
for
{
buf
:=
make
([]
byte
,
rand
.
Intn
(
10
)
*
10
)
n
,
err
:=
read
.
Read
(
buf
)
data2
.
Write
(
buf
[
:
n
])
if
err
!=
nil
{
break
}
}
if
!
bytes
.
Equal
(
data2
.
Bytes
(),
data
.
Bytes
())
{
t
.
Fatal
(
"Reader failed to stream correct bytes"
)
}
}
func
TestXOR
(
t
*
testing
.
T
)
{
cases
:=
[][
3
][]
byte
{
[
3
][]
byte
{
...
...
This diff is collapsed.
Click to expand it.
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