Skip to content
Paco Zamora Martinez edited this page Jul 3, 2014 · 4 revisions

Introduction

Package gzio could be loaded via the standalone binary, or in Lua with require("aprilann.gzio).

gzio class, GZip files

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 a gzio object if the file has .gz extension, otherwise it returns a Lua file.

  • obj:close() closes the file.

  • obj:flush() flushes the file.

  • position = obj:seek(whence="cur",offset=0) moves the cursor from the given base position whence plus the given offset. The whence 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 a string or a number.

  • 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 uses gzio object if the file has .gz extension, otherwise it uses the standard io.lines.

tar class, TAR files

Clone this wiki locally