Open opens the file for read. Call Close() on the returned io.ReadCloser
(ctx context.Context, options ...fs.OpenOption)
| 1048 | |
| 1049 | // Open opens the file for read. Call Close() on the returned io.ReadCloser |
| 1050 | func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (rc io.ReadCloser, err error) { |
| 1051 | if o.f.opt.NoDataEncryption { |
| 1052 | return o.Object.Open(ctx, options...) |
| 1053 | } |
| 1054 | |
| 1055 | var openOptions []fs.OpenOption |
| 1056 | var offset, limit int64 = 0, -1 |
| 1057 | for _, option := range options { |
| 1058 | switch x := option.(type) { |
| 1059 | case *fs.SeekOption: |
| 1060 | offset = x.Offset |
| 1061 | case *fs.RangeOption: |
| 1062 | offset, limit = x.Decode(o.Size()) |
| 1063 | default: |
| 1064 | // pass on Options to underlying open if appropriate |
| 1065 | openOptions = append(openOptions, option) |
| 1066 | } |
| 1067 | } |
| 1068 | rc, err = o.f.cipher.DecryptDataSeek(ctx, func(ctx context.Context, underlyingOffset, underlyingLimit int64) (io.ReadCloser, error) { |
| 1069 | if underlyingOffset == 0 && underlyingLimit < 0 { |
| 1070 | // Open with no seek |
| 1071 | return o.Object.Open(ctx, openOptions...) |
| 1072 | } |
| 1073 | // Open stream with a range of underlyingOffset, underlyingLimit |
| 1074 | end := int64(-1) |
| 1075 | if underlyingLimit >= 0 { |
| 1076 | end = underlyingOffset + underlyingLimit - 1 |
| 1077 | if end >= o.Object.Size() { |
| 1078 | end = -1 |
| 1079 | } |
| 1080 | } |
| 1081 | newOpenOptions := append(openOptions, &fs.RangeOption{Start: underlyingOffset, End: end}) |
| 1082 | return o.Object.Open(ctx, newOpenOptions...) |
| 1083 | }, offset, limit) |
| 1084 | if err != nil { |
| 1085 | return nil, err |
| 1086 | } |
| 1087 | return rc, nil |
| 1088 | } |
| 1089 | |
| 1090 | // Update in to the object with the modTime given of the given size |
| 1091 | func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error { |
nothing calls this directly
no test coverage detected