Open opens the file for read. Call Close() on the returned io.ReadCloser
(ctx context.Context, options ...fs.OpenOption)
| 286 | |
| 287 | // Open opens the file for read. Call Close() on the returned io.ReadCloser |
| 288 | func (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 | // |