MCPcopy
hub / github.com/rclone/rclone / FixRangeOption

Function FixRangeOption

fs/open_options.go:145–177  ·  view source on GitHub ↗

FixRangeOption looks through the slice of options and adjusts any RangeOption~s found that request a fetch from the end into an absolute fetch using the size passed in and makes sure the range does not exceed filesize. Some remotes (e.g. Onedrive, Box) don't support range requests which index from t

(options []OpenOption, size int64)

Source from the content-addressed store, hash-verified

143// It also adjusts any SeekOption~s, turning them into absolute
144// RangeOption~s instead.
145func FixRangeOption(options []OpenOption, size int64) {
146 if size < 0 {
147 // Can't do anything for unknown length objects
148 return
149 } else if size == 0 {
150 // if size 0 then remove RangeOption~s
151 // replacing with a NullOptions~s which won't be rendered
152 for i := range options {
153 if _, ok := options[i].(*RangeOption); ok {
154 options[i] = NullOption{}
155
156 }
157 }
158 return
159 }
160 for i, option := range options {
161 switch x := option.(type) {
162 case *RangeOption:
163 // If start is < 0 then fetch from the end
164 if x.Start < 0 {
165 x = &RangeOption{Start: size - x.End, End: -1}
166 options[i] = x
167 }
168 // If end is too big or undefined, fetch to the end
169 if x.End > size || x.End < 0 {
170 x = &RangeOption{Start: x.Start, End: size - 1}
171 options[i] = x
172 }
173 case *SeekOption:
174 options[i] = &RangeOption{Start: x.Offset, End: size - 1}
175 }
176 }
177}
178
179// SeekOption defines an HTTP Range option with start only.
180type SeekOption struct {

Callers 15

OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92
OpenMethod · 0.92

Calls

no outgoing calls

Tested by 2

OpenMethod · 0.74
TestFixRangeOptionsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…