File

enum FileSource
case File(java.io.RandomAccessFile)

Represents a RandomAccessFile - a read-only or read-write file with random access.

File does not properly support Unicode and uses Java / JVM conventions for representing numbers so it is inadequate for serializing data portably.

Instances

instance Reader[File]Source

Definitions

def close!(f: File): Result[IOError, Unit] \ IO Source

Close a file.

def length(f: File): Result[IOError, Int64] \ IO Source

Returns the number of bytes in the file.

def open(path: String, mode: Mode): Result[IOError, File] \ IO Source

Opens a file. path should represent a valid path string. See the Mode enum for an explanation of the available access modes. If the file does not exist, but it open is acalled with a write mode the system will try to make a new file (the attempt may fail due to permissions, IO errors, etc.).

def read!(buf: Array[Int8, r], f: File): Result[IOError, Int32] \ IO + r Source

Read up to Array.length(buf) bytes from the file f. This function blocks until at least one byte of data is available.

def readBool!(f: File): Result[IOError, Bool] \ IO Source

Read a Bool from the file f. The Bool is represented as a single byte.

Reading byte value of 0x00 produces false. Reading any other value produces true.

def readByte!(f: File): Result[IOError, Int32] \ IO Source

Read an unsigned single byte from the file f.

The byte is represented as an Int32, the value returned will be in the range: 0x00 => 0 ... 0xFF => 255

def readChar!(f: File): Result[IOError, Char] \ IO Source

Read a Char value from file f stored in Java's 2-byte Char representation.

This function blocks until the two bytes are read or an exception otherwise occurs.

def readFloat32!(f: File): Result[IOError, Float32] \ IO Source

Read a Float32 value from file f stored in Java's big-endian 4-byte Float representation.

Internally d is read as an 4-byte Int32 then converted to a Float32.

def readFloat64!(f: File): Result[IOError, Float64] \ IO Source

Read a floating point value from file f stored in Java's big-endian 8-byte Float representation.

Internally d is read as an 8-byte Int64 then converted to a Float64.

def readFully!(buf: Array[Int8, r], f: File): Result[IOError, Unit] \ IO + r Source

Reads Array.length(buf) bytes from the file f. This function blocks until the requested length of data is available.

def readFullyWith!(destOffset: { destOffset = Int32 }, length: { length = Int32 }, buf: Array[Int8, r], f: File): Result[IOError, Unit] \ IO + r Source

Reads length#length bytes from the file f, the bytes are written to the array buf at the offset destOffset. This function blocks until the requested length of data is available.

def readInt16!(f: File): Result[IOError, Int16] \ IO Source

Read a Int16 value from file f stored in Java's big-endian 2-byte Short representation.

This function blocks until the two bytes are read or an exception otherwise occurs.

def readInt32!(f: File): Result[IOError, Int32] \ IO Source

Read a Int32 value from file f stored in Java's big-endian 4-byte Int representation.

This function blocks until the four bytes are read or an exception otherwise occurs.

def readInt64!(f: File): Result[IOError, Int64] \ IO Source

Read a Int64 value from file f stored in Java's big-endian 8-byte Long representation.

This function blocks until the eight bytes are read or an exception otherwise occurs.

def readInt8!(f: File): Result[IOError, Int8] \ IO Source

Read a signed Int8 value from file f stored as a single byte.

def readLine!(f: File): Result[IOError, String] \ IO Source

Read a line of text from the file f.

This function does not support the full Unicode character set.

def readModifiedUTF!(f: File): Result[IOError, String] \ IO Source

Read a length prefixed, "modified" UTF8 string from the file f. The length is derived from the first two bytes which are treated as an unsigned short.

The modifications are: Null ('\u0000') is written as two bytes rather than one. Character ranges are represented by 1, 2, or 3 byte formats. Supplementary characters are represented as surrogate pairs.

def readUnsignedByte!(f: File): Result[IOError, Int32] \ IO Source

Read an unsigned byte value from file f stored as a single byte.

The answer is widened to an Int32 because so it can contain values in the range 128..255.

def readUnsignedShort!(f: File): Result[IOError, Int32] \ IO Source

Read a unsigned two byte (short) value from file f.

This function blocks until the two bytes are read or an exception otherwise occurs.

def readWith!(destOffset: { destOffset = Int32 }, length: { length = Int32 }, buf: Array[Int8, r], f: File): Result[IOError, Int32] \ IO + r Source

Read up to length#length bytes from the file f, the bytes are written to the array buf at the offset destOffset. This function blocks until at least one byte of data is available.

def seek!(pos: Int64, f: File): Result[IOError, Unit] \ IO Source

Move the file pointer position to pos measured in bytes from the start of the file.

def setLength!(len: Int64, f: File): Result[IOError, Unit] \ IO Source

Set the length of the file f to len. If len is smaller than the length of the file then the file will be truncated. If len is greater than the length of the file then the file will be extended. In the case of the file being extended, how the new section of the file is filled is not defined and is dependent on the implementation.

def size(f: File): Result[IOError, Int64] \ IO Source

Returns the number of bytes in the file.

def skipBytes!(n: Int32, f: File): Result[IOError, Int32] \ IO Source

Skip over n bytes in a file. The number returned may be smaller than n if the end of file is reached. If n is negative no bytes are skipped.

def write!(buf: Array[Int8, r], f: File): Result[IOError, Unit] \ IO + r Source

Write to Array.length(buf) bytes to the file f starting at the current position of the file pointer.

def writeAsByte!(i: Int32, f: File): Result[IOError, Unit] \ IO Source

Write the byte value i (represented as an Int32) to the file f at the current file pointer position. i is written as a single byte.

def writeAsChar!(c: Int32, f: File): Result[IOError, Unit] \ IO Source

Write the char value c (represented as an Int32) to the file f at the current file pointer position. The char is written as two bytes with the high byte first (big endian).

def writeAsShort!(i: Int32, f: File): Result[IOError, Unit] \ IO Source

Write the short value i (represented as an Int32) to the file f at the current file pointer position. The short is written as two bytes with the high byte first (big endian).

def writeBool!(b: Bool, f: File): Result[IOError, Unit] \ IO Source

Write the Bool value b to the file f at the current file pointer position. The Bool is represented as a single byte.

0x00 is written for false. 0x01 is written for true.

def writeFloat32!(d: Float32, f: File): Result[IOError, Unit] \ IO Source

Write the floating point value d to file f using Java's 4-byte Float representation.

Internally d is first converted to a Int32 than written to file with the high byte first.

def writeFloat64!(d: Float64, f: File): Result[IOError, Unit] \ IO Source

Write the floating point value d to file f using Java's 8-byte Double representation.

Internally d is first converted to a Int64 than written to file with the high byte first.

def writeInt32!(i: Int32, f: File): Result[IOError, Unit] \ IO Source

Write the Int32 value i to the file f at the current file pointer position. The Int32 is written as four bytes with the high byte first (big endian).

def writeInt64!(i: Int64, f: File): Result[IOError, Unit] \ IO Source

Write the Int64 value i to the file f at the current file pointer position. The Int64 is written as eight bytes with the high byte first (big endian).

def writeModifiedUTF!(s: String, f: File): Result[IOError, Unit] \ IO Source

Read a length prefixed, "modified" UTF8 string. The length is written to the first two bytes using the same encoding as an unsigned short.

The modifications follow the rules used by readString.

def writeWith!(sourceOffset: { sourceOffset = Int32 }, length: { length = Int32 }, buf: Array[Int8, r], f: File): Result[IOError, Unit] \ IO + r Source

Write to length#length bytes to the file f, the bytes are read from the array buf starting at sourceOffset#sourceOffset.