Documentation ¶
Overview ¶
Package fsx contains io/fs extensions.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotRegularFile = errors.New("not a regular file")
ErrNotRegularFile indicates you're not opening a regular file.
Functions ¶
func DirectoryExists ¶ added in v3.17.0
DirectoryExists returns whether the given filename exists and is a directory.
func OpenFile ¶
OpenFile is a wrapper for os.OpenFile that ensures that we're opening a file rather than a directory. If you are not opening a regular file, this func returns an error.
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:
func RegularFileExists ¶ added in v3.17.0
RegularFileExists returns whether the given filename exists and is a regular file.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.