This commit is contained in:
celogeek 2022-03-05 17:21:18 +01:00
parent ab15c8c5a8
commit 2361ac8f17
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -50,15 +50,20 @@ func (c *UploadCommand) Execute(args []string) error {
if err != nil {
return err
}
chunkSize := int64(1 << 20)
nbChunks := st.Size() / chunkSize
if st.Size()%chunkSize > 0 {
nbChunks++
}
uploadFile := &UploadFileRequest{Name: filepath.Base(c.File)}
uploadFile := &UploadFileRequest{Name: filepath.Base(c.File), Chunks: make([]string, nbChunks)}
progress := progressbar.DefaultBytes(st.Size(), fmt.Sprintf("Uploading %s", uploadFile.Name))
defer progress.Close()
cli := resty.New().SetBaseURL(c.Url).SetAuthScheme("Private").SetAuthToken(c.Token)
b := make([]byte, 1<<20)
b := make([]byte, chunkSize)
checksum := sha1.New()
for {
for i := 0; ; i++ {
n, err := f.Read(b)
if n == 0 {
if err == io.EOF {
@ -77,7 +82,7 @@ func (c *UploadCommand) Execute(args []string) error {
}
if result, ok := resp.Result().(*UploadChunkSuccess); ok {
uploadFile.Chunks = append(uploadFile.Chunks, result.Checksum)
uploadFile.Chunks[i] = result.Checksum
checksum.Write(b[0:n])
progress.Add(n)
}