beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / luazlib / gzip.lua
blobd7b0db4a0e062bde38ca138d98abb1958afdfcb6
1 --[[------------------------------------------------------------------------
2 gzip.lua
3 support code for zlib library version 1.2.1 - gzip extentions
4 usage lua -lgzip ...
6 Author: Tiago Dionizio (tngd@mega.ist.utl.pt)
7 $Id: gzip.lua,v 1.3 2004/07/22 19:11:55 tngd Exp $
8 --]]------------------------------------------------------------------------
11 --[[------------------------------------------------------------------------
13 After loading the module a table with the following interface should be
14 available:
16 gzip.open(filename [, mode])
18 Opens a file name using "gzopen". Behaviour is identical to the description
19 given in the zlib library. If mode is not given a default mode "rb" will be
20 used. Mode is the same as interpreted by gzopen function, ie, it can
21 include special modes such as characters 1 to 9 that will be treated as the
22 compression level when opening a file for writing.
24 It returns a new file handle, or, in case of errors, nil plus an error
25 message
27 gzip.lines(filename)
29 Same behaviour as io.lines in the io standard library provided by lua
30 with the aditional feature of working with gzip files. If a normal text
31 file is read it will read it normaly (normal gzopen behaviour).
33 gzip.close(file)
35 Same as file:close, use file:close instead.
37 file:flush()
39 This function takes no parameters and flushes all output to working file.
40 The same as calling 'gzflush(file, Z_FINISH)' so writing to the file will
41 most likely not work as expected. This is subject to change in the future
42 if there is a strong reason for it to happen.
44 file:read(format1, ...)
45 Reads the file file, according to the given formats, which specify what
46 to read. For each format, the function returns a string with the characters
47 read, or nil if it cannot read data with the specified format. When called
48 without formats, it uses a default format that reads the entire next line
49 (see below).
51 The available formats are
53 "*a" reads the whole file, starting at the current position. On end of
54 file, it returns the empty string.
55 "*l" reads the next line (skipping the end of line), returning nil on
56 end of file. This is the default format.
57 number reads a string with up to that number of characters, returning
58 nil on end of file. If number is zero, it reads nothing and
59 returns an empty string, or nil on end of file.
61 Unlink io.read, the "*n" format will not be available.
64 file:lines()
66 Returns an iterator function that, each time it is called, returns a new
67 line from the file. Therefore, the construction
68 for line in file:lines() do ... end
69 will iterate over all lines of the file. (Unlike gzip.lines, this function
70 does not close the file when the loop ends.)
72 file:seek([whence] [, offset])
74 Sets and gets the file position, measured from the beginning of the file,
75 to the position given by offset plus a base specified by the string whence,
76 as follows:
78 "set" base is position 0 (beginning of the file);
79 "cur" base is current position;
81 In case of success, function seek returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error.
82 The default value for whence is "cur", and for offset is 0. Therefore, the call file:seek() returns the current file position, without changing it; the call file:seek("set") sets the position to the beginning of the file (and returns 0); and the call file:seek("end") sets the position to the end of the file, and returns its size.
84 This function is subject to limitations imposed by gzseek function from
85 zlib library, such as the inability to use "end" as the base for seeking
86 and the inability to seek backwards when writing.
88 file:write(value1, ...)
90 Writes the value of each of its arguments to the filehandle file. The
91 arguments must be strings or numbers. To write other values, use tostring
92 or string.format before write
94 file:close()
96 Closes the file.
98 --]]------------------------------------------------------------------------
100 require("requirelib")
102 requirelib("lzlib", "luaopen_gzip", true)