Skip to content

Commit 0e1e73b

Browse files
committed
Remove ioutils.CountWriter
We had 2 implementations to keep track of how long an io.Reader is: ioutils.CountWriter and ioutils.PositionTrackerReader. ioutils.CountWriter implements io.Writer, but it just discards the bytes and keeps track of the number of bytes written. The caller connects it to an existing io.Reader by creating an io.TeeReader which writes to it whenever the original reader is read. ioutils.PositionTrackerReader is a simpler interface that wraps an existing io.Reader and proxies Read requests while updating it's internal position. This change removes CountWriter in favor of the simpler and better tested PositionTrackerReader. Signed-off-by: Kern Walster <[email protected]>
1 parent 3510a96 commit 0e1e73b

File tree

2 files changed

+3
-58
lines changed

2 files changed

+3
-58
lines changed

fs/artifact_fetcher.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,17 @@ func FetchSociArtifacts(ctx context.Context, refspec reference.Spec, indexDesc o
146146
}
147147
defer indexReader.Close()
148148

149-
cw := new(ioutils.CountWriter)
150-
tee := io.TeeReader(indexReader, cw)
149+
tr := ioutils.NewPositionTrackerReader(indexReader)
151150

152151
var index soci.Index
153-
err = soci.DecodeIndex(tee, &index)
152+
err = soci.DecodeIndex(tr, &index)
154153
if err != nil {
155154
return nil, fmt.Errorf("cannot deserialize byte data to index: %w", err)
156155
}
157156

158157
desc := ocispec.Descriptor{
159158
Digest: indexDesc.Digest,
160-
Size: cw.Size(),
159+
Size: tr.CurrentPos(),
161160
}
162161

163162
// batch will prevent content from being garbage collected in the middle of the following operations

util/ioutils/countwriter.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)