Operations on a file.
class ref File
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^
Open for read only. Set _errno according to result.
new ref open( from: FilePath val) : File ref^
Internal constructor from a file descriptor and a path.
new ref _descriptor( fd: I32 val, from: FilePath val) : File ref^ ?
This is the filesystem path locating this file on the file system and an object capability granting access to operate on this file.
true
if the underlying file descriptor has been opened as writeable.
Returns the last error code set for this File
fun box errno() : (FileOK val | FileError val | FileEOF val | FileBadFileNumber val | FileExists val | FilePermissionDenied val)
Clears the last error code set for this File. Clears the error indicator for the stream.
fun ref clear_errno() : None val
Returns true if the file is currently open.
fun box valid() : Bool val
Returns up to len bytes.
fun ref read( len: USize val) : Array[U8 val] iso^
Returns up to len bytes. The resulting string may have internal null characters.
fun ref read_string( len: USize val) : String iso^
Same as write, buts adds a newline.
fun ref print( data: (String box | Array[U8 val] box)) : Bool val
Print an iterable collection of ByteSeqs.
fun ref printv( data: ByteSeqIter box) : Bool val
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
Write an iterable collection of ByteSeqs.
fun ref writev( data: ByteSeqIter box) : Bool val
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
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
Flush any queued data
fun ref flush() : Bool val
Return the current cursor position in the file.
fun ref position() : USize val
Return the total length of the file.
fun ref size() : USize val
Set the cursor position relative to the start of the file.
fun ref seek_start( offset: USize val) : None val
Set the cursor position relative to the end of the file.
fun ref seek_end( offset: USize val) : None val
Move the cursor position.
fun ref seek( offset: ISize val) : None val
Sync the file contents to physical storage.
fun ref sync() : None val
Sync the file contents to physical storage.
fun ref datasync() : None val
Change the file size. If it is made larger, the new contents are undefined.
fun ref set_length( len: USize val) : Bool val
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 ?
Set the FileMode for this directory.
fun box chmod( mode: FileMode box) : Bool val
Set the owner and group for this directory. Does nothing on Windows.
fun box chown( uid: U32 val, gid: U32 val) : Bool val
Set the last access and modification times of the directory to now.
fun box touch() : Bool val
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
Returns an iterator for reading lines from the file.
fun ref lines() : FileLines ref
Close the file. Future operations will do nothing.
fun ref dispose() : None val
Fetch errno from the OS.
fun box _get_error() : (FileOK val | FileError val | FileEOF val | FileBadFileNumber val | FileExists val | FilePermissionDenied val)
Write pending data. Returns false if the file wasn't opened with write permission. Returns false and closes the file and discards all pending data if not all the bytes were written. Returns true if it sent all pending data.
fun ref _pending_writes() : Bool val
Write pending data. Returns false if the file wasn't opened with write permission. Raises an error if not all the bytes were written. Returns true if it sent all pending data. Returns num_processed and new pending_total also.
fun box _write_to_disk() : (Bool val , USize val , USize val) ?
Move the cursor position.
fun ref _seek( offset: I64 val, base: I32 val) : None val
Close the file.
fun box _final() : None val
© 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/files-File