truncate file size on resume
This commit is contained in:
commit
a0dbbb23c4
1 changed files with 9 additions and 1 deletions
|
@ -939,6 +939,7 @@ func downloadBlob(mp ModelPath, digest string, regOpts *RegistryOptions, fn func
|
||||||
}
|
}
|
||||||
|
|
||||||
var size int64
|
var size int64
|
||||||
|
chunkSize := 1024 * 1024 // 1 MiB in bytes
|
||||||
|
|
||||||
fi, err := os.Stat(fp + "-partial")
|
fi, err := os.Stat(fp + "-partial")
|
||||||
switch {
|
switch {
|
||||||
|
@ -948,6 +949,13 @@ func downloadBlob(mp ModelPath, digest string, regOpts *RegistryOptions, fn func
|
||||||
return fmt.Errorf("stat: %w", err)
|
return fmt.Errorf("stat: %w", err)
|
||||||
default:
|
default:
|
||||||
size = fi.Size()
|
size = fi.Size()
|
||||||
|
// Ensure the size is divisible by the chunk size by removing excess bytes
|
||||||
|
size -= size % int64(chunkSize)
|
||||||
|
|
||||||
|
err := os.Truncate(fp+"-partial", size)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("truncate: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/v2/%s/blobs/%s", mp.Registry, mp.GetNamespaceRepository(), digest)
|
url := fmt.Sprintf("%s/v2/%s/blobs/%s", mp.Registry, mp.GetNamespaceRepository(), digest)
|
||||||
|
@ -1008,7 +1016,7 @@ func downloadBlob(mp ModelPath, digest string, regOpts *RegistryOptions, fn func
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
n, err := io.CopyN(out, resp.Body, 8192)
|
n, err := io.CopyN(out, resp.Body, int64(chunkSize))
|
||||||
if err != nil && !errors.Is(err, io.EOF) {
|
if err != nil && !errors.Is(err, io.EOF) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue