W3cubDocs

/Pony

File

[Source]

Operations on a file.

class ref File

Constructors

create

[Source]

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

Returns

open

[Source]

Open for read only. Set _errno according to result.

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

Parameters

Returns

_descriptor

[Source]

Internal constructor from a file descriptor and a path.

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

Parameters

Returns

Public fields

let path: FilePath val

[Source]

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

[Source]

true if the underlying file descriptor has been opened as writeable.

Public Functions

errno

[Source]

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

[Source]

Clears the last error code set for this File. Clears the error indicator for the stream.

fun ref clear_errno()
: None val

Returns

valid

[Source]

Returns true if the file is currently open.

fun box valid()
: Bool val

Returns

read

[Source]

Returns up to len bytes.

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

Parameters

Returns

read_string

[Source]

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

[Source]

Same as write, buts adds a newline.

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

Parameters

Returns

printv

[Source]

Print an iterable collection of ByteSeqs.

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

Parameters

Returns

write

[Source]

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

[Source]

Write an iterable collection of ByteSeqs.

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

Parameters

Returns

queue

[Source]

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

[Source]

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

[Source]

Flush any queued data

fun ref flush()
: Bool val

Returns

position

[Source]

Return the current cursor position in the file.

fun ref position()
: USize val

Returns

size

[Source]

Return the total length of the file.

fun ref size()
: USize val

Returns

seek_start

[Source]

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

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

Parameters

Returns

seek_end

[Source]

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

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

Parameters

Returns

seek

[Source]

Move the cursor position.

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

Parameters

Returns

sync

[Source]

Sync the file contents to physical storage.

fun ref sync()
: None val

Returns

datasync

[Source]

Sync the file contents to physical storage.

fun ref datasync()
: None val

Returns

set_length

[Source]

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

[Source]

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

[Source]

Set the FileMode for this directory.

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

Parameters

Returns

chown

[Source]

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

[Source]

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

fun box touch()
: Bool val

Returns

set_time

[Source]

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

[Source]

Returns an iterator for reading lines from the file.

fun ref lines()
: FileLines ref

Returns

dispose

[Source]

Close the file. Future operations will do nothing.

fun ref dispose()
: None val

Returns

Private Functions

_get_error

[Source]

Fetch errno from the OS.

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

Returns

_pending_writes

[Source]

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

[Source]

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) ?

Returns

_seek

[Source]

Move the cursor position.

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

Parameters

  • offset: I64 val
  • base: I32 val

Returns

_final

[Source]

Close the file.

fun box _final()
: None val

Returns

© 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/files-File