Direct parent types
Represents file system path such as a file, a block device, etcDirect subtypes: 7
- access(f:File, mode:Int=0) Source: stdlib.ngs:6478
Check whether current process has the specified access to the file. Wrapper around ACCESS(2). Throws CException.
mode One of the file ACCESS::* modes, defaults to ACCESS::F_OK (test file existance only).
access(File("mydata"), ACCESS::R_OK).not() throws Error("No access to data file").set("file", "mydata")
- close(f:File) Source: stdlib.ngs:4590
Close a file and sets the "fd" field to null. Uses CLOSE(2). Throws InvalidArgument if file is not open. Throws FileIOFail if an underlying error occurs.
- init(f:File, path:Str) Source: stdlib.ngs:4507
Create File object from the given path. The file is not open.
f = File('/tmp/myfile')
- init(f:File, fd:Int) Source: stdlib.ngs:4513
Create File object from the given file descriptor.
- init(f:File, path:Path) Source: stdlib.ngs:4517
- lines(f:File, cb:Fun) Source: stdlib.ngs:4553
Iterate over lines of the file
f Closed File cb function to call with successive lines from the file
- lines(f:File) Source: stdlib.ngs:4568
Get all lines of the file
ReturnsArr of Str
- lines(f:File, lines_:Arr) Source: stdlib.ngs:4573
Write given lines to the file. Overwrites the file.
ReturnsArr of Str
- open(f:File, flags:Str) Source: stdlib.ngs:4531
Open a file and set the "fd" field to the file descriptor. Uses OPEN(2). Throws InvalidArgument if file is already open. Throws FileIOFail if an underlying error occurs.
flags Currently "r", "w" or "a" for read/write/append
- read(f:File) Source: stdlib.ngs:6498
Read whole file
- Str(f:File) Source: stdlib.ngs:4521
String representation of File
open(File("tmp/v8/LICENSE"), "r").Str().echo() # Output: <File path=tmp/v8/LICENSE fd=4>
- write(s:Str, f:File) Source: stdlib.ngs:6514
Write whole file if it's closed, write to file descriptor if it's open
- write(f:File, s:Str) Source: stdlib.ngs:6519