Source File
file.go
Belonging Package
src.elv.sh/pkg/eval/mods/file
package fileimport ()var Ns = eval.NsBuilder{}.AddGoFns("file:", fns).Ns()var fns = map[string]interface{}{"close": close,"open": open,"pipe": pipe,"prclose": prclose,"pwclose": pwclose,}//elvdoc:fn open//// ```elvish// file:open $filename// ```//// Opens a file. Currently, `open` only supports opening a file for reading.// File must be closed with `close` explicitly. Example://// ```elvish-transcript// ~> cat a.txt// This is// a file.// ~> use file// ~> f = (file:open a.txt)// ~> cat < $f// This is// a file.// ~> close $f// ```//// @cf closefunc ( string) (vals.File, error) {return os.Open()}//elvdoc:fn close//// ```elvish// ~> file:close $file// ```//// Closes a file opened with `open`.//// @cf openfunc ( vals.File) error {return .Close()}//elvdoc:fn pipe//// ```elvish// file:pipe// ```//// Create a new Unix pipe that can be used in redirections.//// A pipe contains both the read FD and the write FD. When redirecting command// input to a pipe with `<`, the read FD is used. When redirecting command output// to a pipe with `>`, the write FD is used. It is not supported to redirect both// input and output with `<>` to a pipe.//// Pipes have an OS-dependent buffer, so writing to a pipe without an active reader// does not necessarily block. Pipes **must** be explicitly closed with `prclose`// and `pwclose`.//// Putting values into pipes will cause those values to be discarded.//// Examples (assuming the pipe has a large enough buffer)://// ```elvish-transcript// ~> p = (file:pipe)// ~> echo 'lorem ipsum' > $p// ~> head -n1 < $p// lorem ipsum// ~> put 'lorem ipsum' > $p// ~> head -n1 < $p// # blocks// # $p should be closed with prclose and pwclose afterwards// ```//// @cf prclose pwclosefunc () (vals.Pipe, error) {, , := os.Pipe()return vals.NewPipe(, ),}//elvdoc:fn prclose//// ```elvish// file:prclose $pipe// ```//// Close the read end of a pipe.//// @cf pwclose pipefunc ( vals.Pipe) error {return .ReadEnd.Close()}//elvdoc:fn pwclose//// ```elvish// file:pwclose $pipe// ```//// Close the write end of a pipe.//// @cf prclose pipefunc ( vals.Pipe) error {return .WriteEnd.Close()}
The pages are generated with Golds v0.2.8-preview. (GOOS=darwin GOARCH=arm64)