File
Operations on a file.
class ref File
Constructors
create
Attempt to open for read/write, creating if it doesn't exist, preserving the contents if it does exist. Set errno according to result.
new ref create( from: FilePath val) : File ref^
Parameters
- from: FilePath val
Returns
- File ref^
open
Open for read only. Set _errno according to result.
new ref open( from: FilePath val) : File ref^
Parameters
- from: FilePath val
Returns
- File ref^
Public fields
let path: FilePath val
This is the filesystem path locating this file on the file system and an object capability granting access to operate on this file.
let writeable: Bool val
true
if the underlying file descriptor has been opened as writeable.
Public Functions
errno
Returns the last error code set for this File
fun box errno() : (FileOK val | FileError val | FileEOF val | FileBadFileNumber val | FileExists val | FilePermissionDenied val)
Returns
- (FileOK val | FileError val | FileEOF val | FileBadFileNumber val | FileExists val | FilePermissionDenied val)
clear_errno
Clears the last error code set for this File. Clears the error indicator for the stream.
fun ref clear_errno() : None val
Returns
- None val
valid
Returns true if the file is currently open.
fun box valid() : Bool val
Returns
- Bool val
read
Returns up to len bytes.
fun ref read( len: USize val) : Array[U8 val] iso^
Parameters
- len: USize val
Returns
read_string
Returns up to len bytes. The resulting string may have internal null characters.
fun ref read_string( len: USize val) : String iso^
Parameters
- len: USize val
Returns
- String iso^
Same as write, buts adds a newline.
fun ref print( data: (String box | Array[U8 val] box)) : Bool val
Parameters
Returns
- Bool val
printv
Print an iterable collection of ByteSeqs.
fun ref printv( data: ByteSeqIter box) : Bool val
Parameters
- data: ByteSeqIter box
Returns
- Bool val
write
Returns false if the file wasn't opened with write permission. Returns false and closes the file if not all the bytes were written.
fun ref write( data: (String box | Array[U8 val] box)) : Bool val
Parameters
Returns
- Bool val
writev
Write an iterable collection of ByteSeqs.
fun ref writev( data: ByteSeqIter box) : Bool val
Parameters
- data: ByteSeqIter box
Returns
- Bool val
queue
Queue data to be written NOTE: Queue'd data will always be written before normal print/write requested data
fun ref queue( data: (String box | Array[U8 val] box)) : None val
Parameters
Returns
- None val
queuev
Queue an iterable collection of ByteSeqs to be written NOTE: Queue'd data will always be written before normal print/write requested data
fun ref queuev( data: ByteSeqIter box) : None val
Parameters
- data: ByteSeqIter box
Returns
- None val
flush
Flush any queued data
fun ref flush() : Bool val
Returns
- Bool val
position
Return the current cursor position in the file.
fun ref position() : USize val
Returns
- USize val
size
Return the total length of the file.
fun ref size() : USize val
Returns
- USize val
seek_start
Set the cursor position relative to the start of the file.
fun ref seek_start( offset: USize val) : None val
Parameters
- offset: USize val
Returns
- None val
seek_end
Set the cursor position relative to the end of the file.
fun ref seek_end( offset: USize val) : None val
Parameters
- offset: USize val
Returns
- None val
seek
Move the cursor position.
fun ref seek( offset: ISize val) : None val
Parameters
- offset: ISize val
Returns
- None val
sync
Sync the file contents to physical storage.
fun ref sync() : None val
Returns
- None val
datasync
Sync the file contents to physical storage.
fun ref datasync() : None val
Returns
- None val
set_length
Change the file size. If it is made larger, the new contents are undefined.
fun ref set_length( len: USize val) : Bool val
Parameters
- len: USize val
Returns
- Bool val
info
Return a FileInfo for this directory. Raise an error if the fd is invalid or if we don't have FileStat permission.
fun box info() : FileInfo val ?
Returns
- FileInfo val ?
chmod
Set the FileMode for this directory.
fun box chmod( mode: FileMode box) : Bool val
Parameters
- mode: FileMode box
Returns
- Bool val
chown
Set the owner and group for this directory. Does nothing on Windows.
fun box chown( uid: U32 val, gid: U32 val) : Bool val
Parameters
Returns
- Bool val
touch
Set the last access and modification times of the directory to now.
fun box touch() : Bool val
Returns
- Bool val
set_time
Set the last access and modification times of the directory to the given values.
fun box set_time( atime: (I64 val , I64 val), mtime: (I64 val , I64 val)) : Bool val
Parameters
Returns
- Bool val
lines
Returns an iterator for reading lines from the file.
fun ref lines() : FileLines ref
Returns
- FileLines ref
dispose
Close the file. Future operations will do nothing.
fun ref dispose() : None val
Returns
- None val
© 2016-2020, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/files-File