fix(all): introduce and use iox.CopyContext (#380)
* fix(all): introduce and use iox.CopyContext This PR is part of https://github.com/ooni/probe/issues/1417. In https://github.com/ooni/probe-cli/pull/379 we introduced a context aware wrapper for io.ReadAll (formerly ioutil.ReadAll). Here we introduce a context aware wrapper for io.Copy. * fix(humanize): more significant digits * fix: rename humanize files to follow the common pattern * fix aligment * fix test
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/iox"
|
||||
)
|
||||
|
||||
func getShasum(path string) (string, error) {
|
||||
@@ -17,7 +19,7 @@ func getShasum(path string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := io.Copy(hasher, f); err != nil {
|
||||
if _, err := iox.CopyContext(context.Background(), hasher, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return hex.EncodeToString(hasher.Sum(nil)), nil
|
||||
|
||||
Reference in New Issue
Block a user