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 ¶
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-engine/pkg/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")
}
}
Example (OpeningFile) ¶
package main
import (
"context"
"fmt"
"log"
"path/filepath"
"github.com/ooni/probe-engine/pkg/fsx"
"github.com/ooni/probe-engine/pkg/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))
}
func RegularFileExists ¶
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.