class Bytes
A Bytes object represents an array of UInt8 and provides various utilities for importing and exporting values into and out of that array.
The object maintains a position marker which is used to denote the position from which new export operations proceed.
An export will advance the position by the appropriate amount.
func export8Bits() -> UInt8
Exports one UInt8 from the current position. Advances the position marker by 1 byte.
- returns: The UInt8 value
struct Dir
This class represents a directory on the file system.
It can be used for creating & inspecting directories and enumerating directory contents.
func delete() throws
Deletes the directory. The directory must be empty in order to be successfuly deleted.
- throws: `PerfectError.FileError`
var parentDir: Dir?
Returns a Dir object representing the current Dir's parent. Returns nil if there is no parent.
class File
Provides access to a file on the local file system
var exists: Bool
Checks that the file exists on the file system
- returns: True if the file exists or false otherwise
var realPath: String
Returns the file path. If the file is a symbolic link, the link will be resolved.
var modificationTime: Int
Returns the modification date for the file in the standard UNIX format of seconds since 1970/01/01 00:00:00 GMT
- returns: The date as Int
func init(_ path: String, fd: Int32 = -1)
Create a file object given a path and open mode
- parameter path: Path to the file which will be accessed
- parameter fd: The file descriptor, if any, for an already opened file
func abandon()
Resets the internal file descriptor, leaving the file opened if it had been.
extension File
enum OpenMode
The open mode for the file.
case read
Opens the file for read-only access.
case write
Opens the file for write-only access, creating the file if it did not exist.
case readWrite
Opens the file for read-write access, creating the file if it did not exist.
case append
Opens the file for read-write access, creating the file if it did not exist and moving the file marker to the end.
case truncate
Opens the file for read-write access, creating the file if it did not exist and setting the file's size to zero.
extension File
func moveTo(path: String, overWrite: Bool = false) throws -> File
Moves the file to the new location, optionally overwriting any existing file
- parameter path: The path to move the file to
- parameter overWrite: Indicates that any existing file at the destination path should first be deleted
- returns: Returns a new file object representing the new location
- throws: `PerfectError.FileError`
func copyTo(path pth: String, overWrite: Bool = false) throws -> File
Copies the file to the new location, optionally overwriting any existing file
- parameter path: The path to copy the file to
- parameter overWrite: Indicates that any existing file at the destination path should first be deleted
- returns: Returns a new file object representing the new location
- throws: `PerfectError.FileError`
extension File
func lock(byteCount: Int) throws
Attempts to place an advisory lock starting from the current position marker up to the indicated byte count. This function will block the current thread until the lock can be performed.
- parameter byteCount: The number of bytes to lock
- throws: `PerfectError.FileError`
func unlock(byteCount: Int) throws
Unlocks the number of bytes starting from the current position marker up to the indicated byte count.
- parameter byteCount: The number of bytes to unlock
- throws: `PerfectError.FileError`
func tryLock(byteCount: Int) throws
Attempts to place an advisory lock starting from the current position marker up to the indicated byte count. This function will throw an exception if the file is already locked, but will not block the current thread.
- parameter byteCount: The number of bytes to lock
- throws: `PerfectError.FileError`
class JSONDecoding
This non-instantiable object serves as an access point to a registry for JSONConvertibleObjects
A JSONConvertibleObject is a custom class or struct which can be converted to and from JSON.
struct Log
Placeholder functions for logging system
struct PerfectServer
Provides access to various system level features for the process.
A static instance of this class is created at startup and all access to this object go through the `PerfectServer.staticPerfectServer` static property.
class SysProcess
This class permits an external process to be launched given a set of command line arguments and environment variables.
The standard in, out and err file streams are made available. The process can be terminated or permitted to be run to completion.
func init(_ cmd: String, args: [String]?, env: [(String,String)]?) throws
Initialize the object and launch the process.
- parameter cmd: The path to the process which will be launched.
- parameter args: An optional array of String arguments which will be given to the process.
- parameter env: An optional array of environment variable name and value pairs.
- throws: `PerfectError.SystemError`
func isOpen() -> Bool
Returns true if the process was opened and was running at some point.
Note that the process may not be currently running. Use `wait(false)` to check if the process is currently running.
func detach()
Detach from the process such that it will not be manually terminated when this object is deinitialized.
struct UTF8Encoding
Utility wrapper permitting a UTF-8 character generator to encode a String. Also permits a String to be converted into a UTF-8 byte array.
func getNow() -> Double
Returns the current time according to ICU
ICU dates are the number of milliseconds since the reference date of Thu, 01-Jan-1970 00:00:00 GMT
func formatDate(_ date: Double, format: String, timezone inTimezone: String? = nil, locale inLocale: String? = nil) throws -> String
Format a date value according to the indicated format string and return a date string.
- parameter date: The date value
- parameter format: The format by which the date will be formatted. Use a valid strftime style format string.
- parameter timezone: The optional timezone in which the date is expected to be based. Default is the local timezone.
- parameter locale: The optional locale which will be used when parsing the date. Default is the current global locale.
- returns: The resulting date string
- throws: `PerfectError.systemError`
The object maintains a position marker which is used to denote the position from which new export operations proceed.
An export will advance the position by the appropriate amount.