github.com/iikira/iikira-go-utils@v0.0.0-20230610031953-f2cb11cde33a/requester/uploader/block_test.go (about) 1 package uploader_test 2 3 import ( 4 "fmt" 5 "github.com/iikira/iikira-go-utils/requester/rio" 6 "github.com/iikira/iikira-go-utils/requester/transfer" 7 "github.com/iikira/iikira-go-utils/requester/uploader" 8 "github.com/iikira/iikira-go-utils/utils/cachepool" 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 }