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)
| 143 | // It also adjusts any SeekOption~s, turning them into absolute |
| 144 | // RangeOption~s instead. |
| 145 | func 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. |
| 180 | type SeekOption struct { |
no outgoing calls
searching dependent graphs…