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

Method Open

backend/hdfs/object.go:76–106  ·  view source on GitHub ↗

Open an object for read

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

Source from the content-addressed store, hash-verified

74
75// Open an object for read
76func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) {
77 realpath := o.realpath()
78 fs.Debugf(o.fs, "open [%s]", realpath)
79 f, err := o.fs.client.Open(realpath)
80 if err != nil {
81 return nil, err
82 }
83
84 var offset, limit int64 = 0, -1
85 for _, option := range options {
86 switch x := option.(type) {
87 case *fs.SeekOption:
88 offset = x.Offset
89 case *fs.RangeOption:
90 offset, limit = x.Decode(o.Size())
91 }
92 }
93
94 _, err = f.Seek(offset, io.SeekStart)
95 if err != nil {
96 return nil, err
97 }
98
99 if limit != -1 {
100 in = readers.NewLimitedReadCloser(f, limit)
101 } else {
102 in = f
103 }
104
105 return in, err
106}
107
108// Update object
109func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {

Callers

nothing calls this directly

Calls 7

realpathMethod · 0.95
SizeMethod · 0.95
DebugfFunction · 0.92
NewLimitedReadCloserFunction · 0.92
OpenMethod · 0.65
DecodeMethod · 0.65
SeekMethod · 0.65

Tested by

no test coverage detected