Open a remote http file object for reading. Seek is supported
(ctx context.Context, options ...fs.OpenOption)
| 756 | |
| 757 | // Open a remote http file object for reading. Seek is supported |
| 758 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) { |
| 759 | url := o.url() |
| 760 | req, err := http.NewRequestWithContext(ctx, "GET", url, nil) |
| 761 | if err != nil { |
| 762 | return nil, fmt.Errorf("Open failed: %w", err) |
| 763 | } |
| 764 | |
| 765 | // Add optional headers |
| 766 | for k, v := range fs.OpenOptionHeaders(options) { |
| 767 | req.Header.Add(k, v) |
| 768 | } |
| 769 | o.fs.addHeaders(req) |
| 770 | |
| 771 | // Do the request |
| 772 | res, err := o.fs.httpClient.Do(req) |
| 773 | err = statusError(res, err) |
| 774 | if err != nil { |
| 775 | return nil, fmt.Errorf("Open failed: %w", err) |
| 776 | } |
| 777 | if err = o.decodeMetadata(ctx, res); err != nil { |
| 778 | return nil, fmt.Errorf("decodeMetadata failed: %w", err) |
| 779 | } |
| 780 | return res.Body, nil |
| 781 | } |
| 782 | |
| 783 | // Hashes returns hash.HashNone to indicate remote hashing is unavailable |
| 784 | func (f *Fs) Hashes() hash.Set { |