Skip to content

File

class File

Base class for a file in a FileSystem.

Functions

Name Description
~File Default destructor.
GetPath Gets the path to the file in the loaded FileSystem.
Read8 Reads a single byte from the file in an AmUInt8.
Read16 Reads two bytes from the file in an AmUInt16.
Read32 Reads four bytes from the file in an AmUInt32.
Read64 Reads eight bytes from the file in an AmUInt64.
ReadString Reads a string from the file.
Write8 Writes a single byte to the file from an AmUInt8.
Write16 Writes two bytes to the file from an AmUInt16.
Write32 Writes four bytes to the file from an AmUInt32.
Write64 Writes eight bytes to the file from an AmUInt64.
WriteString Writes a string to the file.
Eof Checks if the read cursor is at the end of the file.
Read Reads data from the file.
Write Writes data to the file.
Length Gets the size of the file in bytes.
Seek Seeks the read/write to the specified offset.
Seek Seeks the read/write to the specified offset, starting at the given origin.
Position Gets the current position of the read/write cursor.
GetPtr Gets the pointer to the internal file handle.
IsValid Checks if the file is valid.

Function Details

Eof

virtual bool Eof() = 0

Checks if the read cursor is at the end of the file.

Return
true if the read cursor is at the end of the file, false otherwise.

GetPath

[[nodiscard]] virtual AmOsString GetPath() const = 0

Gets the path to the file in the loaded FileSystem.

Return
The path to the file.

GetPtr

virtual AmVoidPtr GetPtr()

Gets the pointer to the internal file handle.

Return
The internal file handle. This depends on the implementation.

IsValid

[[nodiscard]] virtual bool IsValid() const = 0

Checks if the file is valid.

Validity of a file is determined by the underlying implementation. But this should primarily mean that the file exists AND has been opened.

Return
true if the file is valid, false otherwise.

Length

virtual AmSize Length() = 0

Gets the size of the file in bytes.

Return
The size of the file in bytes.

Position

virtual AmSize Position() = 0

Gets the current position of the read/write cursor.

Return
The actual position of the read/write cursor.

Read

virtual AmSize Read(AmUInt8Buffer dst, AmSize bytes) = 0

Reads data from the file.

Parameter dst
The destination buffer of the read data.
Parameter bytes
The number of bytes to read from the file. The destination buffer must be at least as large as the number of bytes to read.
Return
The number of bytes read from the file.

Read16

AmUInt16 Read16()

Reads two bytes from the file in an AmUInt16.

Return
The read value.

Read32

AmUInt32 Read32()

Reads four bytes from the file in an AmUInt32.

Return
The read value.

Read64

AmUInt64 Read64()

Reads eight bytes from the file in an AmUInt64.

Return
The read value.

Read8

AmUInt8 Read8()

Reads a single byte from the file in an AmUInt8.

Return
The read value.

ReadString

AmString ReadString()

Reads a string from the file.

Return
The read value.

Seek

void Seek(AmSize offset)

Seeks the read/write to the specified offset.

Parameter offset
The offset in bytes from the beginning of the file.

virtual void Seek(AmInt64 offset, eFileSeekOrigin origin) = 0

Seeks the read/write to the specified offset, starting at the given origin.

Parameter offset
The offset in bytes from the beginning of the file.
Parameter origin
The origin from which to begin seeking.

Write

virtual AmSize Write(AmConstUInt8Buffer src, AmSize bytes) = 0

Writes data to the file.

Parameter src
The source buffer of the data to write.
Parameter bytes
The number of bytes to write to the file. The source buffer must be at least as large as the number of bytes to write.
Return
The number of bytes written to the file.

Write16

AmSize Write16(AmUInt16 value)

Writes two bytes to the file from an AmUInt16.

Parameter value
The value to write.

Write32

AmSize Write32(AmUInt32 value)

Writes four bytes to the file from an AmUInt32.

Parameter value
The value to write.

Write64

AmSize Write64(AmUInt64 value)

Writes eight bytes to the file from an AmUInt64.

Parameter value
The value to write.

Write8

AmSize Write8(AmUInt8 value)

Writes a single byte to the file from an AmUInt8.

Parameter value
The value to write.

WriteString

AmSize WriteString(const AmString& value)

Writes a string to the file.

Parameter value
The value to write.

~File

virtual ~File() = default

Default destructor.