Documentation ¶
Overview ¶
Package fsx contains io/fs extensions.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenFile ¶
OpenFile is a wrapper for os.OpenFile that ensures that we're opening a file rather than a directory. If you are opening a directory, this func returns an *os.PathError error with Err set to syscall.EISDIR.
As mentioned in CONTRIBUTING.md, this is the function you SHOULD be using when opening files.
Example (OpeningDir) ¶
package main import ( "errors" "log" "syscall" "github.com/ooni/probe-cli/v3/internal/fsx" ) func main() { filep, err := fsx.OpenFile("testdata") if !errors.Is(err, syscall.ENOENT) { log.Fatal("unexpected error", err) } if filep != nil { log.Fatal("expected nil fp") } }
Output:
Example (OpeningFile) ¶
package main import ( "context" "fmt" "log" "path/filepath" "github.com/ooni/probe-cli/v3/internal/fsx" "github.com/ooni/probe-cli/v3/internal/netxlite" ) func main() { filep, err := fsx.OpenFile(filepath.Join("testdata", "testfile.txt")) if err != nil { log.Fatal("unexpected error", err) } data, err := netxlite.ReadAllContext(context.Background(), filep) if err != nil { log.Fatal("unexpected error", err) } fmt.Printf("%d\n", len(data)) }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.