mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-27 13:27:50 +08:00
Merge pull request ipfs/go-ipfs-http-client#31 from ipfs/feat/read-at
file: implement ReadAt This commit was moved from ipfs/go-ipfs-http-client@187d8d16e5
This commit is contained in:
commit
c71a840bb8
@ -82,6 +82,25 @@ func (f *apiFile) Read(p []byte) (int, error) {
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (f *apiFile) ReadAt(p []byte, off int64) (int, error) {
|
||||
// Always make a new request. This method should be parallel-safe.
|
||||
resp, err := f.core.Request("cat", f.path.String()).
|
||||
Option("offset", off).Option("length", len(p)).Send(f.ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if resp.Error != nil {
|
||||
return 0, resp.Error
|
||||
}
|
||||
defer resp.Output.Close()
|
||||
|
||||
n, err := io.ReadFull(resp.Output, p)
|
||||
if err == io.ErrUnexpectedEOF {
|
||||
err = io.EOF
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (f *apiFile) Seek(offset int64, whence int) (int64, error) {
|
||||
switch whence {
|
||||
case io.SeekEnd:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user