Documentation ¶
Index ¶
- Variables
- func CheckDone(ctx context.Context) error
- func CopyClose(dst io.WriteCloser, src io.ReadCloser) (int64, error)
- func CopyCloseSrc(dst io.Writer, src io.ReadCloser) (int64, error)
- func DiscardCloser() io.WriteCloser
- func EnsureWriter(w io.Writer) io.Writer
- func ExpandMany(paths []string) ([]string, error)
- func ExtlessFile(fpath string) string
- func IsFileEmpty(f *os.File) (bool, error)
- func Mkdirs(ps ...string) error
- func Rmdirs(ps ...string) error
- type ErrWriter
- type NopWriteCloser
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPathsetNil = errors.New("pathset nil")
ErrPathsetNil is a standard error for when things that expect a pathset don't get one.
Functions ¶
func CheckDone ¶
CheckDone checks, without blocking, to see if ctx has been cancelled as of this instant in time. If so, it propagates the context's error value; if not, it returns nil.
Example ¶
ExampleCheckDone is a runnable example for CheckDone.
package main import ( "context" "errors" "fmt" "github.com/c4-project/c4t/internal/helper/iohelp" ) func main() { ctx, cancel := context.WithCancel(context.Background()) // This shouldn't block, but should return without an error: err1 := iohelp.CheckDone(ctx) // This should also not block, but return a 'cancelled' error: cancel() err2 := iohelp.CheckDone(ctx) fmt.Printf("1: nil=%v, cancelled=%v\n", err1 == nil, errors.Is(err1, context.Canceled)) fmt.Printf("2: nil=%v, cancelled=%v\n", err2 == nil, errors.Is(err2, context.Canceled)) }
Output: 1: nil=true, cancelled=false 2: nil=false, cancelled=true
func CopyClose ¶
func CopyClose(dst io.WriteCloser, src io.ReadCloser) (int64, error)
CopyClose copies src to dst, then closes both. It closes src and dst even if there was an error while copying.
func CopyCloseSrc ¶
CopyCloseSrc copies src to dst, then closes src. It closes src even if there was an error while copying.
func DiscardCloser ¶
func DiscardCloser() io.WriteCloser
DiscardCloser is like io.Discard, but implements WriteCloser.
func EnsureWriter ¶
EnsureWriter passes through w if non-nil, or supplies io.Discard otherwise.
func ExpandMany ¶
ExpandMany applies homedir.Expand to every (file)path in paths.
func ExtlessFile ¶
ExtlessFile gets the file part of slash-path fpath without its extension.
Example ¶
ExampleExtlessFile is a runnable example for ExtlessFile.
package main import ( "fmt" "github.com/c4-project/c4t/internal/helper/iohelp" ) func main() { fmt.Println(iohelp.ExtlessFile("foo.c")) fmt.Println(iohelp.ExtlessFile("/home/piers/test")) fmt.Println(iohelp.ExtlessFile("/home/piers/example.txt")) }
Output: foo test example
func IsFileEmpty ¶
IsFileEmpty checks whether the open file f is empty. It can fail if we can't stat the file.
Types ¶
type ErrWriter ¶
type ErrWriter struct {
Err error
}
ErrWriter provides an io.Writer that fails with the wrapped error.
type NopWriteCloser ¶
NopWriteCloser is like a NopCloser, but implements WriteCloser rather than ReadCloser.