chunksize 계산

This commit is contained in:
2023-10-24 20:57:41 +09:00
parent c9fecf55de
commit b8c1e97ab8
3 changed files with 41 additions and 7 deletions

View File

@ -23,6 +23,24 @@ import (
"golang.org/x/text/transform"
)
func pof2(x int64, min int64) (out int64) {
out = 1
org := x
for (x >> 1) > 0 {
out = out << 1
x = x >> 1
}
if org > out {
out = out << 1
}
if out < min {
out = min
}
return
}
func download(dir string, urlpath string, accessToken string, cb func(int64, int64)) (target string, err error) {
logger.Println("start downloading", dir, urlpath)
defer func() {
@ -59,13 +77,13 @@ func download(dir string, urlpath string, accessToken string, cb func(int64, int
cl := resp.Header.Get("Content-Length")
totalLength, _ := strconv.ParseInt(cl, 10, 0)
totalWritten := int64(0)
chunkSize := pof2(totalLength/100, 1024*1024)
if cb != nil {
cb(0, totalLength)
}
for {
written, err := io.CopyN(out, resp.Body, 1024*1024)
written, err := io.CopyN(out, resp.Body, chunkSize)
totalWritten += written
if cb != nil {
cb(totalWritten, totalLength)
@ -324,7 +342,7 @@ func (hc *houstonClient) deploy(req *shared.DeployRequest, cb func(*protos.Deplo
}
cb(&protos.DeployingProgress{
State: "unzip/untar",
State: "unpack",
Progress: 0,
Total: 0,
})