aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2/filechunks.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer2/filechunks.go')
-rw-r--r--weed/filer2/filechunks.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.go
index 9de888d50..d7c31bf0f 100644
--- a/weed/filer2/filechunks.go
+++ b/weed/filer2/filechunks.go
@@ -134,17 +134,18 @@ func ViewFromVisibleIntervals(visibles []VisibleInterval, offset int64, size int
for _, chunk := range visibles {
- if chunk.start <= offset && offset < chunk.stop && offset < stop {
+ chunkStart, chunkStop := max(offset, chunk.start), min(stop, chunk.stop)
+
+ if chunkStart < chunkStop {
views = append(views, &ChunkView{
FileId: chunk.fileId,
- Offset: offset - chunk.start, // offset is the data starting location in this file id
- Size: uint64(min(chunk.stop, stop) - offset),
- LogicOffset: offset,
+ Offset: chunkStart - chunk.start,
+ Size: uint64(chunkStop - chunkStart),
+ LogicOffset: chunkStart,
ChunkSize: chunk.chunkSize,
CipherKey: chunk.cipherKey,
IsGzipped: chunk.isGzipped,
})
- offset = min(chunk.stop, stop)
}
}
@@ -266,3 +267,9 @@ func min(x, y int64) int64 {
}
return y
}
+func max(x, y int64) int64 {
+ if x <= y {
+ return y
+ }
+ return x
+}