Hello, I'm bringing my new library for Lua which provides functions for reading files, folders, etc.
Documentation 
ByteMax(x)
Returns: The max. value for X bytes
ReadStream(path)
Returns: A stream object used to read a file
WriteStream(path)
Returns: A stream object used to re-write a file
ReadByte(stream)
Description: Reads a byte from a stream (1b)
Returns: A byte number value (0-255)
WriteByte(stream,n)
Description: Writes a byte number value to a stream (0-255)
ReadShort(stream)
Description: Reads two bytes from a stream (2b)
Returns: 2 bytes number value (0-65535)
WriteShort(stream,n)
Description: Writes 2 bytes number value to a stream (0-65535)
ReadInt(stream); ReadFloat(stream)
Description: Reads 4 bytes from a stream (4b)
Returns: 4 bytes value (0 - (256^4-1))
WriteInt(stream,n); WriteFloat(stream,n)
Description: Writes 4 bytes number value to a stream (0-(256^4-1))
ReadLong(stream); ReadDouble(stream)
Description: Reads 8 bytes from a stream (8b)
Returns: 8 bytes number value (0 - (256^8-1))
WriteLong(stream,n); WriteDouble(stream,n)
Description: Writes 8 bytes number value to a stream (0-(256^8-1))
ReadLine(stream)
Description: Reads a line from a stream
Returns: A string containing the read line.
WriteLine(stream,str)
Description: Writes a line to a stream
ReadString(stream,length)
Description: Reads a string from a stream with the specified length
Returns: The read string
WriteString(stream,str)
Description: Writes a string to a stream
Eof(stream)
Description: Tells if you've reached the end of the stream
Returns: True or false
StreamPos(stream)
Returns: The current position of the reading in this stream
StreamSize(stream)
Returns: The number of bytes available to read in this stream
SeekStream(stream,pos)
Description: Changes the reading position in the stream
CloseStream(stream)
Description: Closes a stream (reading or writing streams)
CopyBytes(fromStream,toStream,count)
Description: Reads count amount of bytes from fromStream and writes it to toStream
CreateStream()
Description: Creates a stream object that can be used for your own purposes.
Returns: A stream object
CreateDir(path)
Description: Builds a directory with it's folders
ReadDir(path,readFolders,readFiles)
Description: Reads the files and folders placed in a directory
Returns: A table that contains a list of folders and files from the specified path
CreateRamStream()
Description: Creates a stream that allows you to write data and read it (doesn't create a file)
Returns: A temporal stream object that can read and write data
Example 
CreateRamStream
Code:1
2
3
4
5
6
7
8
stream = CreateRamStream()
WriteByte(stream, 123)
WriteLine(stream, "Hello")
WriteShort(stream, 15239)
print(ReadByte(stream))
print(ReadLine(stream))
print(ReadShort(stream))
ReadStream
Code:1
2
3
4
5
stream = ReadStream("sys/server.cfg")
while not Eof(stream) do
print(ReadLine(stream))
end
CloseStream(stream)
WriteStream
Code:1
2
3
4
stream = WriteStream("sys/servertransfer.lst")
WriteLine(stream, "gfx/sprites/wave.bmp")
CloseStream(stream)
ReadDir
Code:1
2
3
4
filePath = ReadDir("sys")
for i = 1, #filePath do
print(filePath[i])
end
CreateDir
Code:1
CreateDir("gfx/starkkz")
Changelog 

Few bugs and problems reading bytes

Lua Command
CreateRamStream

Operating systems

Windows

Linux
Note: There are two files: one for windows and one for Linux, I've tested the Windows version but not the Linux version yet so if you find any bug then contact me or leave a comment.
Comment & subscribe to my
Facebook page
edited 7×, last 05.08.14 01:55:26 am