MCPcopy
hub / github.com/rclone/rclone / Open

Method Open

backend/mega/mega.go:1135–1167  ·  view source on GitHub ↗

Open an object for read

(ctx context.Context, options ...fs.OpenOption)

Source from the content-addressed store, hash-verified

1133
1134// Open an object for read
1135func (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//

Callers

nothing calls this directly

Calls 8

SizeMethod · 0.95
LogfFunction · 0.92
NewLimitedReadCloserFunction · 0.92
shouldRetryFunction · 0.70
DecodeMethod · 0.65
MandatoryMethod · 0.65
CallMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected