MCPcopy Index your code
hub / github.com/rclone/rclone / Open

Method Open

fs/object/object.go:288–310  ·  view source on GitHub ↗

Open opens the file for read. Call Close() on the returned io.ReadCloser

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

Source from the content-addressed store, hash-verified

286
287// Open opens the file for read. Call Close() on the returned io.ReadCloser
288func (o *MemoryObject) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) {
289 var offset, limit int64 = 0, -1
290 for _, option := range options {
291 switch x := option.(type) {
292 case *fs.RangeOption:
293 offset, limit = x.Decode(o.Size())
294 case *fs.SeekOption:
295 offset = x.Offset
296 default:
297 if option.Mandatory() {
298 fs.Logf(o, "Unsupported mandatory option: %v", option)
299 }
300 }
301 }
302 content := o.content
303 offset = max(offset, 0)
304 if limit < 0 {
305 content = content[offset:]
306 } else {
307 content = content[offset:min(offset+limit, int64(len(content)))]
308 }
309 return io.NopCloser(bytes.NewBuffer(content)), nil
310}
311
312// Update in to the object with the modTime given of the given size
313//

Callers 1

TestMemoryObjectFunction · 0.95

Calls 4

SizeMethod · 0.95
LogfFunction · 0.92
DecodeMethod · 0.65
MandatoryMethod · 0.65

Tested by 1

TestMemoryObjectFunction · 0.76