MCPcopy
hub / github.com/rclone/rclone / Open

Method Open

backend/cache/object.go:218–246  ·  view source on GitHub ↗

Open is used to request a specific part of the file using fs.RangeOption

(ctx context.Context, options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

216
217// Open is used to request a specific part of the file using fs.RangeOption
218func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) {
219 var err error
220
221 if o.Object == nil {
222 err = o.refreshFromSource(ctx, true)
223 } else {
224 err = o.refresh(ctx)
225 }
226 if err != nil {
227 return nil, err
228 }
229
230 cacheReader := NewObjectHandle(ctx, o, o.CacheFs)
231 var offset, limit int64 = 0, -1
232 for _, option := range options {
233 switch x := option.(type) {
234 case *fs.SeekOption:
235 offset = x.Offset
236 case *fs.RangeOption:
237 offset, limit = x.Decode(o.Size())
238 }
239 _, err = cacheReader.Seek(offset, io.SeekStart)
240 if err != nil {
241 return nil, err
242 }
243 }
244
245 return readers.NewLimitedReadCloser(cacheReader, limit), nil
246}
247
248// Update will change the object data
249func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {

Callers

nothing calls this directly

Calls 7

refreshFromSourceMethod · 0.95
refreshMethod · 0.95
SizeMethod · 0.95
NewLimitedReadCloserFunction · 0.92
NewObjectHandleFunction · 0.85
DecodeMethod · 0.65
SeekMethod · 0.65

Tested by

no test coverage detected