-
Notifications
You must be signed in to change notification settings - Fork 12
61 gzio
Package gzio
could be loaded via the standalone binary, or in Lua with
require("aprilann.gzio)
.
NOTE that io.open
is overwritten by APRIL-ANN to automatically open gzipped files by using gzio
class, if the filename has .gz
extension.
The gzio
class is compatible with standard Lua file
. See Lua documentation for more details
-
obj = gzio.open(path,mode="r")
constructs the object and opens the given path using the given mode. -
obj = io.open(path,mode="r")
opens the given path using the given mode, and returns agzio
object if the file has.gz
extension, otherwise it returns a Luafile
. -
obj:close()
closes the file. -
obj:flush()
flushes the file. -
position = obj:seek(whence="cur",offset=0)
moves the cursor from the given base positionwhence
plus the givenoffset
. Thewhence
could be "cur" or "set", the "end" value is forbidden in ZLib. It returns the position of the cursor at the file. -
value,... = obj:read(format="*l", ...)
reads a sequence of values from the file, following the given format strings.- "*l" reads a line.
- "*n" reads a number.
- "*a" reads the whole file.
- NUMBER reads a string with a maximum of NUMBER bytes.
-
obj:write(value, ...)
write the given sequence of values to the file. A valid value is astring
or anumber
. -
iterator = obj:lines(...)
returns an iterator which read by lines following the given values, by default "*l". The file is not closed at end. -
iterator = io.lines(path, ..)
returns an iterator which traverse the given path by lines, following the given values, by default "*l". Read Lua documentation for details. This function usesgzio
object if the file has.gz
extension, otherwise it uses the standardio.lines
.