Skip to content

Commit

Permalink
refactor: better tracker
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <[email protected]>
  • Loading branch information
shizhMSFT committed Dec 30, 2024
1 parent 76ff766 commit ae3f351
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/oras/internal/display/status/track/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func NewReader(r io.Reader, descriptor ocispec.Descriptor, actionPrompt string,
}

func managedReader(r io.Reader, descriptor ocispec.Descriptor, manager track.Manager) (*reader, error) {
tracker, err := track.NewReadTracker(manager, descriptor, r)
tracker, err := manager.Track(descriptor)
if err != nil {
return nil, err
}

return &reader{
ReadTracker: tracker,
ReadTracker: track.NewReadTracker(tracker, r),
manager: manager,
}, nil
}
Expand Down
14 changes: 4 additions & 10 deletions internal/experimental/track/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package track

import (
"io"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

// ReadTracker tracks the transmission based on the read operation.
Expand All @@ -13,16 +11,12 @@ type ReadTracker struct {
offset int64
}

// NewReadTracker returns a new ReadTracker.
func NewReadTracker(manager Manager, descriptor ocispec.Descriptor, r io.Reader) (*ReadTracker, error) {
tracker, err := manager.Track(descriptor)
if err != nil {
return nil, err
}
// NewReadTracker attaches a tracker to a reader.
func NewReadTracker(track Tracker, r io.Reader) *ReadTracker {
return &ReadTracker{
base: r,
tracker: tracker,
}, nil
tracker: track,
}
}

// Read reads from the base reader and updates the status.
Expand Down

0 comments on commit ae3f351

Please sign in to comment.