Open an object for read
(ctx context.Context, options ...fs.OpenOption)
| 1133 | |
| 1134 | // Open an object for read |
| 1135 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) { |
| 1136 | var offset, limit int64 = 0, -1 |
| 1137 | for _, option := range options { |
| 1138 | switch x := option.(type) { |
| 1139 | case *fs.SeekOption: |
| 1140 | offset = x.Offset |
| 1141 | case *fs.RangeOption: |
| 1142 | offset, limit = x.Decode(o.Size()) |
| 1143 | default: |
| 1144 | if option.Mandatory() { |
| 1145 | fs.Logf(o, "Unsupported mandatory option: %v", option) |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | var d *mega.Download |
| 1151 | err = o.fs.pacer.Call(func() (bool, error) { |
| 1152 | d, err = o.fs.srv.NewDownload(o.info) |
| 1153 | return shouldRetry(ctx, err) |
| 1154 | }) |
| 1155 | if err != nil { |
| 1156 | return nil, fmt.Errorf("open download file failed: %w", err) |
| 1157 | } |
| 1158 | |
| 1159 | oo := &openObject{ |
| 1160 | ctx: ctx, |
| 1161 | o: o, |
| 1162 | d: d, |
| 1163 | skip: offset, |
| 1164 | } |
| 1165 | |
| 1166 | return readers.NewLimitedReadCloser(oo, limit), nil |
| 1167 | } |
| 1168 | |
| 1169 | // Update the object with the contents of the io.Reader, modTime and size |
| 1170 | // |
nothing calls this directly
no test coverage detected