File

Operations on a file.

class ref File

Constructors

create

new ref create(
  from: FilePath val)
: File ref^

Parameters

Returns


open

new ref open(
  from: FilePath val)
: File ref^

Parameters

Returns


_descriptor

new ref _descriptor(
  fd: I32 val,
  from: FilePath val)
: File ref^ ?

Parameters

Returns


Public fields


  • let writeable: Bool val

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


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


valid

Returns true if the file is currently open.

fun box valid()
: Bool val

Returns


line

Returns a line as a String. The newline is not included in the string. If there is no more data, this raises an error. If there is a file error, this raises an error.

fun ref line()
: String iso^ ?

Returns


read

Returns up to len bytes.

fun ref read(
  len: USize val)
: Array[U8 val] iso^

Parameters

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

Returns


print

Same as write, buts adds a newline.

fun ref print(
  data: (String box | Array[U8 val] box))
: Bool val

Parameters

Returns


printv

Print an iterable collection of ByteSeqs.

fun ref printv(
  data: ByteSeqIter box)
: Bool val

Parameters

Returns


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


writev

Write an iterable collection of ByteSeqs.

fun ref writev(
  data: ByteSeqIter box)
: Bool val

Parameters

Returns


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


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

Returns


flush

Flush any queued data

fun ref flush()
: Bool val

Returns


position

Return the current cursor position in the file.

fun ref position()
: USize val

Returns


size

Return the total length of the file.

fun ref size()
: USize val

Returns


seek_start

Set the cursor position relative to the start of the file.

fun ref seek_start(
  offset: USize val)
: None val

Parameters

Returns


seek_end

Set the cursor position relative to the end of the file.

fun ref seek_end(
  offset: USize val)
: None val

Parameters

Returns


seek

Move the cursor position.

fun ref seek(
  offset: ISize val)
: None val

Parameters

Returns


sync

Sync the file contents to physical storage.

fun ref sync()
: None val

Returns


datasync

Sync the file contents to physical storage.

fun ref datasync()
: None val

Returns


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

Returns


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


chmod

Set the FileMode for this directory.

fun box chmod(
  mode: FileMode box)
: Bool val

Parameters

Returns


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


touch

Set the last access and modification times of the directory to now.

fun box touch()
: Bool val

Returns


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


lines

Returns an iterator for reading lines from the file.

fun ref lines()
: FileLines ref

Returns


dispose

Close the file. Future operations will do nothing.

fun ref dispose()
: None val

Returns


Private Functions

_get_error

Fetch errno from the OS.

fun box _get_error()
: (FileOK val | FileError val | FileEOF val | 
    FileBadFileNumber val | FileExists val | FilePermissionDenied val)

Returns


_pending_writes

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

Returns


_write_to_disk

Write pending data. Returns false if the file wasn't opened with write permission. Returns raises 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) ?

Returns


_seek

Move the cursor position.

fun ref _seek(
  offset: I64 val,
  base: I32 val)
: None val

Parameters

  • offset: I64 val
  • base: I32 val

Returns


_final

Close the file.

fun box _final()
: None val

Returns