| 183 | } |
| 184 | |
| 185 | func NewStreamSectionReader(file model.FileStreamer, sectionSize int, up *model.UpdateProgress) (StreamSectionReader, error) { |
| 186 | if file.GetFile() != nil { |
| 187 | return &cachedSectionReader{file.GetFile()}, nil |
| 188 | } |
| 189 | |
| 190 | blockSize := min(uint64(sectionSize), uint64(file.GetSize()), conf.MaxBlockLimit) |
| 191 | hc, err := hcache.NewHybridCache(blockSize, uint64(file.GetSize())) |
| 192 | if err != nil { |
| 193 | return nil, err |
| 194 | } |
| 195 | file.Add(hc) |
| 196 | return &hybridSectionReader{file: file, hc: hc}, nil |
| 197 | } |
| 198 | |
| 199 | type cachedSectionReader struct { |
| 200 | cache io.ReaderAt |