Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): Implement io.WriterTo in Reader #9659

Merged
merged 5 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
fix review comments
  • Loading branch information
tritone committed Mar 28, 2024
commit 45d0180b2600c4955e5962586e1e21c877d2a895
10 changes: 4 additions & 6 deletions storage/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,10 +1486,8 @@ func (r *gRPCReader) updateCRC(b []byte) {

// Checks whether the CRC matches at the conclusion of a read, if CRC checking was enabled.
func (r *gRPCReader) runCRCCheck() error {
if r.checkCRC {
if r.gotCRC != r.wantCRC {
return fmt.Errorf("storage: bad CRC on read: got %d, want %d", r.gotCRC, r.wantCRC)
}
if r.checkCRC && r.gotCRC != r.wantCRC {
return fmt.Errorf("storage: bad CRC on read: got %d, want %d", r.gotCRC, r.wantCRC)
}
return nil
}
Expand All @@ -1510,7 +1508,7 @@ func (r *gRPCReader) Read(p []byte) (int, error) {
// using the same reader. One encounters an error and the stream is closed
// and then reopened while the other routine attempts to read from it.
if r.stream == nil {
return 0, fmt.Errorf("reader has been closed")
return 0, fmt.Errorf("storage: reader has been closed")
}

var n int
Expand Down Expand Up @@ -1567,7 +1565,7 @@ func (r *gRPCReader) WriteTo(w io.Writer) (int64, error) {
// using the same reader. One encounters an error and the stream is closed
// and then reopened while the other routine attempts to read from it.
if r.stream == nil {
return 0, fmt.Errorf("reader has been closed")
return 0, fmt.Errorf("storage: reader has been closed")
}

// Track bytes written during before call.
Expand Down
2 changes: 1 addition & 1 deletion storage/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ func (r *httpReader) Read(p []byte) (int, error) {
r.gotCRC = crc32.Update(r.gotCRC, crc32cTable, p[:n])
}
if err == nil {
return n, err
return n, nil
}
if err == io.EOF {
// Check CRC here. It would be natural to check it in Close, but
Expand Down
1 change: 1 addition & 0 deletions storage/retry_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ var methods = map[string][]retryFunc{
return err
},
func(ctx context.Context, c *Client, fs *resources, _ bool) error {
tritone marked this conversation as resolved.
Show resolved Hide resolved
// This tests downloads by calling Reader.Read rather than Reader.WriteTo.
r, err := c.Bucket(fs.bucket.Name).Object(fs.object.Name).NewReader(ctx)
if err != nil {
return err
Expand Down