-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.txt
More file actions
127 lines (94 loc) · 4.21 KB
/
README.txt
File metadata and controls
127 lines (94 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
lua-miniz - Lua module for miniz support
This module add deflate/inflate and zip file operations support to Lua
language. some code from luvit's miniz module, thanks for that work!
license:
This module has the same license with Lua (the Lua license here[1]).
note that the modified version of miniz.c has its own license (see miniz.c file).
[1]: https://www.lua.org/license.html
build:
use your fabourite compiler to build lminiz.c and miniz.c, get miniz.dll
or miniz.so
usage:
local miniz = require "miniz"
functions:
miniz.adler32([string[, prev: number]]) -> number
miniz.crc32([string[, prev: number]]) -> number
calculate adler32 and crc32 checksum for string. without arguments, give a
initialize checksum.
local a = miniz.crc32("hello")
local b = miniz.crc32("world", a)
-- a is the checksum of "hello", and b is the checksum of "helloworld"
miniz.compress(string[, level: number[, window_size: number]]) -> [string]
miniz.decompress(string[, window_bits: number]) -> [string]
compress/decompress string, use given flags.
when window_size and window_bits are negature, the compress result will
not include a zlib-compatible header.
miniz.compress([level: number[, window_size: number]]) -> [stream]
miniz.decompress([window_bits: number]) -> [stream]
create a new compress/decompress stream,
when compress:
output, eof, input_bytes, output_bytes = stream(string[, flush])
where flush are "sync", "full" or "finish"
when decompress:
output, eof, input_bytes, output_bytes = stream(string)
same as lua-zlib module.
miniz.zip_read_file(filename: string[, flags: number]) -> [miniz.ZipReader]
miniz.zip_read_string(content: string[, flags: number]) -> [miniz.ZipReader]
read a zip from file (given filename) or content string.
flags: (from miniz.c)
0x100: case sensitive file name in zip file.
0x200: ignore path of file in zip.
0x400: file is compressed data.
0x800: do not sort central directory in zip file.
miniz.zip_write_file(filename: string[, reserved: number]) -> miniz.ZipWriter
miniz.zip_write_string([reserved: number[, init_size: number]]) -> miniz.ZipWriter
write files to a zip file or a string.
reserved is the reserved size before zip file itself. init_size is the
first allocated memory for write file content.
#ZipReader -> number
ZipReader:get_num_files() -> number
get the file count in zip file.
ZipReader[idx:number] -> string
ZipReader:get_filename(idx:number) -> string
get the idx-th file name in zip file.
ZipReader:close() -> boolean
close zip file, return success or not.
ZipReader:locate_file(filename: string) -> number
get the index from file name
ZipReader:stat(idx: number) -> table
get file information from given index.
returned table fields:
index: index of file
version_made_by: zip version
version_needed: extract file need version
bit_flag: flags of file
method: compress method
time: file time
crc32: file crc32 checksum
comp_size: compressed size
uncomp_size: uncompressed size
internal_attr: internal attribute
external_attr: external attribute
filename: filename
comment: comment
ZipReader:is_file_a_directory(idx: number) -> boolean
return whether given idx of file is a directory.
ZipReader:get_offset() -> number
get the start offset of zip file in given file/string.
ZipReader:extract(idx: number[, flags: number]) -> [string]
ZipReader:extract(filename: string[, flags: number]) -> [string]
extract a file from zip. flags see miniz.zip_read_file()
ZipWriter:close() -> boolean
close a zip file
ZipWriter:add_string(path: string, content: string[, comment: string[, flags: number]]) -> ZipWriter
ZipWriter:add_file(path: string, filename: string[, comment: string[, flags: number]]) -> ZipWriter
add a file to zip.
ZipWriter:add_from_zip_reader(src: miniz.ZipReader, idx: number) -> ZipWriter
add a file from zip reader to zip.
ZipWriter:finalize() -> string
ZipWriter:finalize() -> ZipWriter
ZipWriter:finalize() -> nil, string
finalize the write of zip. if zip writer is created from zip_write_string,
then the result string is returned; if zip writer is created from
zip_write_file, then ZipWriter itself is returned, otherwire a nil and a
error message is returned.