Documentation ¶
Overview ¶
Package stdio sets the source for standard input and the destination for standard output:
- if the filename is "-", input is read from stdin and output is written to stdout
- otherwise input is read from the named file with output written to stdout
- if the WithInPlace option is set, a temporary file is created and the original file overwritten when the file descriptor is closed
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
func Open ¶
Open opens the file using a temporary file by appending a random string to the filename. The file is renamed to the original name when it is closed.
If the filename is "-", input is read from stdin and written to stdout.
Example ¶
package main import ( "fmt" "codeberg.org/msantos/redact/pkg/stdio" ) func main() { f, err := stdio.Open("-") if err != nil { fmt.Printf("unexpected error: %v", err) return } _, _ = f.WriteString("stdout") }
Output: stdout
func (*File) Close ¶
Close closes the file and conditionally renames to the original filename based on the error status set by SetErr:
- nil: file is renamed
- non-nil: the temporary file is deleted, the source file closed and the error returned
Click to show internal directories.
Click to hide internal directories.