github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/requester/uploader/block_test.go (about) 1 package uploader_test 2 3 import ( 4 "fmt" 5 "github.com/fzfile/BaiduPCS-Go/pcsutil/cachepool" 6 "github.com/fzfile/BaiduPCS-Go/requester/rio" 7 "github.com/fzfile/BaiduPCS-Go/requester/transfer" 8 "github.com/fzfile/BaiduPCS-Go/requester/uploader" 9 "io" 10 "testing" 11 ) 12 13 var ( 14 blockList = uploader.SplitBlock(10000, 999) 15 ) 16 17 func TestSplitBlock(t *testing.T) { 18 for k, e := range blockList { 19 fmt.Printf("%d %#v\n", k, e) 20 } 21 } 22 23 func TestSplitUnitRead(t *testing.T) { 24 var size int64 = 65536*2+3432 25 buffer := rio.NewBuffer(cachepool.RawMallocByteSlice(int(size))) 26 unit := uploader.NewBufioSplitUnit(buffer, transfer.Range{Begin: 2, End: size}, nil, nil) 27 28 buf := cachepool.RawMallocByteSlice(1022) 29 for { 30 n, err := unit.Read(buf) 31 if err != nil { 32 if err == io.EOF { 33 break 34 } 35 t.Fatalf("read error: %s\n", err) 36 } 37 fmt.Printf("n: %d, left: %d\n", n, unit.Left()) 38 } 39 }