Open an object for read
(ctx context.Context, options ...fs.OpenOption)
| 616 | |
| 617 | // Open an object for read |
| 618 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) { |
| 619 | if o.fs.opt.Discard { |
| 620 | return nil, errWriteOnly |
| 621 | } |
| 622 | var offset, limit int64 = 0, -1 |
| 623 | for _, option := range options { |
| 624 | switch x := option.(type) { |
| 625 | case *fs.RangeOption: |
| 626 | offset, limit = x.Decode(int64(len(o.od.data))) |
| 627 | case *fs.SeekOption: |
| 628 | offset = x.Offset |
| 629 | default: |
| 630 | if option.Mandatory() { |
| 631 | fs.Logf(o, "Unsupported mandatory option: %v", option) |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | if offset > int64(len(o.od.data)) { |
| 636 | offset = int64(len(o.od.data)) |
| 637 | } |
| 638 | data := o.od.data[offset:] |
| 639 | if limit >= 0 { |
| 640 | if limit > int64(len(data)) { |
| 641 | limit = int64(len(data)) |
| 642 | } |
| 643 | data = data[:limit] |
| 644 | } |
| 645 | return io.NopCloser(bytes.NewBuffer(data)), nil |
| 646 | } |
| 647 | |
| 648 | // Update the object with the contents of the io.Reader, modTime and size |
| 649 | // |