Open an object for read
(ctx context.Context, options ...fs.OpenOption)
| 74 | |
| 75 | // Open an object for read |
| 76 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) { |
| 77 | realpath := o.realpath() |
| 78 | fs.Debugf(o.fs, "open [%s]", realpath) |
| 79 | f, err := o.fs.client.Open(realpath) |
| 80 | if err != nil { |
| 81 | return nil, err |
| 82 | } |
| 83 | |
| 84 | var offset, limit int64 = 0, -1 |
| 85 | for _, option := range options { |
| 86 | switch x := option.(type) { |
| 87 | case *fs.SeekOption: |
| 88 | offset = x.Offset |
| 89 | case *fs.RangeOption: |
| 90 | offset, limit = x.Decode(o.Size()) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | _, err = f.Seek(offset, io.SeekStart) |
| 95 | if err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | |
| 99 | if limit != -1 { |
| 100 | in = readers.NewLimitedReadCloser(f, limit) |
| 101 | } else { |
| 102 | in = f |
| 103 | } |
| 104 | |
| 105 | return in, err |
| 106 | } |
| 107 | |
| 108 | // Update object |
| 109 | func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error { |