721ce95315
* 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
36 lines
711 B
Go
36 lines
711 B
Go
package fsx_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"path/filepath"
|
|
"syscall"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/fsx"
|
|
"github.com/ooni/probe-cli/v3/internal/iox"
|
|
)
|
|
|
|
func ExampleOpenFile_openingDir() {
|
|
filep, err := fsx.OpenFile("testdata")
|
|
if !errors.Is(err, syscall.ENOENT) {
|
|
log.Fatal("unexpected error", err)
|
|
}
|
|
if filep != nil {
|
|
log.Fatal("expected nil fp")
|
|
}
|
|
}
|
|
|
|
func ExampleOpenFile_openingFile() {
|
|
filep, err := fsx.OpenFile(filepath.Join("testdata", "testfile.txt"))
|
|
if err != nil {
|
|
log.Fatal("unexpected error", err)
|
|
}
|
|
data, err := iox.ReadAllContext(context.Background(), filep)
|
|
if err != nil {
|
|
log.Fatal("unexpected error", err)
|
|
}
|
|
fmt.Printf("%d\n", len(data))
|
|
}
|