Lua:Class:FileStream

From Cheat Engine
Jump to navigation Jump to search
<> Function

class FileStream : HandleStream

The FileStream class represents a stream backed by a file on disk.

A FileStream inherits from HandleStream, Stream, and Object. It can be created with createFileStream and is used to read from or write to files.

Inheritance

Class Inherits From Description
FileStream HandleStream A stream object backed by a file on disk.
HandleStream Stream Base class for streams that use a handle.
Stream Object Base class for stream objects.

Creation

<> Function

function createFileStream(filename, mode) : FileStream

Creates a FileStream object for the specified file.

The mode parameter controls how the file is opened or created. File open modes can be combined with file sharing modes using a bitwise or operation.

Function Parameters

Parameter Type Description
filename String The path to the file to open or create.
mode Integer The file open mode. This can be combined with a file sharing mode.

Returns

FileStream — The created FileStream object.

File Open Modes

Constant Value Description
fmCreate 0xff00 Creates a new file. If the file already exists, it is overwritten.
fmOpenRead Integer Opens the file for reading.
fmOpenWrite Integer Opens the file for writing.
fmOpenReadWrite Integer Opens the file for both reading and writing.

File Sharing Modes

Constant Value Description
fmShareCompat 0x0000 Uses compatibility sharing mode.
fmShareExclusive 0x0010 Prevents other processes from opening the file.
fmShareDenyWrite 0x0020 Prevents other processes from opening the file for writing.
fmShareDenyRead 0x0030 Prevents other processes from opening the file for reading.
fmShareDenyNone 0x0040 Allows other processes to open the file for reading or writing.

Properties

This class has no documented properties.

Methods

This class has no documented methods beyond the inherited stream methods.

Examples

local stream = createFileStream("C:\\\\Temp\\\\example.bin", fmCreate)

stream.writeByte(0x41)
stream.writeByte(0x42)
stream.writeByte(0x43)

stream.destroy()
local mode = fmOpenReadWrite | fmShareDenyNone
local stream = createFileStream("C:\\\\Temp\\\\example.bin", mode)

print("FileStream: " .. tostring(stream))

stream.destroy()

See also

Lua
Script Engine