Garry's Mod Wiki

File

You might be looking for the "file" Library, which has the same name as this class.

This is the file object. It used used primarily to read or write binary data from files.
The default endianness is little-endian. To use big-endian you will need to provide your own functions to read and write shorts and longs.

The object is returned by file.Open.

Methods

File:Close()
Dumps the file changes to disk and closes the file handle which makes the handle useless.
Returns whether the File object has reached the end of file or not.
File:Flush()
Dumps the file changes to disk and saves the file.
string File:Read( number length = nil )
Reads the specified amount of chars and returns them as a binary string.
Reads one byte of the file and returns whether that byte was not 0.
Reads one unsigned 8-bit integer from the file.
Reads an 8-byte little-endian IEEE-754 floating point double from the file.
Reads an IEEE 754 little-endian 4-byte float from the file.
Returns the contents of the file from the current position up until the end of the current line. This function will look specifically for Line Feed characters \n and will completely ignore Carriage Return characters \r. This function will not return more than 8192 characters. The return value will include the \n character.
Reads a signed little-endian 32-bit integer from the file.
Reads a signed little-endian 16-bit integer from the file.
Reads an unsigned 64-bit integer from the file.
Reads an unsigned little-endian 32-bit integer from the file.
Reads an unsigned little-endian 16-bit integer from the file.
File:Seek( number pos )
Sets the file pointer to the specified position.
number File:Size()
Returns the size of the file in bytes.
number File:Skip( number amount )
Moves the file pointer by the specified amount of chars.
number File:Tell()
Returns the current position of the file pointer.
File:Write( string data )
Writes the given string into the file.
File:WriteBool( boolean bool )
Writes a boolean value to the file as one byte.
File:WriteByte( number uint8 )
Write an 8-bit unsigned integer to the file.
File:WriteDouble( number double )
Writes an 8-byte little-endian IEEE-754 floating point double to the file.
File:WriteFloat( number float )
Writes an IEEE 754 little-endian 4-byte float to the file.
File:WriteLong( number int32 )
Writes a signed little-endian 32-bit integer to the file.
File:WriteShort( number int16 )
Writes a signed little-endian 16-bit integer to the file.
File:WriteUInt64( string uint64 )
Writes an unsigned 64-bit integer to the file.
File:WriteULong( number uint32 )
Writes an unsigned little-endian 32-bit integer to the file.
File:WriteUShort( number uint16 )
Writes an unsigned little-endian 16-bit integer to the file.