github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/api/apc/blob.go (about) 1 // Package apc: API control messages and constants 2 /* 3 * Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package apc 6 7 import ( 8 "fmt" 9 "net/http" 10 "strconv" 11 12 "github.com/NVIDIA/aistore/cmn/cos" 13 ) 14 15 const _bldl = "blob-downloader" 16 17 type BlobMsg struct { 18 ChunkSize int64 `json:"chunk-size"` 19 FullSize int64 `json:"full-size"` 20 NumWorkers int `json:"num-workers"` 21 LatestVer bool `json:"latest-ver"` 22 } 23 24 func (msg *BlobMsg) FromHeader(hdr http.Header) error { 25 snw, schunk := hdr.Get(HdrBlobWorkers), hdr.Get(HdrBlobChunk) 26 if snw != "" { 27 nw, err := strconv.ParseInt(snw, 10, 16) 28 if err != nil { 29 return fmt.Errorf("%s: failed to parse %s=%s: %v", _bldl, HdrBlobWorkers, snw, err) 30 } 31 if nw < 0 || nw > 128 { 32 return fmt.Errorf("%s: invalid %s=%s: expecting (0..128) range", _bldl, HdrBlobWorkers, snw) 33 } 34 msg.NumWorkers = int(nw) 35 } 36 if schunk == "" { 37 return nil 38 } 39 chunk, err := cos.ParseSize(schunk, "") 40 if err != nil { 41 return fmt.Errorf("%s: failed to parse %s=%s: %v", _bldl, HdrBlobChunk, schunk, err) 42 } 43 msg.ChunkSize = chunk 44 return nil 45 }