file: implement ReadAt
This commit was moved from ipfs/go-ipfs-http-client@88a9b615205816ea20ea38fbee170b3256e51b94
Steven Allen committed
Sep 10, 2019 at 18:07 UTC
d48f8fce64d6496a18b442c74021829554151823
1 file changed
+19
client/httpapi/apifile.go
+19
@@ -82,6 +82,25 @@ func (f *apiFile) Read(p []byte) (int, error) {
82
return n, err
83
}
84
85
+func (f *apiFile) ReadAt(p []byte, off int64) (int, error) {
86
+ // Always make a new request. This method should be parallel-safe.
87
+ resp, err := f.core.Request("cat", f.path.String()).
88
+ Option("offset", off).Option("length", len(p)).Send(f.ctx)
89
+ if err != nil {
90
+ return 0, err
91
+ }
92
+ if resp.Error != nil {
93
+ return 0, resp.Error
94
+ }
95
+ defer resp.Output.Close()
96
+
97
+ n, err := io.ReadFull(resp.Output, p)
98
+ if err == io.ErrUnexpectedEOF {
99
+ err = io.EOF
100
+ }
101
+ return n, err
102
+}
103
+
104
func (f *apiFile) Seek(offset int64, whence int) (int64, error) {
105
switch whence {
106
case io.SeekEnd: