aboutsummaryrefslogtreecommitdiff
path: root/repo_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'repo_test.go')
-rw-r--r--repo_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/repo_test.go b/repo_test.go
index 7d54ef5..07af682 100644
--- a/repo_test.go
+++ b/repo_test.go
@@ -2,6 +2,7 @@ package main
import (
"bytes"
+ "fmt"
"io"
"io/ioutil"
"log"
@@ -54,6 +55,44 @@ func chunkCompare(t *testing.T, dataDir string, repo *Repo, testFiles []string,
}
}
+func (r *Repo) chunkStream(stream io.Reader, chunks chan<- []byte) {
+ var buff []byte
+ var prev, read = r.chunkSize, 0
+ var err error
+
+ for err != io.EOF {
+ if prev == r.chunkSize {
+ buff = make([]byte, r.chunkSize)
+ prev, err = stream.Read(buff)
+ } else {
+ read, err = stream.Read(buff[prev:])
+ prev += read
+ }
+ if err != nil && err != io.EOF {
+ log.Println(err)
+ }
+ if prev == r.chunkSize {
+ chunks <- buff
+ }
+ }
+ if prev != r.chunkSize {
+ chunks <- buff[:prev]
+ }
+ close(chunks)
+}
+
+func storeChunks(dest string, chunks <-chan []byte) {
+ i := 0
+ for c := range chunks {
+ path := path.Join(dest, fmt.Sprintf(chunkIdFmt, i))
+ err := os.WriteFile(path, c, 0664)
+ if err != nil {
+ log.Println(err)
+ }
+ i++
+ }
+}
+
func TestReadFiles1(t *testing.T) {
repo := NewRepo("")
chunkCount := 590/repo.chunkSize + 1