Commit 069b4b5c authored by Henry's avatar Henry

rm util.NewByteChanReader()

parent 90d2113f
......@@ -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
}
......
......@@ -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{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment