Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
feat: Implement IoCallback support (#23)
Browse files Browse the repository at this point in the history
* feat: Implement IoCallback support

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix build

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Aug 23, 2021
1 parent 2820be4 commit eb22951
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ github.com/dave/rebecca v0.9.1/go.mod h1:N6XYdMD/OKw3lkF3ywh8Z6wPGuwNFDNtWYEMFWE
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/pprof v0.0.0-20181127221834-b4f47329b966/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
Expand Down
9 changes: 9 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"strings"

"github.com/beyondstorage/go-storage/v4/pkg/iowrap"
"github.com/beyondstorage/go-storage/v4/services"
. "github.com/beyondstorage/go-storage/v4/types"
)
Expand Down Expand Up @@ -153,6 +154,9 @@ func (s *Storage) read(ctx context.Context, path string, w io.Writer, opt pairSt
if opt.HasOffset {
offset = opt.Offset
}
if opt.HasIoCallback {
w = iowrap.CallbackWriter(w, opt.IoCallback)
}

written, err := w.Write(o.data[offset:])
if err != nil {
Expand Down Expand Up @@ -184,6 +188,10 @@ func (s *Storage) write(ctx context.Context, path string, r io.Reader, size int6
o.mode = ModeRead
o.data = make([]byte, size)

if opt.HasIoCallback {
r = iowrap.CallbackReader(r, opt.IoCallback)
}

// TODO: we need to add integration tests for this case.
read, err := r.Read(o.data)
// Update o.length even after read met error.
Expand All @@ -205,6 +213,7 @@ func (s *Storage) writeAppend(ctx context.Context, o *Object, r io.Reader, size
return 0, services.ErrObjectModeInvalid
}
}

buf := make([]byte, size)
read, err := r.Read(buf)
ro.data = append(ro.data, buf[:read]...)
Expand Down

0 comments on commit eb22951

Please sign in to comment.