Difference between revisions of "Lua:Class:FileStream"
Jump to navigation
Jump to search
(Initial page creation.) |
m (Syntax Highlighting.) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | {{ | + | {{Class|'''class''' FileStream ''':''' HandleStream}} |
The FileStream class represents a stream backed by a file on disk. | The FileStream class represents a stream backed by a file on disk. | ||
| Line 107: | Line 107: | ||
===Examples=== | ===Examples=== | ||
| − | < | + | <syntaxhighlight lang="lua" line> |
local stream = createFileStream("C:\\\\Temp\\\\example.bin", fmCreate) | local stream = createFileStream("C:\\\\Temp\\\\example.bin", fmCreate) | ||
| Line 115: | Line 115: | ||
stream.destroy() | stream.destroy() | ||
| − | </ | + | </syntaxhighlight> |
| − | < | + | <syntaxhighlight lang="lua" line> |
local mode = fmOpenReadWrite | fmShareDenyNone | local mode = fmOpenReadWrite | fmShareDenyNone | ||
local stream = createFileStream("C:\\\\Temp\\\\example.bin", mode) | local stream = createFileStream("C:\\\\Temp\\\\example.bin", mode) | ||
| Line 124: | Line 124: | ||
stream.destroy() | stream.destroy() | ||
| − | </ | + | </syntaxhighlight> |
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
Latest revision as of 19:21, 25 June 2026
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.
Contents
Inheritance[edit]
| 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[edit]
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[edit]
| 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[edit]
FileStream — The created FileStream object.
File Open Modes[edit]
| 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[edit]
| 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[edit]
This class has no documented properties.
Methods[edit]
This class has no documented methods beyond the inherited stream methods.
Examples[edit]
1 local stream = createFileStream("C:\\\\Temp\\\\example.bin", fmCreate)
2
3 stream.writeByte(0x41)
4 stream.writeByte(0x42)
5 stream.writeByte(0x43)
6
7 stream.destroy()
1 local mode = fmOpenReadWrite | fmShareDenyNone
2 local stream = createFileStream("C:\\\\Temp\\\\example.bin", mode)
3
4 print("FileStream: " .. tostring(stream))
5
6 stream.destroy()