├── .gitignore ├── .npmignore ├── .travis.yml ├── benchmark ├── benchmark_ifile.js ├── benchmark_ifile_gzip.js ├── benchmark_node.js ├── benchmark_node_gzip.js └── static │ └── jquery.1.7.1.js ├── binding.gyp ├── index.js ├── lib └── ifile.js ├── package.json ├── readme.md ├── src ├── gzip.cpp ├── gzip.h ├── ifile.cpp ├── ifile_class.cpp ├── ifile_class.h ├── ifile_handler.h ├── mime.h ├── request.h └── zlib │ ├── LICENSE │ ├── README.chromium │ ├── adler32.c │ ├── compress.c │ ├── contrib │ └── minizip │ │ ├── ChangeLogUnzip │ │ ├── Makefile │ │ ├── crypt.h │ │ ├── ioapi.c │ │ ├── ioapi.h │ │ ├── iowin32.c │ │ ├── iowin32.h │ │ ├── miniunz.c │ │ ├── minizip.c │ │ ├── mztools.c │ │ ├── mztools.h │ │ ├── unzip.c │ │ ├── unzip.h │ │ ├── zip.c │ │ └── zip.h │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── gzio.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── mozzconf.h │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.gyp │ ├── zlib.h │ ├── zutil.c │ └── zutil.h ├── test.js ├── test ├── Static │ ├── Mount_Huangshan.jpg │ └── Mount_Huangshan2.jpg ├── build │ └── config.gypi ├── main.js ├── pipe.js └── static2 │ ├── static2 │ ├── aaa.js │ ├── test.css │ └── test.js │ └── static3 │ └── static3 │ ├── test.css │ ├── test.txt │ ├── test.xml │ ├── test2.css │ ├── test2.xml │ └── test3.xml └── vendor.yml /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .git 3 | node_modules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | threads_a_gogo.node 2 | build 3 | .lock-wscript 4 | .git 5 | node_modules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" -------------------------------------------------------------------------------- /benchmark/benchmark_ifile.js: -------------------------------------------------------------------------------- 1 | var times = 1000 2 | var count = times; 3 | 4 | var ifile = require("../index.js"); 5 | 6 | ifile.add([ 7 | ["/static/",__dirname], 8 | ],function(req,res){ 9 | throw(404) 10 | //console.log('404') 11 | }) 12 | 13 | var req= { 14 | url:'/static/jquery.1.7.1.js', 15 | method:'GET', 16 | headers:{} 17 | } 18 | 19 | var res = { 20 | end:function(buf){ 21 | var jquery = buf.toString(); 22 | //console.log(jquery) 23 | if(!--count){ 24 | console.timeEnd('ifile'); 25 | } 26 | }, 27 | statusCode:200, 28 | setHeader:function(name,val){} 29 | } 30 | console.time('ifile'); 31 | for(var i=0;i=gzip_size? 1 : 0; 38 | 39 | var raw = fs.createReadStream(filepath); 40 | 41 | res.setHeader("Transfer-Encoding", "chunked"); 42 | res.removeHeader("Cotent-Length"); 43 | if(is_gzip){ 44 | res.setHeader("Content-Encoding", "gzip") 45 | raw.pipe(zlib.createGzip()).pipe(res); 46 | } 47 | else raw.pipe(res); 48 | 49 | } 50 | 51 | 52 | ifile_obj.add = function(static_array, not_found_callback){ 53 | var that = this; 54 | 55 | static_array.forEach(function(v,i){ 56 | 57 | if('object' !== typeof v || v.length <2 || v.length >3 ){ 58 | throw(ADD_ERROR); 59 | } 60 | if('string' !== typeof v[0] || 'string' !== typeof v[1] || v[0].length<1 || v[1].length<1){ 61 | throw(ADD_ERROR2); 62 | } 63 | 64 | v[2] = 'undefined' === typeof v[2] ? 0 : v[2]; 65 | 66 | if(0 !== v[2] && 'object' !== typeof v[2]){ 67 | throw(ADD_ERROR) 68 | } 69 | 70 | var s_uri = v[0]; 71 | var s_dir = v[1]; 72 | var array_suffix = v[2]; 73 | s_uri = s_uri //.toLowerCase(); 74 | s_dir = s_dir //.toLowerCase(); 75 | 76 | 77 | 78 | if(s_uri[0] !== '/') s_uri = '/'+s_uri; 79 | var last_po = s_uri.length-1; 80 | if(s_uri[last_po] !== '/') s_uri += '/'; 81 | 82 | if(s_dir[0] !== '/' && !/^[a-zA-Z][:]+/.test(s_dir)){ 83 | 84 | var file_array = module.parent.parent.filename.split(path.sep); 85 | var dirname = file_array.slice(0, file_array.length-1).join(path.sep); 86 | 87 | s_dir = dirname + path.sep + s_dir; 88 | } 89 | var last_po_2 = s_dir.length-1; 90 | if(s_dir[last_po_2] === path.sep) s_dir = s_dir.slice(0, last_po_2-1); 91 | 92 | 93 | if(array_suffix === 0 || array_suffix.length === 0){ 94 | array_suffix = 0; 95 | } 96 | else{ 97 | 98 | array_suffix.map(function(v){ 99 | 100 | if(!/^[a-zA-z0-9]+/.test(v)) throw(ADD_ERROR3) 101 | return v //.toLowerCase(); 102 | }) 103 | } 104 | 105 | static_uri_array.push(s_uri); 106 | static_dir_array.push(s_dir); 107 | static_suffix_array.push(array_suffix) 108 | }); 109 | 110 | 111 | default_callback = not_found_callback || default_callback; 112 | if('function' !== typeof default_callback){ 113 | throw(ADD_ERROR2); 114 | } 115 | 116 | if(static_uri_array.length !== static_dir_array.length || static_dir_array.length !== static_suffix_array.length){ 117 | 118 | console.log(static_uri_array) 119 | console.log(static_dir_array) 120 | console.log(static_suffix_array) 121 | throw('static_uri_array static_dir_array static_suffix_array length error!') 122 | } 123 | 124 | 125 | if(!ifile_obj.options) ifile_obj.options = {} 126 | 127 | 128 | ifile_obj.options.pipe_szie = ifile_obj.options.pipe_szie || ifile_obj.default_options.pipe_szie; 129 | 130 | ifile_obj.options.expired = ifile_obj.options.expired || ifile_obj.default_options.expired; 131 | 132 | ifile_obj.options.gzip = ifile_obj.options.gzip || ifile_obj.default_options.gzip; 133 | 134 | ifile_obj.options.gzip_min_size = ifile_obj.options.gzip_min_size || ifile_obj.default_options.gzip_min_size; 135 | 136 | ifile_obj.options.gzip_file = ifile_obj.options.gzip_file || ifile_obj.default_options.gzip_file; 137 | 138 | ifile_obj.options.gzip_level = ifile_obj.options.gzip_level || ifile_obj.default_options.gzip_level; 139 | 140 | ifile_obj.options._ifile_obj = ifile_obj; 141 | 142 | 143 | ifile_obj.options.expired = "max-age="+(ifile_obj.options.expired/1000); 144 | 145 | ifile_obj.options.gzip = ifile_obj.options.gzip ? 1 : 0; 146 | 147 | 148 | 149 | ifile_cc.add(static_uri_array, static_dir_array, static_suffix_array, default_callback, ifile_obj.options); 150 | 151 | 152 | } 153 | 154 | 155 | ifile_obj.route = ifile_cc.match; 156 | 157 | 158 | 159 | var add_mime = function(){ 160 | 161 | var len = Object.keys(mime.types).length; 162 | var types = mime.types; 163 | var types_keys = Object.keys(mime.types); 164 | var mime_name_array = []; 165 | var mime_type_array = []; 166 | for(var i=0;i=0.10.0" 28 | }, 29 | "dependencies":{ 30 | "mime":"1.2.6" 31 | }, 32 | "scripts": { 33 | "install": "node-gyp rebuild", 34 | "tset":"node ./test/main.js" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ifile(fast and simple nodejs http/https static file module)[![Build Status](https://travis-ci.org/DoubleSpout/ifile.png?branch=master)](https://travis-ci.org/DoubleSpout/ifile) 2 | 3 | ifile is a simple static http/https handler module, build with libuv and c++. 4 | 5 | the module are also be used in express and flat.js framework. 6 | 7 | ## Installing the module 8 | 9 | With [npm](http://npmjs.org/): 10 | 11 | ifile module is supported windows, linux, mac. 12 | 13 | Make sure, node-gyp has installed. 14 | 15 | npm install ifile 16 | 17 | From source: 18 | 19 | git clone https://github.com/DoubleSpout/ifile.git 20 | cd ifile 21 | node-gyp rebuild 22 | 23 | To include the module in your project: 24 | 25 | var ifile = require('ifile'); 26 | 27 | ##benchmark 28 | send the same js file, 6KB size. 29 | 30 | nginx 31 | ab -c 100 -n 20000 http://192.168.28.5:8124/js/test.js 32 | Requests per second: 2634.31 [#/sec] (mean) 33 | 34 | ab -c 500 -n 20000 http://192.168.28.5:8124/js/test.js 35 | Requests per second: 1886.92 [#/sec] (mean) 36 | 37 | ab -c 800 -n 20000 http://192.168.28.5:8124/js/test.js 38 | Requests per second: 2033.45 [#/sec] (mean) 39 | 40 | ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8124/js/test.js 41 | Requests per second: 2029.59 [#/sec] (mean) 42 | 43 | 44 | ifile 45 | ab -c 100 -n 20000 http://192.168.28.5:8125/js/test.js 46 | Requests per second: 2077.29 [#/sec] (mean) 47 | 48 | ab -c 500 -n 20000 http://192.168.28.5:8125/js/test.js 49 | Requests per second: 1880.00 [#/sec] (mean) 50 | 51 | ab -c 800 -n 20000 http://192.168.28.5:8125/js/test.js 52 | Requests per second: 1791.16 [#/sec] (mean) 53 | 54 | ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8125/js/test.js 55 | Requests per second: 1858.01 [#/sec] (mean) 56 | 57 | 58 | express 59 | ab -c 100 -n 20000 http://192.168.28.5:8126/js/test.js 60 | Requests per second: 915.21 [#/sec] (mean) 61 | 62 | ab -c 500 -n 20000 http://192.168.28.5:8126/js/test.js 63 | Requests per second: 858.89 [#/sec] (mean) 64 | 65 | ab -c 800 -n 20000 http://192.168.28.5:8126/js/test.js 66 | Requests per second: 668.99 [#/sec] (mean) 67 | 68 | ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8126/js/test.js 69 | Requests per second: 677.11 [#/sec] (mean) 70 | 71 | 72 | 73 | express+ifile 74 | ab -c 100 -n 20000 http://192.168.28.5:8127/js/test.js 75 | Requests per second: 1684.85 [#/sec] (mean) 76 | 77 | ab -c 500 -n 20000 http://192.168.28.5:8127/js/test.js 78 | Requests per second: 1717.32 [#/sec] (mean) 79 | 80 | ab -c 800 -n 20000 http://192.168.28.5:8127/js/test.js 81 | Requests per second: 1399.09 [#/sec] (mean) 82 | 83 | ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8127/js/test.js 84 | Requests per second: 1468.06 [#/sec] (mean) 85 | 86 | 87 | ## example 88 | 89 | var ifile = require('ifile') 90 | 91 | var http = require('http') 92 | 93 | ifile.add([ 94 | 95 | ["/static",__dirname,['js','css','jpg']], 96 | 97 | ],function(req,res,is_static){ 98 | 99 | res.statusCode = 404; 100 | 101 | res.end('404') 102 | 103 | }) 104 | 105 | var http = require('http'); 106 | 107 | http.createServer(function (req, res) { 108 | 109 | ifile.route(req,res); 110 | 111 | }).listen(8124); 112 | 113 | then request the 127.0.0.1:8124/static/xxx.js 114 | 115 | if you have a file in __dirname/static/xxx.js then you will see it. 116 | 117 | ##API 118 | 119 | ifile.add(routearray,not_match_callback); 120 | 121 | ifile.route(req,res); 122 | route the request 123 | 124 | routearray: 125 | 126 | [ 127 | [request_url_prefix, static_folder [,support_extensions_array]], 128 | ... 129 | ] 130 | 131 | example: 132 | 133 | [ 134 | ["/static",__dirname,['js','css','jpg']], 135 | ["/static2",__dirname], 136 | ["/skin","static",['js','css','jpg']] //static folder will be __dirname+'/'+static 137 | ] 138 | 139 | not_match_function: 140 | if ifile not match the request,the not_match_function will be called.It has three parameters,req, res and is_static. 141 | for example if add ["/static2",__dirname] 142 | 1,request "/user/aaa" will call the not_match_function,and is_static param will be 0; 143 | 2,request "/static/not_exist_file" will call the not_match_function,and is_static param will be 1; 144 | 145 | ##options 146 | set ifile.options property to change the default options,for example: 147 | 148 | var ifile = require('ifile'); 149 | ifile.options = { 150 | expired:86400*100*30, 151 | gzip:false 152 | } 153 | 154 | default options is that: 155 | 156 | default_options = { 157 | pipe_szie : 1024*1024*20, //超过20MB的静态文件使用pipe传输不读入内存 158 | expired : 86400*1000, //cache-control : max-age=86400 159 | gzip : true, //是否开启gzip 160 | gzip_min_size : 1024, //开启gzip的文件必须大于等于1024byte 161 | gzip_file : ['js','css','less','html','xhtml','htm','xml','json','txt'], //gzip压缩的文件后缀名 162 | gzip_level : 9, //-1表示使用默认值 163 | } 164 | 165 | more example see /test/main.js 166 | 167 | ##expressjs example 168 | 169 | var express = require('express'); 170 | var app = express(); 171 | var ifile = require("ifile"); 172 | app.use(ifile.connect()); 173 | //default is [['/static',__dirname]]; 174 | 175 | app.listen(3000); 176 | 177 | -------------------------------------------------------------------------------- /src/gzip.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include "gzip.h" 6 | #include 7 | #include 8 | #include 9 | 10 | #include "zlib/zlib.h" 11 | 12 | using namespace std; 13 | 14 | int Gzip::gzip_uncompress(char *bufin, int lenin, char *bufout, int lenout){ 15 | 16 | z_stream d_stream; 17 | int result; 18 | 19 | d_stream.zalloc = NULL; 20 | d_stream.zfree = NULL; 21 | d_stream.opaque = NULL; 22 | 23 | result = inflateInit2(&d_stream, MAX_WBITS + 16); 24 | if (result != Z_OK) { 25 | return -1; 26 | } 27 | d_stream.next_in = reinterpret_cast(bufin); 28 | d_stream.avail_in = lenin; 29 | d_stream.next_out = reinterpret_cast(bufout); 30 | d_stream.avail_out = lenout; 31 | 32 | inflate(&d_stream, Z_SYNC_FLUSH); 33 | inflateEnd(&d_stream); 34 | return 0; 35 | 36 | }; 37 | int Gzip::gzip_compress(char *bufin, int lenin, char *bufout, int lenout, int level){ 38 | 39 | z_stream d_stream; 40 | int result; 41 | 42 | d_stream.zalloc = NULL; 43 | d_stream.zfree = NULL; 44 | d_stream.opaque = NULL; 45 | 46 | result = deflateInit2(&d_stream, level, 47 | Z_DEFLATED, MAX_WBITS + 16, 48 | 9, Z_DEFAULT_STRATEGY); 49 | if (result != Z_OK) { 50 | return -1; 51 | } 52 | d_stream.next_in = reinterpret_cast(bufin); 53 | d_stream.avail_in = lenin; 54 | d_stream.next_out = reinterpret_cast(bufout); 55 | d_stream.avail_out = lenout; 56 | 57 | deflate(&d_stream, Z_SYNC_FLUSH); 58 | deflateEnd(&d_stream); 59 | 60 | return d_stream.total_out; 61 | 62 | }; 63 | -------------------------------------------------------------------------------- /src/gzip.h: -------------------------------------------------------------------------------- 1 | #ifndef GZIP_H 2 | #define GZIP_H 3 | #include 4 | #include 5 | #include 6 | #include "zlib/zlib.h" 7 | 8 | using namespace v8; 9 | 10 | class Gzip { 11 | 12 | public: 13 | static int gzip_uncompress(char *bufin, int lenin, char *bufout, int lenout); 14 | static int gzip_compress(char *bufin, int lenin, char *bufout, int lenout, int level=Z_DEFAULT_COMPRESSION); 15 | Gzip(){}; 16 | ~Gzip(){}; 17 | 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /src/ifile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ifile_class.h" 3 | 4 | 5 | 6 | using namespace v8; 7 | 8 | void Init(Handle target) { 9 | 10 | HandleScope scope; 11 | 12 | target->Set(String::NewSymbol("add"), 13 | FunctionTemplate::New(ifile_class::add)->GetFunction()); 14 | 15 | 16 | target->Set(String::NewSymbol("match"), 17 | FunctionTemplate::New(ifile_class::match)->GetFunction()); 18 | 19 | 20 | target->Set(String::NewSymbol("add_mime"), 21 | FunctionTemplate::New(ifile_class::add_mime)->GetFunction()); 22 | 23 | 24 | } 25 | 26 | NODE_MODULE(ifile, Init) -------------------------------------------------------------------------------- /src/ifile_class.h: -------------------------------------------------------------------------------- 1 | #ifndef ROUTE_H 2 | #define ROUTE_H 3 | #include 4 | #include 5 | #include 6 | #include "request.h" 7 | #include "ifile_handler.h" 8 | 9 | using namespace v8; 10 | 11 | class ifile_class { 12 | 13 | public: 14 | static Handle add(const Arguments& args); 15 | static Handle match(const Arguments& args); 16 | static Handle add_mime(const Arguments& args); 17 | 18 | static void loop_add(Handle uri_array, Handle dir_array, Handle suffix_array, ifile_handler **ifile_handler_p, int len); 19 | static void worker_callback(uv_work_t* req); 20 | static void after_worker_callback(uv_work_t *req, int status); 21 | static void fs_state_callback(uv_fs_t *req); 22 | 23 | static char* mystrsep(char** stringp, const char* delim); 24 | static inline char* tolower2(char* s); 25 | static void show_handler_p(ifile_handler **ifile_handler_p, int len);//测试用打印静态文件handler规则数组 26 | static std::string toCString(Handle strp); 27 | static time_t parseLocalDate(char* date); 28 | static std::string time_to_utc(time_t *time_p); 29 | static void create_etag(unsigned long mtime, unsigned long size, std::string &etag_str); 30 | ifile_class(){}; 31 | ~ifile_class(){}; 32 | 33 | 34 | 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /src/ifile_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef IFILE_HANDLER_H 2 | #define IFILE_HANDLER_H 3 | #include 4 | #include 5 | 6 | 7 | using namespace v8; 8 | 9 | class ifile_handler { 10 | 11 | public: 12 | 13 | char *static_uri; //静态文件的url地址 14 | int static_uri_len; 15 | char *static_dir; //静态文件的路径地址 16 | int static_dir_len; 17 | char **file_type; //静态文件的后缀名数组 18 | int file_type_len; //后缀名判断数组长度 19 | int is_file_type; //是否设置后缀名判断 20 | 21 | 22 | ifile_handler(){}; 23 | ~ifile_handler(){}; 24 | 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/mime.h: -------------------------------------------------------------------------------- 1 | #ifndef Mime_H 2 | #define Mime_H 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | using namespace v8; 9 | 10 | class Mime { 11 | 12 | public: 13 | 14 | char *mime_name;//文件后缀名,比如.js文件保存为js 15 | int mime_name_len; 16 | char *mime_type;//文件响应类型比如,text/plain 17 | int mime_type_len; 18 | 19 | Mime(){}; 20 | ~Mime(){}; 21 | 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /src/request.h: -------------------------------------------------------------------------------- 1 | #ifndef REQUEST_H 2 | #define REQUEST_H 3 | #include 4 | #include "uv.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace v8; 11 | 12 | class Request { 13 | 14 | public: 15 | 16 | char *url; //保存url 17 | char *if_modified_since; //客户端缓存日期字符串 18 | char *if_none_match; //etag对应的请求头,表示静态资源缓存 19 | char *accept_encoding; //gzip压缩请求头 20 | int is_gzip; 21 | std::string method; //保存请求方法 22 | char *no_param_uri; //拆分之后的请求url 23 | char *char_uri_sep; //保存用来切分的char* 24 | char *suffix; //请求后缀名 25 | char *file_path; //文件保存的文件路径 26 | char *file_dir; //文件保存的文件夹路径 27 | std::string file_hole_path; //读取完整的文件路径 28 | node::Buffer* buffer_p; //保存nodejs的buffer指针 29 | 30 | uv_statbuf_t *uv_statbuf_p; //uvstatebuf的指针 31 | 32 | char *buf; //保存文件的buf指针 33 | unsigned long buf_size; 34 | char *buf_gzip; //保存gzip的buf指针 35 | unsigned long buf_gzip_size; 36 | 37 | uv_work_t work_pool; //libuv工作线程池 38 | uv_fs_t fs_t; //libuv fs_t 39 | 40 | int is_find_file; //是否匹配到文件 41 | int is_static; //请求是否是static 42 | Persistent res_js_obj; //保存res对象at 43 | Persistent req_js_obj; //保存res对象at 44 | 45 | //res header use 46 | int status_code; 47 | char *content_type; 48 | int content_type_len; 49 | unsigned long content_length; 50 | time_t mtime; //mtime时间戳 51 | std::string last_modify; 52 | std::string etag; 53 | 54 | 55 | //gzip 56 | int is_pipe; 57 | int pipe_size; 58 | int is_config_gzip; 59 | int gzip_min_size; 60 | int gzip_level; 61 | 62 | 63 | Request(){ 64 | url = 0; 65 | if_modified_since=0; 66 | if_none_match=0; 67 | accept_encoding=0; 68 | is_gzip=0; 69 | no_param_uri = 0; 70 | char_uri_sep = 0; 71 | suffix = 0; 72 | file_path = 0; 73 | file_dir = 0; 74 | buf = 0; 75 | is_static = 0; 76 | content_length = 0; 77 | content_type = 0; 78 | status_code = 200; 79 | buf_gzip=0; 80 | is_pipe=0; 81 | }; 82 | ~Request(){ 83 | 84 | //if(url) delete []url; 85 | if(if_modified_since) delete[]if_modified_since; 86 | if(if_none_match) delete[]if_none_match; 87 | if(accept_encoding) delete[]accept_encoding; 88 | if(no_param_uri) delete []no_param_uri; 89 | if(char_uri_sep) delete []char_uri_sep; 90 | if(suffix) delete []suffix; 91 | if(file_path) delete []file_path; 92 | if(file_dir) delete []file_dir; 93 | if(buf) delete []buf; 94 | if(content_type) delete[]content_type; 95 | if(buf_gzip) delete[]buf_gzip; 96 | 97 | res_js_obj.Dispose(); 98 | req_js_obj.Dispose(); 99 | }; 100 | 101 | }; 102 | 103 | #endif -------------------------------------------------------------------------------- /src/zlib/LICENSE: -------------------------------------------------------------------------------- 1 | /* zlib.h -- interface of the 'zlib' general purpose compression library 2 | version 1.2.4, March 14th, 2010 3 | 4 | Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 5 | 6 | This software is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this software must not be misrepresented; you must not 15 | claim that you wrote the original software. If you use this software 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | 22 | Jean-loup Gailly 23 | Mark Adler 24 | 25 | */ 26 | -------------------------------------------------------------------------------- /src/zlib/README.chromium: -------------------------------------------------------------------------------- 1 | Name: zlib 2 | URL: http://zlib.net/ 3 | Version: 1.2.3 4 | 5 | Description: 6 | General purpose compression library 7 | 8 | Local Modifications: 9 | A few minor changes, all marked with "Google": 10 | - Added #ifdefs to avoid compile warnings when NO_GZCOMPRESS is defined. 11 | - Removed use of strerror for WinCE in gzio.c. 12 | - Added 'int z_errno' global for WinCE, to which 'errno' is defined in zutil.h. 13 | -------------------------------------------------------------------------------- /src/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: adler32.c,v 3.6 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | #define BASE 65521UL /* largest prime smaller than 65536 */ 12 | #define NMAX 5552 13 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 14 | 15 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 16 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 17 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 18 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 19 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 20 | 21 | /* use NO_DIVIDE if your processor does not do division in hardware */ 22 | #ifdef NO_DIVIDE 23 | # define MOD(a) \ 24 | do { \ 25 | if (a >= (BASE << 16)) a -= (BASE << 16); \ 26 | if (a >= (BASE << 15)) a -= (BASE << 15); \ 27 | if (a >= (BASE << 14)) a -= (BASE << 14); \ 28 | if (a >= (BASE << 13)) a -= (BASE << 13); \ 29 | if (a >= (BASE << 12)) a -= (BASE << 12); \ 30 | if (a >= (BASE << 11)) a -= (BASE << 11); \ 31 | if (a >= (BASE << 10)) a -= (BASE << 10); \ 32 | if (a >= (BASE << 9)) a -= (BASE << 9); \ 33 | if (a >= (BASE << 8)) a -= (BASE << 8); \ 34 | if (a >= (BASE << 7)) a -= (BASE << 7); \ 35 | if (a >= (BASE << 6)) a -= (BASE << 6); \ 36 | if (a >= (BASE << 5)) a -= (BASE << 5); \ 37 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 38 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 39 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 40 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 41 | if (a >= BASE) a -= BASE; \ 42 | } while (0) 43 | # define MOD4(a) \ 44 | do { \ 45 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 46 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 47 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 48 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 49 | if (a >= BASE) a -= BASE; \ 50 | } while (0) 51 | #else 52 | # define MOD(a) a %= BASE 53 | # define MOD4(a) a %= BASE 54 | #endif 55 | 56 | /* ========================================================================= */ 57 | uLong ZEXPORT adler32(adler, buf, len) 58 | uLong adler; 59 | const Bytef *buf; 60 | uInt len; 61 | { 62 | unsigned long sum2; 63 | unsigned n; 64 | 65 | /* split Adler-32 into component sums */ 66 | sum2 = (adler >> 16) & 0xffff; 67 | adler &= 0xffff; 68 | 69 | /* in case user likes doing a byte at a time, keep it fast */ 70 | if (len == 1) { 71 | adler += buf[0]; 72 | if (adler >= BASE) 73 | adler -= BASE; 74 | sum2 += adler; 75 | if (sum2 >= BASE) 76 | sum2 -= BASE; 77 | return adler | (sum2 << 16); 78 | } 79 | 80 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 81 | if (buf == Z_NULL) 82 | return 1L; 83 | 84 | /* in case short lengths are provided, keep it somewhat fast */ 85 | if (len < 16) { 86 | while (len--) { 87 | adler += *buf++; 88 | sum2 += adler; 89 | } 90 | if (adler >= BASE) 91 | adler -= BASE; 92 | MOD4(sum2); /* only added so many BASE's */ 93 | return adler | (sum2 << 16); 94 | } 95 | 96 | /* do length NMAX blocks -- requires just one modulo operation */ 97 | while (len >= NMAX) { 98 | len -= NMAX; 99 | n = NMAX / 16; /* NMAX is divisible by 16 */ 100 | do { 101 | DO16(buf); /* 16 sums unrolled */ 102 | buf += 16; 103 | } while (--n); 104 | MOD(adler); 105 | MOD(sum2); 106 | } 107 | 108 | /* do remaining bytes (less than NMAX, still just one modulo) */ 109 | if (len) { /* avoid modulos if none remaining */ 110 | while (len >= 16) { 111 | len -= 16; 112 | DO16(buf); 113 | buf += 16; 114 | } 115 | while (len--) { 116 | adler += *buf++; 117 | sum2 += adler; 118 | } 119 | MOD(adler); 120 | MOD(sum2); 121 | } 122 | 123 | /* return recombined sums */ 124 | return adler | (sum2 << 16); 125 | } 126 | 127 | /* ========================================================================= */ 128 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 129 | uLong adler1; 130 | uLong adler2; 131 | z_off_t len2; 132 | { 133 | unsigned long sum1; 134 | unsigned long sum2; 135 | unsigned rem; 136 | 137 | /* the derivation of this formula is left as an exercise for the reader */ 138 | rem = (unsigned)(len2 % BASE); 139 | sum1 = adler1 & 0xffff; 140 | sum2 = rem * sum1; 141 | MOD(sum2); 142 | sum1 += (adler2 & 0xffff) + BASE - 1; 143 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 144 | if (sum1 > BASE) sum1 -= BASE; 145 | if (sum1 > BASE) sum1 -= BASE; 146 | if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); 147 | if (sum2 > BASE) sum2 -= BASE; 148 | return sum1 | (sum2 << 16); 149 | } 150 | -------------------------------------------------------------------------------- /src/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: compress.c,v 3.6 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; 79 | } 80 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/ChangeLogUnzip: -------------------------------------------------------------------------------- 1 | Change in 1.01e (12 feb 05) 2 | - Fix in zipOpen2 for globalcomment (Rolf Kalbermatter) 3 | - Fix possible memory leak in unzip.c (Zoran Stevanovic) 4 | 5 | Change in 1.01b (20 may 04) 6 | - Integrate patch from Debian package (submited by Mark Brown) 7 | - Add tools mztools from Xavier Roche 8 | 9 | Change in 1.01 (8 may 04) 10 | - fix buffer overrun risk in unzip.c (Xavier Roche) 11 | - fix a minor buffer insecurity in minizip.c (Mike Whittaker) 12 | 13 | Change in 1.00: (10 sept 03) 14 | - rename to 1.00 15 | - cosmetic code change 16 | 17 | Change in 0.22: (19 May 03) 18 | - crypting support (unless you define NOCRYPT) 19 | - append file in existing zipfile 20 | 21 | Change in 0.21: (10 Mar 03) 22 | - bug fixes 23 | 24 | Change in 0.17: (27 Jan 02) 25 | - bug fixes 26 | 27 | Change in 0.16: (19 Jan 02) 28 | - Support of ioapi for virtualize zip file access 29 | 30 | Change in 0.15: (19 Mar 98) 31 | - fix memory leak in minizip.c 32 | 33 | Change in 0.14: (10 Mar 98) 34 | - fix bugs in minizip.c sample for zipping big file 35 | - fix problem in month in date handling 36 | - fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for 37 | comment handling 38 | 39 | Change in 0.13: (6 Mar 98) 40 | - fix bugs in zip.c 41 | - add real minizip sample 42 | 43 | Change in 0.12: (4 Mar 98) 44 | - add zip.c and zip.h for creates .zip file 45 | - fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) 46 | - fix miniunz.c for file without specific record for directory 47 | 48 | Change in 0.11: (3 Mar 98) 49 | - fix bug in unzGetCurrentFileInfo for get extra field and comment 50 | - enhance miniunz sample, remove the bad unztst.c sample 51 | 52 | Change in 0.10: (2 Mar 98) 53 | - fix bug in unzReadCurrentFile 54 | - rename unzip* to unz* function and structure 55 | - remove Windows-like hungary notation variable name 56 | - modify some structure in unzip.h 57 | - add somes comment in source 58 | - remove unzipGetcCurrentFile function 59 | - replace ZUNZEXPORT by ZEXPORT 60 | - add unzGetLocalExtrafield for get the local extrafield info 61 | - add a new sample, miniunz.c 62 | 63 | Change in 0.4: (25 Feb 98) 64 | - suppress the type unzipFileInZip. 65 | Only on file in the zipfile can be open at the same time 66 | - fix somes typo in code 67 | - added tm_unz structure in unzip_file_info (date/time in readable format) 68 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS=-O -I../.. 3 | 4 | UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a 5 | ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a 6 | 7 | .c.o: 8 | $(CC) -c $(CFLAGS) $*.c 9 | 10 | all: miniunz minizip 11 | 12 | miniunz: $(UNZ_OBJS) 13 | $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) 14 | 15 | minizip: $(ZIP_OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) 17 | 18 | test: miniunz minizip 19 | ./minizip test readme.txt 20 | ./miniunz -l test.zip 21 | mv readme.txt readme.old 22 | ./miniunz test.zip 23 | 24 | clean: 25 | /bin/rm -f *.o *~ minizip miniunz 26 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile 2 | 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | 8 | This code is a modified version of crypting code in Infozip distribution 9 | 10 | The encryption/decryption parts of this source code (as opposed to the 11 | non-echoing password parts) were originally written in Europe. The 12 | whole source package can be freely distributed, including from the USA. 13 | (Prior to January 2000, re-export from the US was a violation of US law.) 14 | 15 | This encryption code is a direct transcription of the algorithm from 16 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 | file (appnote.txt) is distributed with the PKZIP program (even in the 18 | version without encryption capabilities). 19 | 20 | If you don't need crypting in your application, just define symbols 21 | NOCRYPT and NOUNCRYPT. 22 | 23 | This code support the "Traditional PKWARE Encryption". 24 | 25 | The new AES encryption added on Zip format by Winzip (see the page 26 | http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 | Encryption is not supported. 28 | */ 29 | 30 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 31 | 32 | /*********************************************************************** 33 | * Return the next byte in the pseudo-random sequence 34 | */ 35 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 36 | { 37 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 38 | * unpredictable manner on 16-bit systems; not a problem 39 | * with any known compiler so far, though */ 40 | 41 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 42 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 43 | } 44 | 45 | /*********************************************************************** 46 | * Update the encryption keys with the next byte of plain text 47 | */ 48 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 49 | { 50 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 51 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 52 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 53 | { 54 | register int keyshift = (int)((*(pkeys+1)) >> 24); 55 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 56 | } 57 | return c; 58 | } 59 | 60 | 61 | /*********************************************************************** 62 | * Initialize the encryption keys and the random header according to 63 | * the given password. 64 | */ 65 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 66 | { 67 | *(pkeys+0) = 305419896L; 68 | *(pkeys+1) = 591751049L; 69 | *(pkeys+2) = 878082192L; 70 | while (*passwd != '\0') { 71 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 | passwd++; 73 | } 74 | } 75 | 76 | #define zdecode(pkeys,pcrc_32_tab,c) \ 77 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 78 | 79 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 80 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 | 82 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 | 84 | #define RAND_HEAD_LEN 12 85 | /* "last resort" source for second part of crypt seed pattern */ 86 | # ifndef ZCR_SEED2 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 | # endif 89 | 90 | static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 91 | const char *passwd; /* password string */ 92 | unsigned char *buf; /* where to write header */ 93 | int bufSize; 94 | unsigned long* pkeys; 95 | const unsigned long* pcrc_32_tab; 96 | unsigned long crcForCrypting; 97 | { 98 | int n; /* index in random header */ 99 | int t; /* temporary */ 100 | int c; /* random byte */ 101 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 102 | static unsigned calls = 0; /* ensure different random header each time */ 103 | 104 | if (bufSize> 7) & 0xff; 119 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 120 | } 121 | /* Encrypt random header (last two bytes is high word of crc) */ 122 | init_keys(passwd, pkeys, pcrc_32_tab); 123 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 124 | { 125 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 126 | } 127 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 128 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 129 | return n; 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #if defined(USE_SYSTEM_ZLIB) 14 | #include 15 | #else 16 | #include "../../zlib.h" 17 | #endif 18 | 19 | #include "ioapi.h" 20 | 21 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 22 | 23 | #ifndef SEEK_CUR 24 | #define SEEK_CUR 1 25 | #endif 26 | 27 | #ifndef SEEK_END 28 | #define SEEK_END 2 29 | #endif 30 | 31 | #ifndef SEEK_SET 32 | #define SEEK_SET 0 33 | #endif 34 | 35 | voidpf ZCALLBACK fopen_file_func OF(( 36 | voidpf opaque, 37 | const char* filename, 38 | int mode)); 39 | 40 | uLong ZCALLBACK fread_file_func OF(( 41 | voidpf opaque, 42 | voidpf stream, 43 | void* buf, 44 | uLong size)); 45 | 46 | uLong ZCALLBACK fwrite_file_func OF(( 47 | voidpf opaque, 48 | voidpf stream, 49 | const void* buf, 50 | uLong size)); 51 | 52 | long ZCALLBACK ftell_file_func OF(( 53 | voidpf opaque, 54 | voidpf stream)); 55 | 56 | long ZCALLBACK fseek_file_func OF(( 57 | voidpf opaque, 58 | voidpf stream, 59 | uLong offset, 60 | int origin)); 61 | 62 | int ZCALLBACK fclose_file_func OF(( 63 | voidpf opaque, 64 | voidpf stream)); 65 | 66 | int ZCALLBACK ferror_file_func OF(( 67 | voidpf opaque, 68 | voidpf stream)); 69 | 70 | 71 | voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 72 | voidpf opaque; 73 | const char* filename; 74 | int mode; 75 | { 76 | FILE* file = NULL; 77 | const char* mode_fopen = NULL; 78 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 79 | mode_fopen = "rb"; 80 | else 81 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 82 | mode_fopen = "r+b"; 83 | else 84 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 85 | mode_fopen = "wb"; 86 | 87 | if ((filename!=NULL) && (mode_fopen != NULL)) 88 | file = fopen(filename, mode_fopen); 89 | return file; 90 | } 91 | 92 | 93 | uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 94 | voidpf opaque; 95 | voidpf stream; 96 | void* buf; 97 | uLong size; 98 | { 99 | uLong ret; 100 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 101 | return ret; 102 | } 103 | 104 | 105 | uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) 106 | voidpf opaque; 107 | voidpf stream; 108 | const void* buf; 109 | uLong size; 110 | { 111 | uLong ret; 112 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 113 | return ret; 114 | } 115 | 116 | long ZCALLBACK ftell_file_func (opaque, stream) 117 | voidpf opaque; 118 | voidpf stream; 119 | { 120 | long ret; 121 | ret = ftell((FILE *)stream); 122 | return ret; 123 | } 124 | 125 | long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 126 | voidpf opaque; 127 | voidpf stream; 128 | uLong offset; 129 | int origin; 130 | { 131 | int fseek_origin=0; 132 | long ret; 133 | switch (origin) 134 | { 135 | case ZLIB_FILEFUNC_SEEK_CUR : 136 | fseek_origin = SEEK_CUR; 137 | break; 138 | case ZLIB_FILEFUNC_SEEK_END : 139 | fseek_origin = SEEK_END; 140 | break; 141 | case ZLIB_FILEFUNC_SEEK_SET : 142 | fseek_origin = SEEK_SET; 143 | break; 144 | default: return -1; 145 | } 146 | ret = 0; 147 | fseek((FILE *)stream, offset, fseek_origin); 148 | return ret; 149 | } 150 | 151 | int ZCALLBACK fclose_file_func (opaque, stream) 152 | voidpf opaque; 153 | voidpf stream; 154 | { 155 | int ret; 156 | ret = fclose((FILE *)stream); 157 | return ret; 158 | } 159 | 160 | int ZCALLBACK ferror_file_func (opaque, stream) 161 | voidpf opaque; 162 | voidpf stream; 163 | { 164 | int ret; 165 | ret = ferror((FILE *)stream); 166 | return ret; 167 | } 168 | 169 | void fill_fopen_filefunc (pzlib_filefunc_def) 170 | zlib_filefunc_def* pzlib_filefunc_def; 171 | { 172 | pzlib_filefunc_def->zopen_file = fopen_file_func; 173 | pzlib_filefunc_def->zread_file = fread_file_func; 174 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 175 | pzlib_filefunc_def->ztell_file = ftell_file_func; 176 | pzlib_filefunc_def->zseek_file = fseek_file_func; 177 | pzlib_filefunc_def->zclose_file = fclose_file_func; 178 | pzlib_filefunc_def->zerror_file = ferror_file_func; 179 | pzlib_filefunc_def->opaque = NULL; 180 | } 181 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01e, February 12th, 2005 5 | 6 | Copyright (C) 1998-2005 Gilles Vollant 7 | */ 8 | 9 | #ifndef _ZLIBIOAPI_H 10 | #define _ZLIBIOAPI_H 11 | 12 | 13 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 14 | #define ZLIB_FILEFUNC_SEEK_END (2) 15 | #define ZLIB_FILEFUNC_SEEK_SET (0) 16 | 17 | #define ZLIB_FILEFUNC_MODE_READ (1) 18 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 19 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 20 | 21 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 22 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 23 | 24 | 25 | #ifndef ZCALLBACK 26 | 27 | #if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 28 | #define ZCALLBACK CALLBACK 29 | #else 30 | #define ZCALLBACK 31 | #endif 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 39 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 40 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 41 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 42 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 43 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 44 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 45 | 46 | typedef struct zlib_filefunc_def_s 47 | { 48 | open_file_func zopen_file; 49 | read_file_func zread_file; 50 | write_file_func zwrite_file; 51 | tell_file_func ztell_file; 52 | seek_file_func zseek_file; 53 | close_file_func zclose_file; 54 | testerror_file_func zerror_file; 55 | voidpf opaque; 56 | } zlib_filefunc_def; 57 | 58 | 59 | 60 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 61 | 62 | #define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 63 | #define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 64 | #define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 65 | #define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 66 | #define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 67 | #define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 68 | 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/iowin32.c: -------------------------------------------------------------------------------- 1 | /* iowin32.c -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | This IO API version uses the Win32 API (for Microsoft Windows) 4 | 5 | Version 1.01e, February 12th, 2005 6 | 7 | Copyright (C) 1998-2005 Gilles Vollant 8 | */ 9 | 10 | #include 11 | 12 | #include "../../zlib.h" 13 | #include "ioapi.h" 14 | #include "iowin32.h" 15 | 16 | #ifndef INVALID_HANDLE_VALUE 17 | #define INVALID_HANDLE_VALUE (0xFFFFFFFF) 18 | #endif 19 | 20 | #ifndef INVALID_SET_FILE_POINTER 21 | #define INVALID_SET_FILE_POINTER ((DWORD)-1) 22 | #endif 23 | 24 | voidpf ZCALLBACK win32_open_file_func OF(( 25 | voidpf opaque, 26 | const char* filename, 27 | int mode)); 28 | 29 | uLong ZCALLBACK win32_read_file_func OF(( 30 | voidpf opaque, 31 | voidpf stream, 32 | void* buf, 33 | uLong size)); 34 | 35 | uLong ZCALLBACK win32_write_file_func OF(( 36 | voidpf opaque, 37 | voidpf stream, 38 | const void* buf, 39 | uLong size)); 40 | 41 | long ZCALLBACK win32_tell_file_func OF(( 42 | voidpf opaque, 43 | voidpf stream)); 44 | 45 | long ZCALLBACK win32_seek_file_func OF(( 46 | voidpf opaque, 47 | voidpf stream, 48 | uLong offset, 49 | int origin)); 50 | 51 | int ZCALLBACK win32_close_file_func OF(( 52 | voidpf opaque, 53 | voidpf stream)); 54 | 55 | int ZCALLBACK win32_error_file_func OF(( 56 | voidpf opaque, 57 | voidpf stream)); 58 | 59 | typedef struct 60 | { 61 | HANDLE hf; 62 | int error; 63 | } WIN32FILE_IOWIN; 64 | 65 | voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) 66 | voidpf opaque; 67 | const char* filename; 68 | int mode; 69 | { 70 | const char* mode_fopen = NULL; 71 | DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 72 | HANDLE hFile = 0; 73 | voidpf ret=NULL; 74 | 75 | dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; 76 | 77 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 78 | { 79 | dwDesiredAccess = GENERIC_READ; 80 | dwCreationDisposition = OPEN_EXISTING; 81 | dwShareMode = FILE_SHARE_READ; 82 | } 83 | else 84 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 85 | { 86 | dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 87 | dwCreationDisposition = OPEN_EXISTING; 88 | } 89 | else 90 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 91 | { 92 | dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 93 | dwCreationDisposition = CREATE_ALWAYS; 94 | } 95 | 96 | if ((filename!=NULL) && (dwDesiredAccess != 0)) 97 | hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, 98 | dwCreationDisposition, dwFlagsAndAttributes, NULL); 99 | 100 | if (hFile == INVALID_HANDLE_VALUE) 101 | hFile = NULL; 102 | 103 | if (hFile != NULL) 104 | { 105 | WIN32FILE_IOWIN w32fiow; 106 | w32fiow.hf = hFile; 107 | w32fiow.error = 0; 108 | ret = malloc(sizeof(WIN32FILE_IOWIN)); 109 | if (ret==NULL) 110 | CloseHandle(hFile); 111 | else *((WIN32FILE_IOWIN*)ret) = w32fiow; 112 | } 113 | return ret; 114 | } 115 | 116 | 117 | uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) 118 | voidpf opaque; 119 | voidpf stream; 120 | void* buf; 121 | uLong size; 122 | { 123 | uLong ret=0; 124 | HANDLE hFile = NULL; 125 | if (stream!=NULL) 126 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 127 | if (hFile != NULL) 128 | if (!ReadFile(hFile, buf, size, &ret, NULL)) 129 | { 130 | DWORD dwErr = GetLastError(); 131 | if (dwErr == ERROR_HANDLE_EOF) 132 | dwErr = 0; 133 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 134 | } 135 | 136 | return ret; 137 | } 138 | 139 | 140 | uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) 141 | voidpf opaque; 142 | voidpf stream; 143 | const void* buf; 144 | uLong size; 145 | { 146 | uLong ret=0; 147 | HANDLE hFile = NULL; 148 | if (stream!=NULL) 149 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 150 | 151 | if (hFile !=NULL) 152 | if (!WriteFile(hFile, buf, size, &ret, NULL)) 153 | { 154 | DWORD dwErr = GetLastError(); 155 | if (dwErr == ERROR_HANDLE_EOF) 156 | dwErr = 0; 157 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 158 | } 159 | 160 | return ret; 161 | } 162 | 163 | long ZCALLBACK win32_tell_file_func (opaque, stream) 164 | voidpf opaque; 165 | voidpf stream; 166 | { 167 | long ret=-1; 168 | HANDLE hFile = NULL; 169 | if (stream!=NULL) 170 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 171 | if (hFile != NULL) 172 | { 173 | DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); 174 | if (dwSet == INVALID_SET_FILE_POINTER) 175 | { 176 | DWORD dwErr = GetLastError(); 177 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 178 | ret = -1; 179 | } 180 | else 181 | ret=(long)dwSet; 182 | } 183 | return ret; 184 | } 185 | 186 | long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) 187 | voidpf opaque; 188 | voidpf stream; 189 | uLong offset; 190 | int origin; 191 | { 192 | DWORD dwMoveMethod=0xFFFFFFFF; 193 | HANDLE hFile = NULL; 194 | 195 | long ret=-1; 196 | if (stream!=NULL) 197 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 198 | switch (origin) 199 | { 200 | case ZLIB_FILEFUNC_SEEK_CUR : 201 | dwMoveMethod = FILE_CURRENT; 202 | break; 203 | case ZLIB_FILEFUNC_SEEK_END : 204 | dwMoveMethod = FILE_END; 205 | break; 206 | case ZLIB_FILEFUNC_SEEK_SET : 207 | dwMoveMethod = FILE_BEGIN; 208 | break; 209 | default: return -1; 210 | } 211 | 212 | if (hFile != NULL) 213 | { 214 | DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); 215 | if (dwSet == INVALID_SET_FILE_POINTER) 216 | { 217 | DWORD dwErr = GetLastError(); 218 | ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 219 | ret = -1; 220 | } 221 | else 222 | ret=0; 223 | } 224 | return ret; 225 | } 226 | 227 | int ZCALLBACK win32_close_file_func (opaque, stream) 228 | voidpf opaque; 229 | voidpf stream; 230 | { 231 | int ret=-1; 232 | 233 | if (stream!=NULL) 234 | { 235 | HANDLE hFile; 236 | hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 237 | if (hFile != NULL) 238 | { 239 | CloseHandle(hFile); 240 | ret=0; 241 | } 242 | free(stream); 243 | } 244 | return ret; 245 | } 246 | 247 | int ZCALLBACK win32_error_file_func (opaque, stream) 248 | voidpf opaque; 249 | voidpf stream; 250 | { 251 | int ret=-1; 252 | if (stream!=NULL) 253 | { 254 | ret = ((WIN32FILE_IOWIN*)stream) -> error; 255 | } 256 | return ret; 257 | } 258 | 259 | void fill_win32_filefunc (pzlib_filefunc_def) 260 | zlib_filefunc_def* pzlib_filefunc_def; 261 | { 262 | pzlib_filefunc_def->zopen_file = win32_open_file_func; 263 | pzlib_filefunc_def->zread_file = win32_read_file_func; 264 | pzlib_filefunc_def->zwrite_file = win32_write_file_func; 265 | pzlib_filefunc_def->ztell_file = win32_tell_file_func; 266 | pzlib_filefunc_def->zseek_file = win32_seek_file_func; 267 | pzlib_filefunc_def->zclose_file = win32_close_file_func; 268 | pzlib_filefunc_def->zerror_file = win32_error_file_func; 269 | pzlib_filefunc_def->opaque=NULL; 270 | } 271 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/iowin32.h: -------------------------------------------------------------------------------- 1 | /* iowin32.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | This IO API version uses the Win32 API (for Microsoft Windows) 4 | 5 | Version 1.01e, February 12th, 2005 6 | 7 | Copyright (C) 1998-2005 Gilles Vollant 8 | */ 9 | 10 | #include 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/minizip.c: -------------------------------------------------------------------------------- 1 | /* 2 | minizip.c 3 | Version 1.01e, February 12th, 2005 4 | 5 | Copyright (C) 1998-2005 Gilles Vollant 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef unix 16 | # include 17 | # include 18 | # include 19 | # include 20 | #else 21 | # include 22 | # include 23 | #endif 24 | 25 | #include "zip.h" 26 | 27 | #ifdef WIN32 28 | #define USEWIN32IOAPI 29 | #include "iowin32.h" 30 | #endif 31 | 32 | 33 | 34 | #define WRITEBUFFERSIZE (16384) 35 | #define MAXFILENAME (256) 36 | 37 | #ifdef WIN32 38 | uLong filetime(f, tmzip, dt) 39 | char *f; /* name of file to get info on */ 40 | tm_zip *tmzip; /* return value: access, modific. and creation times */ 41 | uLong *dt; /* dostime */ 42 | { 43 | int ret = 0; 44 | { 45 | FILETIME ftLocal; 46 | HANDLE hFind; 47 | WIN32_FIND_DATA ff32; 48 | 49 | hFind = FindFirstFile(f,&ff32); 50 | if (hFind != INVALID_HANDLE_VALUE) 51 | { 52 | FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); 53 | FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); 54 | FindClose(hFind); 55 | ret = 1; 56 | } 57 | } 58 | return ret; 59 | } 60 | #else 61 | #ifdef unix 62 | uLong filetime(f, tmzip, dt) 63 | char *f; /* name of file to get info on */ 64 | tm_zip *tmzip; /* return value: access, modific. and creation times */ 65 | uLong *dt; /* dostime */ 66 | { 67 | int ret=0; 68 | struct stat s; /* results of stat() */ 69 | struct tm* filedate; 70 | time_t tm_t=0; 71 | 72 | if (strcmp(f,"-")!=0) 73 | { 74 | char name[MAXFILENAME+1]; 75 | int len = strlen(f); 76 | if (len > MAXFILENAME) 77 | len = MAXFILENAME; 78 | 79 | strncpy(name, f,MAXFILENAME-1); 80 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ 81 | name[ MAXFILENAME ] = '\0'; 82 | 83 | if (name[len - 1] == '/') 84 | name[len - 1] = '\0'; 85 | /* not all systems allow stat'ing a file with / appended */ 86 | if (stat(name,&s)==0) 87 | { 88 | tm_t = s.st_mtime; 89 | ret = 1; 90 | } 91 | } 92 | filedate = localtime(&tm_t); 93 | 94 | tmzip->tm_sec = filedate->tm_sec; 95 | tmzip->tm_min = filedate->tm_min; 96 | tmzip->tm_hour = filedate->tm_hour; 97 | tmzip->tm_mday = filedate->tm_mday; 98 | tmzip->tm_mon = filedate->tm_mon ; 99 | tmzip->tm_year = filedate->tm_year; 100 | 101 | return ret; 102 | } 103 | #else 104 | uLong filetime(f, tmzip, dt) 105 | char *f; /* name of file to get info on */ 106 | tm_zip *tmzip; /* return value: access, modific. and creation times */ 107 | uLong *dt; /* dostime */ 108 | { 109 | return 0; 110 | } 111 | #endif 112 | #endif 113 | 114 | 115 | 116 | 117 | int check_exist_file(filename) 118 | const char* filename; 119 | { 120 | FILE* ftestexist; 121 | int ret = 1; 122 | ftestexist = fopen(filename,"rb"); 123 | if (ftestexist==NULL) 124 | ret = 0; 125 | else 126 | fclose(ftestexist); 127 | return ret; 128 | } 129 | 130 | void do_banner() 131 | { 132 | printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); 133 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); 134 | } 135 | 136 | void do_help() 137 | { 138 | printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip [files_to_add]\n\n" \ 139 | " -o Overwrite existing file.zip\n" \ 140 | " -a Append to existing file.zip\n" \ 141 | " -0 Store only\n" \ 142 | " -1 Compress faster\n" \ 143 | " -9 Compress better\n\n"); 144 | } 145 | 146 | /* calculate the CRC32 of a file, 147 | because to encrypt a file, we need known the CRC32 of the file before */ 148 | int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) 149 | { 150 | unsigned long calculate_crc=0; 151 | int err=ZIP_OK; 152 | FILE * fin = fopen(filenameinzip,"rb"); 153 | unsigned long size_read = 0; 154 | unsigned long total_read = 0; 155 | if (fin==NULL) 156 | { 157 | err = ZIP_ERRNO; 158 | } 159 | 160 | if (err == ZIP_OK) 161 | do 162 | { 163 | err = ZIP_OK; 164 | size_read = (int)fread(buf,1,size_buf,fin); 165 | if (size_read < size_buf) 166 | if (feof(fin)==0) 167 | { 168 | printf("error in reading %s\n",filenameinzip); 169 | err = ZIP_ERRNO; 170 | } 171 | 172 | if (size_read>0) 173 | calculate_crc = crc32(calculate_crc,buf,size_read); 174 | total_read += size_read; 175 | 176 | } while ((err == ZIP_OK) && (size_read>0)); 177 | 178 | if (fin) 179 | fclose(fin); 180 | 181 | *result_crc=calculate_crc; 182 | printf("file %s crc %x\n",filenameinzip,calculate_crc); 183 | return err; 184 | } 185 | 186 | int main(argc,argv) 187 | int argc; 188 | char *argv[]; 189 | { 190 | int i; 191 | int opt_overwrite=0; 192 | int opt_compress_level=Z_DEFAULT_COMPRESSION; 193 | int zipfilenamearg = 0; 194 | char filename_try[MAXFILENAME+16]; 195 | int zipok; 196 | int err=0; 197 | int size_buf=0; 198 | void* buf=NULL; 199 | const char* password=NULL; 200 | 201 | 202 | do_banner(); 203 | if (argc==1) 204 | { 205 | do_help(); 206 | return 0; 207 | } 208 | else 209 | { 210 | for (i=1;i='0') && (c<='9')) 224 | opt_compress_level = c-'0'; 225 | 226 | if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) 290 | rep -= 0x20; 291 | } 292 | while ((rep!='Y') && (rep!='N') && (rep!='A')); 293 | if (rep=='N') 294 | zipok = 0; 295 | if (rep=='A') 296 | opt_overwrite = 2; 297 | } 298 | } 299 | 300 | if (zipok==1) 301 | { 302 | zipFile zf; 303 | int errclose; 304 | # ifdef USEWIN32IOAPI 305 | zlib_filefunc_def ffunc; 306 | fill_win32_filefunc(&ffunc); 307 | zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); 308 | # else 309 | zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); 310 | # endif 311 | 312 | if (zf == NULL) 313 | { 314 | printf("error opening %s\n",filename_try); 315 | err= ZIP_ERRNO; 316 | } 317 | else 318 | printf("creating %s\n",filename_try); 319 | 320 | for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && 327 | (strlen(argv[i]) == 2))) 328 | { 329 | FILE * fin; 330 | int size_read; 331 | const char* filenameinzip = argv[i]; 332 | zip_fileinfo zi; 333 | unsigned long crcFile=0; 334 | 335 | zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = 336 | zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; 337 | zi.dosDate = 0; 338 | zi.internal_fa = 0; 339 | zi.external_fa = 0; 340 | filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); 341 | 342 | /* 343 | err = zipOpenNewFileInZip(zf,filenameinzip,&zi, 344 | NULL,0,NULL,0,NULL / * comment * /, 345 | (opt_compress_level != 0) ? Z_DEFLATED : 0, 346 | opt_compress_level); 347 | */ 348 | if ((password != NULL) && (err==ZIP_OK)) 349 | err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); 350 | 351 | err = zipOpenNewFileInZip3(zf,filenameinzip,&zi, 352 | NULL,0,NULL,0,NULL /* comment*/, 353 | (opt_compress_level != 0) ? Z_DEFLATED : 0, 354 | opt_compress_level,0, 355 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ 356 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 357 | password,crcFile); 358 | 359 | if (err != ZIP_OK) 360 | printf("error in opening %s in zipfile\n",filenameinzip); 361 | else 362 | { 363 | fin = fopen(filenameinzip,"rb"); 364 | if (fin==NULL) 365 | { 366 | err=ZIP_ERRNO; 367 | printf("error in opening %s for reading\n",filenameinzip); 368 | } 369 | } 370 | 371 | if (err == ZIP_OK) 372 | do 373 | { 374 | err = ZIP_OK; 375 | size_read = (int)fread(buf,1,size_buf,fin); 376 | if (size_read < size_buf) 377 | if (feof(fin)==0) 378 | { 379 | printf("error in reading %s\n",filenameinzip); 380 | err = ZIP_ERRNO; 381 | } 382 | 383 | if (size_read>0) 384 | { 385 | err = zipWriteInFileInZip (zf,buf,size_read); 386 | if (err<0) 387 | { 388 | printf("error in writing %s in the zipfile\n", 389 | filenameinzip); 390 | } 391 | 392 | } 393 | } while ((err == ZIP_OK) && (size_read>0)); 394 | 395 | if (fin) 396 | fclose(fin); 397 | 398 | if (err<0) 399 | err=ZIP_ERRNO; 400 | else 401 | { 402 | err = zipCloseFileInZip(zf); 403 | if (err!=ZIP_OK) 404 | printf("error in closing %s in the zipfile\n", 405 | filenameinzip); 406 | } 407 | } 408 | } 409 | errclose = zipClose(zf,NULL); 410 | if (errclose != ZIP_OK) 411 | printf("error in closing %s\n",filename_try); 412 | } 413 | else 414 | { 415 | do_help(); 416 | } 417 | 418 | free(buf); 419 | return 0; 420 | } 421 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/mztools.c: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | /* Code */ 8 | #include 9 | #include 10 | #include 11 | 12 | #if defined(USE_SYSTEM_ZLIB) 13 | #include 14 | #else 15 | #include "zlib.h" 16 | #endif 17 | #include "unzip.h" 18 | 19 | #define READ_8(adr) ((unsigned char)*(adr)) 20 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) 21 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) 22 | 23 | #define WRITE_8(buff, n) do { \ 24 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ 25 | } while(0) 26 | #define WRITE_16(buff, n) do { \ 27 | WRITE_8((unsigned char*)(buff), n); \ 28 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ 29 | } while(0) 30 | #define WRITE_32(buff, n) do { \ 31 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ 32 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ 33 | } while(0) 34 | 35 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) 36 | const char* file; 37 | const char* fileOut; 38 | const char* fileOutTmp; 39 | uLong* nRecovered; 40 | uLong* bytesRecovered; 41 | { 42 | int err = Z_OK; 43 | FILE* fpZip = fopen(file, "rb"); 44 | FILE* fpOut = fopen(fileOut, "wb"); 45 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); 46 | if (fpZip != NULL && fpOut != NULL) { 47 | int entries = 0; 48 | uLong totalBytes = 0; 49 | char header[30]; 50 | char filename[256]; 51 | char extra[1024]; 52 | int offset = 0; 53 | int offsetCD = 0; 54 | while ( fread(header, 1, 30, fpZip) == 30 ) { 55 | int currentOffset = offset; 56 | 57 | /* File entry */ 58 | if (READ_32(header) == 0x04034b50) { 59 | unsigned int version = READ_16(header + 4); 60 | unsigned int gpflag = READ_16(header + 6); 61 | unsigned int method = READ_16(header + 8); 62 | unsigned int filetime = READ_16(header + 10); 63 | unsigned int filedate = READ_16(header + 12); 64 | unsigned int crc = READ_32(header + 14); /* crc */ 65 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ 66 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ 67 | unsigned int fnsize = READ_16(header + 26); /* file name length */ 68 | unsigned int extsize = READ_16(header + 28); /* extra field length */ 69 | filename[0] = extra[0] = '\0'; 70 | 71 | /* Header */ 72 | if (fwrite(header, 1, 30, fpOut) == 30) { 73 | offset += 30; 74 | } else { 75 | err = Z_ERRNO; 76 | break; 77 | } 78 | 79 | /* Filename */ 80 | if (fnsize > 0) { 81 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { 82 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { 83 | offset += fnsize; 84 | } else { 85 | err = Z_ERRNO; 86 | break; 87 | } 88 | } else { 89 | err = Z_ERRNO; 90 | break; 91 | } 92 | } else { 93 | err = Z_STREAM_ERROR; 94 | break; 95 | } 96 | 97 | /* Extra field */ 98 | if (extsize > 0) { 99 | if (fread(extra, 1, extsize, fpZip) == extsize) { 100 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { 101 | offset += extsize; 102 | } else { 103 | err = Z_ERRNO; 104 | break; 105 | } 106 | } else { 107 | err = Z_ERRNO; 108 | break; 109 | } 110 | } 111 | 112 | /* Data */ 113 | { 114 | int dataSize = cpsize; 115 | if (dataSize == 0) { 116 | dataSize = uncpsize; 117 | } 118 | if (dataSize > 0) { 119 | char* data = malloc(dataSize); 120 | if (data != NULL) { 121 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { 122 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { 123 | offset += dataSize; 124 | totalBytes += dataSize; 125 | } else { 126 | err = Z_ERRNO; 127 | } 128 | } else { 129 | err = Z_ERRNO; 130 | } 131 | free(data); 132 | if (err != Z_OK) { 133 | break; 134 | } 135 | } else { 136 | err = Z_MEM_ERROR; 137 | break; 138 | } 139 | } 140 | } 141 | 142 | /* Central directory entry */ 143 | { 144 | char header[46]; 145 | char* comment = ""; 146 | int comsize = (int) strlen(comment); 147 | WRITE_32(header, 0x02014b50); 148 | WRITE_16(header + 4, version); 149 | WRITE_16(header + 6, version); 150 | WRITE_16(header + 8, gpflag); 151 | WRITE_16(header + 10, method); 152 | WRITE_16(header + 12, filetime); 153 | WRITE_16(header + 14, filedate); 154 | WRITE_32(header + 16, crc); 155 | WRITE_32(header + 20, cpsize); 156 | WRITE_32(header + 24, uncpsize); 157 | WRITE_16(header + 28, fnsize); 158 | WRITE_16(header + 30, extsize); 159 | WRITE_16(header + 32, comsize); 160 | WRITE_16(header + 34, 0); /* disk # */ 161 | WRITE_16(header + 36, 0); /* int attrb */ 162 | WRITE_32(header + 38, 0); /* ext attrb */ 163 | WRITE_32(header + 42, currentOffset); 164 | /* Header */ 165 | if (fwrite(header, 1, 46, fpOutCD) == 46) { 166 | offsetCD += 46; 167 | 168 | /* Filename */ 169 | if (fnsize > 0) { 170 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { 171 | offsetCD += fnsize; 172 | } else { 173 | err = Z_ERRNO; 174 | break; 175 | } 176 | } else { 177 | err = Z_STREAM_ERROR; 178 | break; 179 | } 180 | 181 | /* Extra field */ 182 | if (extsize > 0) { 183 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { 184 | offsetCD += extsize; 185 | } else { 186 | err = Z_ERRNO; 187 | break; 188 | } 189 | } 190 | 191 | /* Comment field */ 192 | if (comsize > 0) { 193 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { 194 | offsetCD += comsize; 195 | } else { 196 | err = Z_ERRNO; 197 | break; 198 | } 199 | } 200 | 201 | 202 | } else { 203 | err = Z_ERRNO; 204 | break; 205 | } 206 | } 207 | 208 | /* Success */ 209 | entries++; 210 | 211 | } else { 212 | break; 213 | } 214 | } 215 | 216 | /* Final central directory */ 217 | { 218 | int entriesZip = entries; 219 | char header[22]; 220 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; 221 | int comsize = (int) strlen(comment); 222 | if (entriesZip > 0xffff) { 223 | entriesZip = 0xffff; 224 | } 225 | WRITE_32(header, 0x06054b50); 226 | WRITE_16(header + 4, 0); /* disk # */ 227 | WRITE_16(header + 6, 0); /* disk # */ 228 | WRITE_16(header + 8, entriesZip); /* hack */ 229 | WRITE_16(header + 10, entriesZip); /* hack */ 230 | WRITE_32(header + 12, offsetCD); /* size of CD */ 231 | WRITE_32(header + 16, offset); /* offset to CD */ 232 | WRITE_16(header + 20, comsize); /* comment */ 233 | 234 | /* Header */ 235 | if (fwrite(header, 1, 22, fpOutCD) == 22) { 236 | 237 | /* Comment field */ 238 | if (comsize > 0) { 239 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { 240 | err = Z_ERRNO; 241 | } 242 | } 243 | 244 | } else { 245 | err = Z_ERRNO; 246 | } 247 | } 248 | 249 | /* Final merge (file + central directory) */ 250 | fclose(fpOutCD); 251 | if (err == Z_OK) { 252 | fpOutCD = fopen(fileOutTmp, "rb"); 253 | if (fpOutCD != NULL) { 254 | int nRead; 255 | char buffer[8192]; 256 | while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { 257 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { 258 | err = Z_ERRNO; 259 | break; 260 | } 261 | } 262 | fclose(fpOutCD); 263 | } 264 | } 265 | 266 | /* Close */ 267 | fclose(fpZip); 268 | fclose(fpOut); 269 | 270 | /* Wipe temporary file */ 271 | (void)remove(fileOutTmp); 272 | 273 | /* Number of recovered entries */ 274 | if (err == Z_OK) { 275 | if (nRecovered != NULL) { 276 | *nRecovered = entries; 277 | } 278 | if (bytesRecovered != NULL) { 279 | *bytesRecovered = totalBytes; 280 | } 281 | } 282 | } else { 283 | err = Z_STREAM_ERROR; 284 | } 285 | return err; 286 | } 287 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/mztools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | #ifndef _zip_tools_H 8 | #define _zip_tools_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #if defined(USE_SYSTEM_ZLIB) 15 | #include 16 | #else 17 | #include "zlib.h" 18 | #endif 19 | 20 | #include "unzip.h" 21 | 22 | /* Repair a ZIP file (missing central directory) 23 | file: file to recover 24 | fileOut: output file after recovery 25 | fileOutTmp: temporary file name used for recovery 26 | */ 27 | extern int ZEXPORT unzRepair(const char* file, 28 | const char* fileOut, 29 | const char* fileOutTmp, 30 | uLong* nRecovered, 31 | uLong* bytesRecovered); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/unzip.h: -------------------------------------------------------------------------------- 1 | /* unzip.h -- IO for uncompress .zip files using zlib 2 | Version 1.01e, February 12th, 2005 3 | 4 | Copyright (C) 1998-2005 Gilles Vollant 5 | 6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g 7 | WinZip, InfoZip tools and compatible. 8 | 9 | Multi volume ZipFile (span) are not supported. 10 | Encryption compatible with pkzip 2.04g only supported 11 | Old compressions used by old PKZip 1.x are not supported 12 | 13 | 14 | I WAIT FEEDBACK at mail info@winimage.com 15 | Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution 16 | 17 | Condition of use and distribution are the same than zlib : 18 | 19 | This software is provided 'as-is', without any express or implied 20 | warranty. In no event will the authors be held liable for any damages 21 | arising from the use of this software. 22 | 23 | Permission is granted to anyone to use this software for any purpose, 24 | including commercial applications, and to alter it and redistribute it 25 | freely, subject to the following restrictions: 26 | 27 | 1. The origin of this software must not be misrepresented; you must not 28 | claim that you wrote the original software. If you use this software 29 | in a product, an acknowledgment in the product documentation would be 30 | appreciated but is not required. 31 | 2. Altered source versions must be plainly marked as such, and must not be 32 | misrepresented as being the original software. 33 | 3. This notice may not be removed or altered from any source distribution. 34 | 35 | 36 | */ 37 | 38 | /* for more info about .ZIP format, see 39 | http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip 40 | http://www.info-zip.org/pub/infozip/doc/ 41 | PkWare has also a specification at : 42 | ftp://ftp.pkware.com/probdesc.zip 43 | */ 44 | 45 | #ifndef _unz_H 46 | #define _unz_H 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | #if defined(USE_SYSTEM_ZLIB) 53 | #include 54 | #else 55 | #include "../../zlib.h" 56 | #endif 57 | 58 | #ifndef _ZLIBIOAPI_H 59 | #include "ioapi.h" 60 | #endif 61 | 62 | #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 63 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 64 | from (void*) without cast */ 65 | typedef struct TagunzFile__ { int unused; } unzFile__; 66 | typedef unzFile__ *unzFile; 67 | #else 68 | typedef voidp unzFile; 69 | #endif 70 | 71 | 72 | #define UNZ_OK (0) 73 | #define UNZ_END_OF_LIST_OF_FILE (-100) 74 | #define UNZ_ERRNO (Z_ERRNO) 75 | #define UNZ_EOF (0) 76 | #define UNZ_PARAMERROR (-102) 77 | #define UNZ_BADZIPFILE (-103) 78 | #define UNZ_INTERNALERROR (-104) 79 | #define UNZ_CRCERROR (-105) 80 | 81 | /* tm_unz contain date/time info */ 82 | typedef struct tm_unz_s 83 | { 84 | uInt tm_sec; /* seconds after the minute - [0,59] */ 85 | uInt tm_min; /* minutes after the hour - [0,59] */ 86 | uInt tm_hour; /* hours since midnight - [0,23] */ 87 | uInt tm_mday; /* day of the month - [1,31] */ 88 | uInt tm_mon; /* months since January - [0,11] */ 89 | uInt tm_year; /* years - [1980..2044] */ 90 | } tm_unz; 91 | 92 | /* unz_global_info structure contain global data about the ZIPfile 93 | These data comes from the end of central dir */ 94 | typedef struct unz_global_info_s 95 | { 96 | uLong number_entry; /* total number of entries in 97 | the central dir on this disk */ 98 | uLong size_comment; /* size of the global comment of the zipfile */ 99 | } unz_global_info; 100 | 101 | 102 | /* unz_file_info contain information about a file in the zipfile */ 103 | typedef struct unz_file_info_s 104 | { 105 | uLong version; /* version made by 2 bytes */ 106 | uLong version_needed; /* version needed to extract 2 bytes */ 107 | uLong flag; /* general purpose bit flag 2 bytes */ 108 | uLong compression_method; /* compression method 2 bytes */ 109 | uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ 110 | uLong crc; /* crc-32 4 bytes */ 111 | uLong compressed_size; /* compressed size 4 bytes */ 112 | uLong uncompressed_size; /* uncompressed size 4 bytes */ 113 | uLong size_filename; /* filename length 2 bytes */ 114 | uLong size_file_extra; /* extra field length 2 bytes */ 115 | uLong size_file_comment; /* file comment length 2 bytes */ 116 | 117 | uLong disk_num_start; /* disk number start 2 bytes */ 118 | uLong internal_fa; /* internal file attributes 2 bytes */ 119 | uLong external_fa; /* external file attributes 4 bytes */ 120 | 121 | tm_unz tmu_date; 122 | } unz_file_info; 123 | 124 | extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, 125 | const char* fileName2, 126 | int iCaseSensitivity)); 127 | /* 128 | Compare two filename (fileName1,fileName2). 129 | If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) 130 | If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi 131 | or strcasecmp) 132 | If iCaseSenisivity = 0, case sensitivity is defaut of your operating system 133 | (like 1 on Unix, 2 on Windows) 134 | */ 135 | 136 | 137 | extern unzFile ZEXPORT unzOpen OF((const char *path)); 138 | /* 139 | Open a Zip file. path contain the full pathname (by example, 140 | on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer 141 | "zlib/zlib113.zip". 142 | If the zipfile cannot be opened (file don't exist or in not valid), the 143 | return value is NULL. 144 | Else, the return value is a unzFile Handle, usable with other function 145 | of this unzip package. 146 | */ 147 | 148 | extern unzFile ZEXPORT unzOpen2 OF((const char *path, 149 | zlib_filefunc_def* pzlib_filefunc_def)); 150 | /* 151 | Open a Zip file, like unzOpen, but provide a set of file low level API 152 | for read/write the zip file (see ioapi.h) 153 | */ 154 | 155 | extern int ZEXPORT unzClose OF((unzFile file)); 156 | /* 157 | Close a ZipFile opened with unzipOpen. 158 | If there is files inside the .Zip opened with unzOpenCurrentFile (see later), 159 | these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 160 | return UNZ_OK if there is no problem. */ 161 | 162 | extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, 163 | unz_global_info *pglobal_info)); 164 | /* 165 | Write info about the ZipFile in the *pglobal_info structure. 166 | No preparation of the structure is needed 167 | return UNZ_OK if there is no problem. */ 168 | 169 | 170 | extern int ZEXPORT unzGetGlobalComment OF((unzFile file, 171 | char *szComment, 172 | uLong uSizeBuf)); 173 | /* 174 | Get the global comment string of the ZipFile, in the szComment buffer. 175 | uSizeBuf is the size of the szComment buffer. 176 | return the number of byte copied or an error code <0 177 | */ 178 | 179 | 180 | /***************************************************************************/ 181 | /* Unzip package allow you browse the directory of the zipfile */ 182 | 183 | extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); 184 | /* 185 | Set the current file of the zipfile to the first file. 186 | return UNZ_OK if there is no problem 187 | */ 188 | 189 | extern int ZEXPORT unzGoToNextFile OF((unzFile file)); 190 | /* 191 | Set the current file of the zipfile to the next file. 192 | return UNZ_OK if there is no problem 193 | return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 194 | */ 195 | 196 | extern int ZEXPORT unzLocateFile OF((unzFile file, 197 | const char *szFileName, 198 | int iCaseSensitivity)); 199 | /* 200 | Try locate the file szFileName in the zipfile. 201 | For the iCaseSensitivity signification, see unzStringFileNameCompare 202 | 203 | return value : 204 | UNZ_OK if the file is found. It becomes the current file. 205 | UNZ_END_OF_LIST_OF_FILE if the file is not found 206 | */ 207 | 208 | 209 | /* ****************************************** */ 210 | /* Ryan supplied functions */ 211 | /* unz_file_info contain information about a file in the zipfile */ 212 | typedef struct unz_file_pos_s 213 | { 214 | uLong pos_in_zip_directory; /* offset in zip file directory */ 215 | uLong num_of_file; /* # of file */ 216 | } unz_file_pos; 217 | 218 | extern int ZEXPORT unzGetFilePos( 219 | unzFile file, 220 | unz_file_pos* file_pos); 221 | 222 | extern int ZEXPORT unzGoToFilePos( 223 | unzFile file, 224 | unz_file_pos* file_pos); 225 | 226 | /* ****************************************** */ 227 | 228 | extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, 229 | unz_file_info *pfile_info, 230 | char *szFileName, 231 | uLong fileNameBufferSize, 232 | void *extraField, 233 | uLong extraFieldBufferSize, 234 | char *szComment, 235 | uLong commentBufferSize)); 236 | /* 237 | Get Info about the current file 238 | if pfile_info!=NULL, the *pfile_info structure will contain somes info about 239 | the current file 240 | if szFileName!=NULL, the filemane string will be copied in szFileName 241 | (fileNameBufferSize is the size of the buffer) 242 | if extraField!=NULL, the extra field information will be copied in extraField 243 | (extraFieldBufferSize is the size of the buffer). 244 | This is the Central-header version of the extra field 245 | if szComment!=NULL, the comment string of the file will be copied in szComment 246 | (commentBufferSize is the size of the buffer) 247 | */ 248 | 249 | /***************************************************************************/ 250 | /* for reading the content of the current zipfile, you can open it, read data 251 | from it, and close it (you can close it before reading all the file) 252 | */ 253 | 254 | extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); 255 | /* 256 | Open for reading data the current file in the zipfile. 257 | If there is no error, the return value is UNZ_OK. 258 | */ 259 | 260 | extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, 261 | const char* password)); 262 | /* 263 | Open for reading data the current file in the zipfile. 264 | password is a crypting password 265 | If there is no error, the return value is UNZ_OK. 266 | */ 267 | 268 | extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, 269 | int* method, 270 | int* level, 271 | int raw)); 272 | /* 273 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 274 | if raw==1 275 | *method will receive method of compression, *level will receive level of 276 | compression 277 | note : you can set level parameter as NULL (if you did not want known level, 278 | but you CANNOT set method parameter as NULL 279 | */ 280 | 281 | extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, 282 | int* method, 283 | int* level, 284 | int raw, 285 | const char* password)); 286 | /* 287 | Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) 288 | if raw==1 289 | *method will receive method of compression, *level will receive level of 290 | compression 291 | note : you can set level parameter as NULL (if you did not want known level, 292 | but you CANNOT set method parameter as NULL 293 | */ 294 | 295 | 296 | extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); 297 | /* 298 | Close the file in zip opened with unzOpenCurrentFile 299 | Return UNZ_CRCERROR if all the file was read but the CRC is not good 300 | */ 301 | 302 | extern int ZEXPORT unzReadCurrentFile OF((unzFile file, 303 | voidp buf, 304 | unsigned len)); 305 | /* 306 | Read bytes from the current file (opened by unzOpenCurrentFile) 307 | buf contain buffer where data must be copied 308 | len the size of buf. 309 | 310 | return the number of byte copied if somes bytes are copied 311 | return 0 if the end of file was reached 312 | return <0 with error code if there is an error 313 | (UNZ_ERRNO for IO error, or zLib error for uncompress error) 314 | */ 315 | 316 | extern z_off_t ZEXPORT unztell OF((unzFile file)); 317 | /* 318 | Give the current position in uncompressed data 319 | */ 320 | 321 | extern int ZEXPORT unzeof OF((unzFile file)); 322 | /* 323 | return 1 if the end of file was reached, 0 elsewhere 324 | */ 325 | 326 | extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, 327 | voidp buf, 328 | unsigned len)); 329 | /* 330 | Read extra field from the current file (opened by unzOpenCurrentFile) 331 | This is the local-header version of the extra field (sometimes, there is 332 | more info in the local-header version than in the central-header) 333 | 334 | if buf==NULL, it return the size of the local extra field 335 | 336 | if buf!=NULL, len is the size of the buffer, the extra header is copied in 337 | buf. 338 | the return value is the number of bytes copied in buf, or (if <0) 339 | the error code 340 | */ 341 | 342 | /***************************************************************************/ 343 | 344 | /* Get the current file offset */ 345 | extern uLong ZEXPORT unzGetOffset (unzFile file); 346 | 347 | /* Set the current file offset */ 348 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); 349 | 350 | 351 | 352 | #ifdef __cplusplus 353 | } 354 | #endif 355 | 356 | #endif /* _unz_H */ 357 | -------------------------------------------------------------------------------- /src/zlib/contrib/minizip/zip.h: -------------------------------------------------------------------------------- 1 | /* zip.h -- IO for compress .zip files using zlib 2 | Version 1.01e, February 12th, 2005 3 | 4 | Copyright (C) 1998-2005 Gilles Vollant 5 | 6 | This unzip package allow creates .ZIP file, compatible with PKZip 2.04g 7 | WinZip, InfoZip tools and compatible. 8 | Multi volume ZipFile (span) are not supported. 9 | Encryption compatible with pkzip 2.04g only supported 10 | Old compressions used by old PKZip 1.x are not supported 11 | 12 | For uncompress .zip file, look at unzip.h 13 | 14 | 15 | I WAIT FEEDBACK at mail info@winimage.com 16 | Visit also http://www.winimage.com/zLibDll/unzip.html for evolution 17 | 18 | Condition of use and distribution are the same than zlib : 19 | 20 | This software is provided 'as-is', without any express or implied 21 | warranty. In no event will the authors be held liable for any damages 22 | arising from the use of this software. 23 | 24 | Permission is granted to anyone to use this software for any purpose, 25 | including commercial applications, and to alter it and redistribute it 26 | freely, subject to the following restrictions: 27 | 28 | 1. The origin of this software must not be misrepresented; you must not 29 | claim that you wrote the original software. If you use this software 30 | in a product, an acknowledgment in the product documentation would be 31 | appreciated but is not required. 32 | 2. Altered source versions must be plainly marked as such, and must not be 33 | misrepresented as being the original software. 34 | 3. This notice may not be removed or altered from any source distribution. 35 | 36 | 37 | */ 38 | 39 | /* for more info about .ZIP format, see 40 | http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip 41 | http://www.info-zip.org/pub/infozip/doc/ 42 | PkWare has also a specification at : 43 | ftp://ftp.pkware.com/probdesc.zip 44 | */ 45 | 46 | #ifndef _zip_H 47 | #define _zip_H 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | #if defined(USE_SYSTEM_ZLIB) 54 | #include 55 | #else 56 | #include "../../zlib.h" 57 | #endif 58 | 59 | #ifndef _ZLIBIOAPI_H 60 | #include "ioapi.h" 61 | #endif 62 | 63 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 64 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 65 | from (void*) without cast */ 66 | typedef struct TagzipFile__ { int unused; } zipFile__; 67 | typedef zipFile__ *zipFile; 68 | #else 69 | typedef voidp zipFile; 70 | #endif 71 | 72 | #define ZIP_OK (0) 73 | #define ZIP_EOF (0) 74 | #define ZIP_ERRNO (Z_ERRNO) 75 | #define ZIP_PARAMERROR (-102) 76 | #define ZIP_BADZIPFILE (-103) 77 | #define ZIP_INTERNALERROR (-104) 78 | 79 | #ifndef DEF_MEM_LEVEL 80 | # if MAX_MEM_LEVEL >= 8 81 | # define DEF_MEM_LEVEL 8 82 | # else 83 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 84 | # endif 85 | #endif 86 | /* default memLevel */ 87 | 88 | /* tm_zip contain date/time info */ 89 | typedef struct tm_zip_s 90 | { 91 | uInt tm_sec; /* seconds after the minute - [0,59] */ 92 | uInt tm_min; /* minutes after the hour - [0,59] */ 93 | uInt tm_hour; /* hours since midnight - [0,23] */ 94 | uInt tm_mday; /* day of the month - [1,31] */ 95 | uInt tm_mon; /* months since January - [0,11] */ 96 | uInt tm_year; /* years - [1980..2044] */ 97 | } tm_zip; 98 | 99 | typedef struct 100 | { 101 | tm_zip tmz_date; /* date in understandable format */ 102 | uLong dosDate; /* if dos_date == 0, tmu_date is used */ 103 | /* uLong flag; */ /* general purpose bit flag 2 bytes */ 104 | 105 | uLong internal_fa; /* internal file attributes 2 bytes */ 106 | uLong external_fa; /* external file attributes 4 bytes */ 107 | } zip_fileinfo; 108 | 109 | typedef const char* zipcharpc; 110 | 111 | 112 | #define APPEND_STATUS_CREATE (0) 113 | #define APPEND_STATUS_CREATEAFTER (1) 114 | #define APPEND_STATUS_ADDINZIP (2) 115 | 116 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 117 | /* 118 | Create a zipfile. 119 | pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on 120 | an Unix computer "zlib/zlib113.zip". 121 | if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip 122 | will be created at the end of the file. 123 | (useful if the file contain a self extractor code) 124 | if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will 125 | add files in existing zip (be sure you don't add file that doesn't exist) 126 | If the zipfile cannot be opened, the return value is NULL. 127 | Else, the return value is a zipFile Handle, usable with other function 128 | of this zip package. 129 | */ 130 | 131 | /* Note : there is no delete function into a zipfile. 132 | If you want delete file into a zipfile, you must open a zipfile, and create another 133 | Of couse, you can use RAW reading and writing to copy the file you did not want delte 134 | */ 135 | 136 | extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, 137 | int append, 138 | zipcharpc* globalcomment, 139 | zlib_filefunc_def* pzlib_filefunc_def)); 140 | 141 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, 142 | const char* filename, 143 | const zip_fileinfo* zipfi, 144 | const void* extrafield_local, 145 | uInt size_extrafield_local, 146 | const void* extrafield_global, 147 | uInt size_extrafield_global, 148 | const char* comment, 149 | int method, 150 | int level)); 151 | /* 152 | Open a file in the ZIP for writing. 153 | filename : the filename in zip (if NULL, '-' without quote will be used 154 | *zipfi contain supplemental information 155 | if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local 156 | contains the extrafield data the the local header 157 | if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global 158 | contains the extrafield data the the local header 159 | if comment != NULL, comment contain the comment string 160 | method contain the compression method (0 for store, Z_DEFLATED for deflate) 161 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 162 | */ 163 | 164 | 165 | extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, 166 | const char* filename, 167 | const zip_fileinfo* zipfi, 168 | const void* extrafield_local, 169 | uInt size_extrafield_local, 170 | const void* extrafield_global, 171 | uInt size_extrafield_global, 172 | const char* comment, 173 | int method, 174 | int level, 175 | int raw)); 176 | 177 | /* 178 | Same than zipOpenNewFileInZip, except if raw=1, we write raw file 179 | */ 180 | 181 | extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, 182 | const char* filename, 183 | const zip_fileinfo* zipfi, 184 | const void* extrafield_local, 185 | uInt size_extrafield_local, 186 | const void* extrafield_global, 187 | uInt size_extrafield_global, 188 | const char* comment, 189 | int method, 190 | int level, 191 | int raw, 192 | int windowBits, 193 | int memLevel, 194 | int strategy, 195 | const char* password, 196 | uLong crcForCtypting)); 197 | 198 | /* 199 | Same than zipOpenNewFileInZip2, except 200 | windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 201 | password : crypting password (NULL for no crypting) 202 | crcForCtypting : crc of file to compress (needed for crypting) 203 | */ 204 | 205 | 206 | extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, 207 | const void* buf, 208 | unsigned len)); 209 | /* 210 | Write data in the zipfile 211 | */ 212 | 213 | extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 214 | /* 215 | Close the current file in the zipfile 216 | */ 217 | 218 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, 219 | uLong uncompressed_size, 220 | uLong crc32)); 221 | /* 222 | Close the current file in the zipfile, for fiel opened with 223 | parameter raw=1 in zipOpenNewFileInZip2 224 | uncompressed_size and crc32 are value for the uncompressed size 225 | */ 226 | 227 | extern int ZEXPORT zipClose OF((zipFile file, 228 | const char* global_comment)); 229 | /* 230 | Close the zipfile 231 | */ 232 | 233 | #ifdef __cplusplus 234 | } 235 | #endif 236 | 237 | #endif /* _zip_H */ 238 | -------------------------------------------------------------------------------- /src/zlib/deflate.h: -------------------------------------------------------------------------------- 1 | /* deflate.h -- internal compression state 2 | * Copyright (C) 1995-2004 Jean-loup Gailly 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id: deflate.h,v 3.6 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 12 | 13 | #ifndef DEFLATE_H 14 | #define DEFLATE_H 15 | 16 | #include "zutil.h" 17 | 18 | /* define NO_GZIP when compiling if you want to disable gzip header and 19 | trailer creation by deflate(). NO_GZIP would be used to avoid linking in 20 | the crc code when it is not needed. For shared libraries, gzip encoding 21 | should be left enabled. */ 22 | #ifndef NO_GZIP 23 | # define GZIP 24 | #endif 25 | 26 | /* =========================================================================== 27 | * Internal compression state. 28 | */ 29 | 30 | #define LENGTH_CODES 29 31 | /* number of length codes, not counting the special END_BLOCK code */ 32 | 33 | #define LITERALS 256 34 | /* number of literal bytes 0..255 */ 35 | 36 | #define L_CODES (LITERALS+1+LENGTH_CODES) 37 | /* number of Literal or Length codes, including the END_BLOCK code */ 38 | 39 | #define D_CODES 30 40 | /* number of distance codes */ 41 | 42 | #define BL_CODES 19 43 | /* number of codes used to transfer the bit lengths */ 44 | 45 | #define HEAP_SIZE (2*L_CODES+1) 46 | /* maximum heap size */ 47 | 48 | #define MAX_BITS 15 49 | /* All codes must not exceed MAX_BITS bits */ 50 | 51 | #define INIT_STATE 42 52 | #define EXTRA_STATE 69 53 | #define NAME_STATE 73 54 | #define COMMENT_STATE 91 55 | #define HCRC_STATE 103 56 | #define BUSY_STATE 113 57 | #define FINISH_STATE 666 58 | /* Stream status */ 59 | 60 | 61 | /* Data structure describing a single value and its code string. */ 62 | typedef struct ct_data_s { 63 | union { 64 | ush freq; /* frequency count */ 65 | ush code; /* bit string */ 66 | } fc; 67 | union { 68 | ush dad; /* father node in Huffman tree */ 69 | ush len; /* length of bit string */ 70 | } dl; 71 | } FAR ct_data; 72 | 73 | #define Freq fc.freq 74 | #define Code fc.code 75 | #define Dad dl.dad 76 | #define Len dl.len 77 | 78 | typedef struct static_tree_desc_s static_tree_desc; 79 | 80 | typedef struct tree_desc_s { 81 | ct_data *dyn_tree; /* the dynamic tree */ 82 | int max_code; /* largest code with non zero frequency */ 83 | static_tree_desc *stat_desc; /* the corresponding static tree */ 84 | } FAR tree_desc; 85 | 86 | typedef ush Pos; 87 | typedef Pos FAR Posf; 88 | typedef unsigned IPos; 89 | 90 | /* A Pos is an index in the character window. We use short instead of int to 91 | * save space in the various tables. IPos is used only for parameter passing. 92 | */ 93 | 94 | typedef struct internal_state { 95 | z_streamp strm; /* pointer back to this zlib stream */ 96 | int status; /* as the name implies */ 97 | Bytef *pending_buf; /* output still pending */ 98 | ulg pending_buf_size; /* size of pending_buf */ 99 | Bytef *pending_out; /* next pending byte to output to the stream */ 100 | uInt pending; /* nb of bytes in the pending buffer */ 101 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 102 | gz_headerp gzhead; /* gzip header information to write */ 103 | uInt gzindex; /* where in extra, name, or comment */ 104 | Byte method; /* STORED (for zip only) or DEFLATED */ 105 | int last_flush; /* value of flush param for previous deflate call */ 106 | 107 | /* used by deflate.c: */ 108 | 109 | uInt w_size; /* LZ77 window size (32K by default) */ 110 | uInt w_bits; /* log2(w_size) (8..16) */ 111 | uInt w_mask; /* w_size - 1 */ 112 | 113 | Bytef *window; 114 | /* Sliding window. Input bytes are read into the second half of the window, 115 | * and move to the first half later to keep a dictionary of at least wSize 116 | * bytes. With this organization, matches are limited to a distance of 117 | * wSize-MAX_MATCH bytes, but this ensures that IO is always 118 | * performed with a length multiple of the block size. Also, it limits 119 | * the window size to 64K, which is quite useful on MSDOS. 120 | * To do: use the user input buffer as sliding window. 121 | */ 122 | 123 | ulg window_size; 124 | /* Actual size of window: 2*wSize, except when the user input buffer 125 | * is directly used as sliding window. 126 | */ 127 | 128 | Posf *prev; 129 | /* Link to older string with same hash index. To limit the size of this 130 | * array to 64K, this link is maintained only for the last 32K strings. 131 | * An index in this array is thus a window index modulo 32K. 132 | */ 133 | 134 | Posf *head; /* Heads of the hash chains or NIL. */ 135 | 136 | uInt ins_h; /* hash index of string to be inserted */ 137 | uInt hash_size; /* number of elements in hash table */ 138 | uInt hash_bits; /* log2(hash_size) */ 139 | uInt hash_mask; /* hash_size-1 */ 140 | 141 | uInt hash_shift; 142 | /* Number of bits by which ins_h must be shifted at each input 143 | * step. It must be such that after MIN_MATCH steps, the oldest 144 | * byte no longer takes part in the hash key, that is: 145 | * hash_shift * MIN_MATCH >= hash_bits 146 | */ 147 | 148 | long block_start; 149 | /* Window position at the beginning of the current output block. Gets 150 | * negative when the window is moved backwards. 151 | */ 152 | 153 | uInt match_length; /* length of best match */ 154 | IPos prev_match; /* previous match */ 155 | int match_available; /* set if previous match exists */ 156 | uInt strstart; /* start of string to insert */ 157 | uInt match_start; /* start of matching string */ 158 | uInt lookahead; /* number of valid bytes ahead in window */ 159 | 160 | uInt prev_length; 161 | /* Length of the best match at previous step. Matches not greater than this 162 | * are discarded. This is used in the lazy match evaluation. 163 | */ 164 | 165 | uInt max_chain_length; 166 | /* To speed up deflation, hash chains are never searched beyond this 167 | * length. A higher limit improves compression ratio but degrades the 168 | * speed. 169 | */ 170 | 171 | uInt max_lazy_match; 172 | /* Attempt to find a better match only when the current match is strictly 173 | * smaller than this value. This mechanism is used only for compression 174 | * levels >= 4. 175 | */ 176 | # define max_insert_length max_lazy_match 177 | /* Insert new strings in the hash table only if the match length is not 178 | * greater than this length. This saves time but degrades compression. 179 | * max_insert_length is used only for compression levels <= 3. 180 | */ 181 | 182 | int level; /* compression level (1..9) */ 183 | int strategy; /* favor or force Huffman coding*/ 184 | 185 | uInt good_match; 186 | /* Use a faster search when the previous match is longer than this */ 187 | 188 | int nice_match; /* Stop searching when current match exceeds this */ 189 | 190 | /* used by trees.c: */ 191 | /* Didn't use ct_data typedef below to supress compiler warning */ 192 | struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ 193 | struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ 194 | struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ 195 | 196 | struct tree_desc_s l_desc; /* desc. for literal tree */ 197 | struct tree_desc_s d_desc; /* desc. for distance tree */ 198 | struct tree_desc_s bl_desc; /* desc. for bit length tree */ 199 | 200 | ush bl_count[MAX_BITS+1]; 201 | /* number of codes at each bit length for an optimal tree */ 202 | 203 | int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ 204 | int heap_len; /* number of elements in the heap */ 205 | int heap_max; /* element of largest frequency */ 206 | /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. 207 | * The same heap array is used to build all trees. 208 | */ 209 | 210 | uch depth[2*L_CODES+1]; 211 | /* Depth of each subtree used as tie breaker for trees of equal frequency 212 | */ 213 | 214 | uchf *l_buf; /* buffer for literals or lengths */ 215 | 216 | uInt lit_bufsize; 217 | /* Size of match buffer for literals/lengths. There are 4 reasons for 218 | * limiting lit_bufsize to 64K: 219 | * - frequencies can be kept in 16 bit counters 220 | * - if compression is not successful for the first block, all input 221 | * data is still in the window so we can still emit a stored block even 222 | * when input comes from standard input. (This can also be done for 223 | * all blocks if lit_bufsize is not greater than 32K.) 224 | * - if compression is not successful for a file smaller than 64K, we can 225 | * even emit a stored file instead of a stored block (saving 5 bytes). 226 | * This is applicable only for zip (not gzip or zlib). 227 | * - creating new Huffman trees less frequently may not provide fast 228 | * adaptation to changes in the input data statistics. (Take for 229 | * example a binary file with poorly compressible code followed by 230 | * a highly compressible string table.) Smaller buffer sizes give 231 | * fast adaptation but have of course the overhead of transmitting 232 | * trees more frequently. 233 | * - I can't count above 4 234 | */ 235 | 236 | uInt last_lit; /* running index in l_buf */ 237 | 238 | ushf *d_buf; 239 | /* Buffer for distances. To simplify the code, d_buf and l_buf have 240 | * the same number of elements. To use different lengths, an extra flag 241 | * array would be necessary. 242 | */ 243 | 244 | ulg opt_len; /* bit length of current block with optimal trees */ 245 | ulg static_len; /* bit length of current block with static trees */ 246 | uInt matches; /* number of string matches in current block */ 247 | int last_eob_len; /* bit length of EOB code for last block */ 248 | 249 | #ifdef DEBUG 250 | ulg compressed_len; /* total bit length of compressed file mod 2^32 */ 251 | ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ 252 | #endif 253 | 254 | ush bi_buf; 255 | /* Output buffer. bits are inserted starting at the bottom (least 256 | * significant bits). 257 | */ 258 | int bi_valid; 259 | /* Number of valid bits in bi_buf. All bits above the last valid bit 260 | * are always zero. 261 | */ 262 | 263 | } FAR deflate_state; 264 | 265 | /* Output a byte on the stream. 266 | * IN assertion: there is enough room in pending_buf. 267 | */ 268 | #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} 269 | 270 | 271 | #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) 272 | /* Minimum amount of lookahead, except at the end of the input file. 273 | * See deflate.c for comments about the MIN_MATCH+1. 274 | */ 275 | 276 | #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) 277 | /* In order to simplify the code, particularly on 16 bit machines, match 278 | * distances are limited to MAX_DIST instead of WSIZE. 279 | */ 280 | 281 | /* in trees.c */ 282 | void _tr_init OF((deflate_state *s)); 283 | int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 284 | void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, 285 | int eof)); 286 | void _tr_align OF((deflate_state *s)); 287 | void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, 288 | int eof)); 289 | 290 | #define d_code(dist) \ 291 | ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) 292 | /* Mapping from a distance to a distance code. dist is the distance - 1 and 293 | * must not have side effects. _dist_code[256] and _dist_code[257] are never 294 | * used. 295 | */ 296 | 297 | #ifndef DEBUG 298 | /* Inline versions of _tr_tally for speed: */ 299 | 300 | #if defined(GEN_TREES_H) || !defined(STDC) 301 | extern uch _length_code[]; 302 | extern uch _dist_code[]; 303 | #else 304 | extern const uch _length_code[]; 305 | extern const uch _dist_code[]; 306 | #endif 307 | 308 | # define _tr_tally_lit(s, c, flush) \ 309 | { uch cc = (c); \ 310 | s->d_buf[s->last_lit] = 0; \ 311 | s->l_buf[s->last_lit++] = cc; \ 312 | s->dyn_ltree[cc].Freq++; \ 313 | flush = (s->last_lit == s->lit_bufsize-1); \ 314 | } 315 | # define _tr_tally_dist(s, distance, length, flush) \ 316 | { uch len = (length); \ 317 | ush dist = (distance); \ 318 | s->d_buf[s->last_lit] = dist; \ 319 | s->l_buf[s->last_lit++] = len; \ 320 | dist--; \ 321 | s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ 322 | s->dyn_dtree[d_code(dist)].Freq++; \ 323 | flush = (s->last_lit == s->lit_bufsize-1); \ 324 | } 325 | #else 326 | # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) 327 | # define _tr_tally_dist(s, distance, length, flush) \ 328 | flush = _tr_tally(s, distance, length) 329 | #endif 330 | 331 | #endif /* DEFLATE_H */ 332 | -------------------------------------------------------------------------------- /src/zlib/inffast.c: -------------------------------------------------------------------------------- 1 | /* inffast.c -- fast decoding 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "inftrees.h" 8 | #include "inflate.h" 9 | #include "inffast.h" 10 | 11 | #ifndef ASMINF 12 | 13 | /* Allow machine dependent optimization for post-increment or pre-increment. 14 | Based on testing to date, 15 | Pre-increment preferred for: 16 | - PowerPC G3 (Adler) 17 | - MIPS R5000 (Randers-Pehrson) 18 | Post-increment preferred for: 19 | - none 20 | No measurable difference: 21 | - Pentium III (Anderson) 22 | - M68060 (Nikl) 23 | */ 24 | #ifdef POSTINC 25 | # define OFF 0 26 | # define PUP(a) *(a)++ 27 | #else 28 | # define OFF 1 29 | # define PUP(a) *++(a) 30 | #endif 31 | 32 | /* 33 | Decode literal, length, and distance codes and write out the resulting 34 | literal and match bytes until either not enough input or output is 35 | available, an end-of-block is encountered, or a data error is encountered. 36 | When large enough input and output buffers are supplied to inflate(), for 37 | example, a 16K input buffer and a 64K output buffer, more than 95% of the 38 | inflate execution time is spent in this routine. 39 | 40 | Entry assumptions: 41 | 42 | state->mode == LEN 43 | strm->avail_in >= 6 44 | strm->avail_out >= 258 45 | start >= strm->avail_out 46 | state->bits < 8 47 | 48 | On return, state->mode is one of: 49 | 50 | LEN -- ran out of enough output space or enough available input 51 | TYPE -- reached end of block code, inflate() to interpret next block 52 | BAD -- error in block data 53 | 54 | Notes: 55 | 56 | - The maximum input bits used by a length/distance pair is 15 bits for the 57 | length code, 5 bits for the length extra, 15 bits for the distance code, 58 | and 13 bits for the distance extra. This totals 48 bits, or six bytes. 59 | Therefore if strm->avail_in >= 6, then there is enough input to avoid 60 | checking for available input while decoding. 61 | 62 | - The maximum bytes that a single length/distance pair can output is 258 63 | bytes, which is the maximum length that can be coded. inflate_fast() 64 | requires strm->avail_out >= 258 for each loop to avoid checking for 65 | output space. 66 | */ 67 | void inflate_fast(strm, start) 68 | z_streamp strm; 69 | unsigned start; /* inflate()'s starting value for strm->avail_out */ 70 | { 71 | struct inflate_state FAR *state; 72 | unsigned char FAR *in; /* local strm->next_in */ 73 | unsigned char FAR *last; /* while in < last, enough input available */ 74 | unsigned char FAR *out; /* local strm->next_out */ 75 | unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ 76 | unsigned char FAR *end; /* while out < end, enough space available */ 77 | #ifdef INFLATE_STRICT 78 | unsigned dmax; /* maximum distance from zlib header */ 79 | #endif 80 | unsigned wsize; /* window size or zero if not using window */ 81 | unsigned whave; /* valid bytes in the window */ 82 | unsigned write; /* window write index */ 83 | unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ 84 | unsigned long hold; /* local strm->hold */ 85 | unsigned bits; /* local strm->bits */ 86 | code const FAR *lcode; /* local strm->lencode */ 87 | code const FAR *dcode; /* local strm->distcode */ 88 | unsigned lmask; /* mask for first level of length codes */ 89 | unsigned dmask; /* mask for first level of distance codes */ 90 | code this; /* retrieved table entry */ 91 | unsigned op; /* code bits, operation, extra bits, or */ 92 | /* window position, window bytes to copy */ 93 | unsigned len; /* match length, unused bytes */ 94 | unsigned dist; /* match distance */ 95 | unsigned char FAR *from; /* where to copy match from */ 96 | 97 | /* copy state to local variables */ 98 | state = (struct inflate_state FAR *)strm->state; 99 | in = strm->next_in - OFF; 100 | last = in + (strm->avail_in - 5); 101 | out = strm->next_out - OFF; 102 | beg = out - (start - strm->avail_out); 103 | end = out + (strm->avail_out - 257); 104 | #ifdef INFLATE_STRICT 105 | dmax = state->dmax; 106 | #endif 107 | wsize = state->wsize; 108 | whave = state->whave; 109 | write = state->write; 110 | window = state->window; 111 | hold = state->hold; 112 | bits = state->bits; 113 | lcode = state->lencode; 114 | dcode = state->distcode; 115 | lmask = (1U << state->lenbits) - 1; 116 | dmask = (1U << state->distbits) - 1; 117 | 118 | /* decode literals and length/distances until end-of-block or not enough 119 | input data or output space */ 120 | do { 121 | if (bits < 15) { 122 | hold += (unsigned long)(PUP(in)) << bits; 123 | bits += 8; 124 | hold += (unsigned long)(PUP(in)) << bits; 125 | bits += 8; 126 | } 127 | this = lcode[hold & lmask]; 128 | dolen: 129 | op = (unsigned)(this.bits); 130 | hold >>= op; 131 | bits -= op; 132 | op = (unsigned)(this.op); 133 | if (op == 0) { /* literal */ 134 | Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ? 135 | "inflate: literal '%c'\n" : 136 | "inflate: literal 0x%02x\n", this.val)); 137 | PUP(out) = (unsigned char)(this.val); 138 | } 139 | else if (op & 16) { /* length base */ 140 | len = (unsigned)(this.val); 141 | op &= 15; /* number of extra bits */ 142 | if (op) { 143 | if (bits < op) { 144 | hold += (unsigned long)(PUP(in)) << bits; 145 | bits += 8; 146 | } 147 | len += (unsigned)hold & ((1U << op) - 1); 148 | hold >>= op; 149 | bits -= op; 150 | } 151 | Tracevv((stderr, "inflate: length %u\n", len)); 152 | if (bits < 15) { 153 | hold += (unsigned long)(PUP(in)) << bits; 154 | bits += 8; 155 | hold += (unsigned long)(PUP(in)) << bits; 156 | bits += 8; 157 | } 158 | this = dcode[hold & dmask]; 159 | dodist: 160 | op = (unsigned)(this.bits); 161 | hold >>= op; 162 | bits -= op; 163 | op = (unsigned)(this.op); 164 | if (op & 16) { /* distance base */ 165 | dist = (unsigned)(this.val); 166 | op &= 15; /* number of extra bits */ 167 | if (bits < op) { 168 | hold += (unsigned long)(PUP(in)) << bits; 169 | bits += 8; 170 | if (bits < op) { 171 | hold += (unsigned long)(PUP(in)) << bits; 172 | bits += 8; 173 | } 174 | } 175 | dist += (unsigned)hold & ((1U << op) - 1); 176 | #ifdef INFLATE_STRICT 177 | if (dist > dmax) { 178 | strm->msg = (char *)"invalid distance too far back"; 179 | state->mode = BAD; 180 | break; 181 | } 182 | #endif 183 | hold >>= op; 184 | bits -= op; 185 | Tracevv((stderr, "inflate: distance %u\n", dist)); 186 | op = (unsigned)(out - beg); /* max distance in output */ 187 | if (dist > op) { /* see if copy from window */ 188 | op = dist - op; /* distance back in window */ 189 | if (op > whave) { 190 | strm->msg = (char *)"invalid distance too far back"; 191 | state->mode = BAD; 192 | break; 193 | } 194 | from = window - OFF; 195 | if (write == 0) { /* very common case */ 196 | from += wsize - op; 197 | if (op < len) { /* some from window */ 198 | len -= op; 199 | do { 200 | PUP(out) = PUP(from); 201 | } while (--op); 202 | from = out - dist; /* rest from output */ 203 | } 204 | } 205 | else if (write < op) { /* wrap around window */ 206 | from += wsize + write - op; 207 | op -= write; 208 | if (op < len) { /* some from end of window */ 209 | len -= op; 210 | do { 211 | PUP(out) = PUP(from); 212 | } while (--op); 213 | from = window - OFF; 214 | if (write < len) { /* some from start of window */ 215 | op = write; 216 | len -= op; 217 | do { 218 | PUP(out) = PUP(from); 219 | } while (--op); 220 | from = out - dist; /* rest from output */ 221 | } 222 | } 223 | } 224 | else { /* contiguous in window */ 225 | from += write - op; 226 | if (op < len) { /* some from window */ 227 | len -= op; 228 | do { 229 | PUP(out) = PUP(from); 230 | } while (--op); 231 | from = out - dist; /* rest from output */ 232 | } 233 | } 234 | while (len > 2) { 235 | PUP(out) = PUP(from); 236 | PUP(out) = PUP(from); 237 | PUP(out) = PUP(from); 238 | len -= 3; 239 | } 240 | if (len) { 241 | PUP(out) = PUP(from); 242 | if (len > 1) 243 | PUP(out) = PUP(from); 244 | } 245 | } 246 | else { 247 | from = out - dist; /* copy direct from output */ 248 | do { /* minimum length is three */ 249 | PUP(out) = PUP(from); 250 | PUP(out) = PUP(from); 251 | PUP(out) = PUP(from); 252 | len -= 3; 253 | } while (len > 2); 254 | if (len) { 255 | PUP(out) = PUP(from); 256 | if (len > 1) 257 | PUP(out) = PUP(from); 258 | } 259 | } 260 | } 261 | else if ((op & 64) == 0) { /* 2nd level distance code */ 262 | this = dcode[this.val + (hold & ((1U << op) - 1))]; 263 | goto dodist; 264 | } 265 | else { 266 | strm->msg = (char *)"invalid distance code"; 267 | state->mode = BAD; 268 | break; 269 | } 270 | } 271 | else if ((op & 64) == 0) { /* 2nd level length code */ 272 | this = lcode[this.val + (hold & ((1U << op) - 1))]; 273 | goto dolen; 274 | } 275 | else if (op & 32) { /* end-of-block */ 276 | Tracevv((stderr, "inflate: end of block\n")); 277 | state->mode = TYPE; 278 | break; 279 | } 280 | else { 281 | strm->msg = (char *)"invalid literal/length code"; 282 | state->mode = BAD; 283 | break; 284 | } 285 | } while (in < last && out < end); 286 | 287 | /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ 288 | len = bits >> 3; 289 | in -= len; 290 | bits -= len << 3; 291 | hold &= (1U << bits) - 1; 292 | 293 | /* update state and return */ 294 | strm->next_in = in + OFF; 295 | strm->next_out = out + OFF; 296 | strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); 297 | strm->avail_out = (unsigned)(out < end ? 298 | 257 + (end - out) : 257 - (out - end)); 299 | state->hold = hold; 300 | state->bits = bits; 301 | return; 302 | } 303 | 304 | /* 305 | inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): 306 | - Using bit fields for code structure 307 | - Different op definition to avoid & for extra bits (do & for table bits) 308 | - Three separate decoding do-loops for direct, window, and write == 0 309 | - Special case for distance > 1 copies to do overlapped load and store copy 310 | - Explicit branch predictions (based on measured branch probabilities) 311 | - Deferring match copy and interspersed it with decoding subsequent codes 312 | - Swapping literal/length else 313 | - Swapping window/direct else 314 | - Larger unrolled copy loops (three is about right) 315 | - Moving len -= 3 statement into middle of loop 316 | */ 317 | 318 | #endif /* !ASMINF */ 319 | -------------------------------------------------------------------------------- /src/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /src/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. It 6 | is part of the implementation of the compression library and 7 | is subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /src/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY, /* i/o: waiting for input or output to copy stored block */ 36 | TABLE, /* i: waiting for dynamic block table lengths */ 37 | LENLENS, /* i: waiting for code length code lengths */ 38 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 39 | LEN, /* i: waiting for length/lit code */ 40 | LENEXT, /* i: waiting for length extra bits */ 41 | DIST, /* i: waiting for distance code */ 42 | DISTEXT, /* i: waiting for distance extra bits */ 43 | MATCH, /* o: waiting for output space to copy string */ 44 | LIT, /* o: waiting for output space to write literal */ 45 | CHECK, /* i: waiting for 32-bit check value */ 46 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 47 | DONE, /* finished check, done -- remain here until reset */ 48 | BAD, /* got a data error -- remain here until reset */ 49 | MEM, /* got an inflate() memory error -- remain here until reset */ 50 | SYNC /* looking for synchronization bytes to restart inflate() */ 51 | } inflate_mode; 52 | 53 | /* 54 | State transitions between above modes - 55 | 56 | (most modes can go to the BAD or MEM mode -- not shown for clarity) 57 | 58 | Process header: 59 | HEAD -> (gzip) or (zlib) 60 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 61 | NAME -> COMMENT -> HCRC -> TYPE 62 | (zlib) -> DICTID or TYPE 63 | DICTID -> DICT -> TYPE 64 | Read deflate blocks: 65 | TYPE -> STORED or TABLE or LEN or CHECK 66 | STORED -> COPY -> TYPE 67 | TABLE -> LENLENS -> CODELENS -> LEN 68 | Read deflate codes: 69 | LEN -> LENEXT or LIT or TYPE 70 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 71 | LIT -> LEN 72 | Process trailer: 73 | CHECK -> LENGTH -> DONE 74 | */ 75 | 76 | /* state maintained between inflate() calls. Approximately 7K bytes. */ 77 | struct inflate_state { 78 | inflate_mode mode; /* current inflate mode */ 79 | int last; /* true if processing last block */ 80 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 81 | int havedict; /* true if dictionary provided */ 82 | int flags; /* gzip header method and flags (0 if zlib) */ 83 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 84 | unsigned long check; /* protected copy of check value */ 85 | unsigned long total; /* protected copy of output count */ 86 | gz_headerp head; /* where to save gzip header information */ 87 | /* sliding window */ 88 | unsigned wbits; /* log base 2 of requested window size */ 89 | unsigned wsize; /* window size or zero if not using window */ 90 | unsigned whave; /* valid bytes in the window */ 91 | unsigned write; /* window write index */ 92 | unsigned char FAR *window; /* allocated sliding window, if needed */ 93 | /* bit accumulator */ 94 | unsigned long hold; /* input bit accumulator */ 95 | unsigned bits; /* number of bits in "in" */ 96 | /* for string and stored block copying */ 97 | unsigned length; /* literal or length of data to copy */ 98 | unsigned offset; /* distance back to copy string from */ 99 | /* for table and code decoding */ 100 | unsigned extra; /* extra bits needed */ 101 | /* fixed and dynamic code tables */ 102 | code const FAR *lencode; /* starting table for length/literal codes */ 103 | code const FAR *distcode; /* starting table for distance codes */ 104 | unsigned lenbits; /* index bits for lencode */ 105 | unsigned distbits; /* index bits for distcode */ 106 | /* dynamic table building */ 107 | unsigned ncode; /* number of code length code lengths */ 108 | unsigned nlen; /* number of length code lengths */ 109 | unsigned ndist; /* number of distance code lengths */ 110 | unsigned have; /* number of code lengths in lens[] */ 111 | code FAR *next; /* next available space in codes[] */ 112 | unsigned short lens[320]; /* temporary storage for code lengths */ 113 | unsigned short work[288]; /* work area for code table building */ 114 | code codes[ENOUGH]; /* space for code tables */ 115 | }; 116 | -------------------------------------------------------------------------------- /src/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- 39 | exhaustive search was 1444 code structures (852 for length/literals 40 | and 592 for distances, the latter actually the result of an 41 | exhaustive search). The true maximum is not known, but the value 42 | below is more than safe. */ 43 | #define ENOUGH 2048 44 | #define MAXD 592 45 | 46 | /* Type of code to build for inftable() */ 47 | typedef enum { 48 | CODES, 49 | LENS, 50 | DISTS 51 | } codetype; 52 | 53 | extern int inflate_table OF((codetype type, unsigned short FAR *lens, 54 | unsigned codes, code FAR * FAR *table, 55 | unsigned FAR *bits, unsigned short FAR *work)); 56 | -------------------------------------------------------------------------------- /src/zlib/mozzconf.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 | /* ***** BEGIN LICENSE BLOCK ***** 3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.mozilla.org/MPL/ 9 | * 10 | * Software distributed under the License is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 | * for the specific language governing rights and limitations under the 13 | * License. 14 | * 15 | * The Original Code is the mozilla zlib configuration. 16 | * 17 | * The Initial Developer of the Original Code is IBM Corporation. 18 | * Portions created by the Initial Developer are Copyright (C) 2004 19 | * the Initial Developer. All Rights Reserved. 20 | * 21 | * Contributor(s): 22 | * 23 | * Alternatively, the contents of this file may be used under the terms of 24 | * either of the GNU General Public License Version 2 or later (the "GPL"), 25 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 26 | * in which case the provisions of the GPL or the LGPL are applicable instead 27 | * of those above. If you wish to allow use of your version of this file only 28 | * under the terms of either the GPL or the LGPL, and not to allow others to 29 | * use your version of this file under the terms of the MPL, indicate your 30 | * decision by deleting the provisions above and replace them with the notice 31 | * and other provisions required by the GPL or the LGPL. If you do not delete 32 | * the provisions above, a recipient may use your version of this file under 33 | * the terms of any one of the MPL, the GPL or the LGPL. 34 | * 35 | * ***** END LICENSE BLOCK ***** */ 36 | 37 | #ifndef MOZZCONF_H 38 | #define MOZZCONF_H 39 | 40 | #if defined(XP_WIN) && defined(ZLIB_DLL) && !defined(MOZ_ENABLE_LIBXUL) 41 | #undef ZLIB_DLL 42 | #endif 43 | 44 | #ifdef HAVE_VISIBILITY_ATTRIBUTE 45 | #define ZEXTERN __attribute__((visibility ("default"))) extern 46 | #endif 47 | 48 | /* Exported Symbols */ 49 | #define zlibVersion MOZ_Z_zlibVersion 50 | #define deflate MOZ_Z_deflate 51 | #define deflateEnd MOZ_Z_deflateEnd 52 | #define inflate MOZ_Z_inflate 53 | #define inflateEnd MOZ_Z_inflateEnd 54 | #define deflateSetDictionary MOZ_Z_deflateSetDictionary 55 | #define deflateCopy MOZ_Z_deflateCopy 56 | #define deflateReset MOZ_Z_deflateReset 57 | #define deflateParams MOZ_Z_deflateParams 58 | #define deflateBound MOZ_Z_deflateBound 59 | #define deflatePrime MOZ_Z_deflatePrime 60 | #define inflateSetDictionary MOZ_Z_inflateSetDictionary 61 | #define inflateSync MOZ_Z_inflateSync 62 | #define inflateCopy MOZ_Z_inflateCopy 63 | #define inflateReset MOZ_Z_inflateReset 64 | #define inflateBack MOZ_Z_inflateBack 65 | #define inflateBackEnd MOZ_Z_inflateBackEnd 66 | #define zlibCompileFlags MOZ_Z_zlibCompileFlags 67 | #define compress MOZ_Z_compress 68 | #define compress2 MOZ_Z_compress2 69 | #define compressBound MOZ_Z_compressBound 70 | #define uncompress MOZ_Z_uncompress 71 | #define gzopen MOZ_Z_gzopen 72 | #define gzdopen MOZ_Z_gzdopen 73 | #define gzsetparams MOZ_Z_gzsetparams 74 | #define gzread MOZ_Z_gzread 75 | #define gzwrite MOZ_Z_gzwrite 76 | #define gzprintf MOZ_Z_gzprintf 77 | #define gzputs MOZ_Z_gzputs 78 | #define gzgets MOZ_Z_gzgets 79 | #define gzputc MOZ_Z_gzputc 80 | #define gzgetc MOZ_Z_gzgetc 81 | #define gzungetc MOZ_Z_gzungetc 82 | #define gzflush MOZ_Z_gzflush 83 | #define gzseek MOZ_Z_gzseek 84 | #define gzrewind MOZ_Z_gzrewind 85 | #define gztell MOZ_Z_gztell 86 | #define gzeof MOZ_Z_gzeof 87 | #define gzclose MOZ_Z_gzclose 88 | #define gzerror MOZ_Z_gzerror 89 | #define gzclearerr MOZ_Z_gzclearerr 90 | #define adler32 MOZ_Z_adler32 91 | #define crc32 MOZ_Z_crc32 92 | #define deflateInit_ MOZ_Z_deflateInit_ 93 | #define deflateInit2_ MOZ_Z_deflateInit2_ 94 | #define inflateInit_ MOZ_Z_inflateInit_ 95 | #define inflateInit2_ MOZ_Z_inflateInit2_ 96 | #define inflateBackInit_ MOZ_Z_inflateBackInit_ 97 | #define inflateSyncPoint MOZ_Z_inflateSyncPoint 98 | #define get_crc_table MOZ_Z_get_crc_table 99 | #define zError MOZ_Z_zError 100 | 101 | /* Extra global symbols */ 102 | #define _dist_code MOZ_Z__dist_code 103 | #define _length_code MOZ_Z__length_code 104 | #define _tr_align MOZ_Z__tr_align 105 | #define _tr_flush_block MOZ_Z__tr_flush_block 106 | #define _tr_init MOZ_Z__tr_init 107 | #define _tr_stored_block MOZ_Z__tr_stored_block 108 | #define _tr_tally MOZ_Z__tr_tally 109 | #define deflate_copyright MOZ_Z_deflate_copyright 110 | #define inflate_copyright MOZ_Z_inflate_copyright 111 | #define inflate_fast MOZ_Z_inflate_fast 112 | #define inflate_table MOZ_Z_inflate_table 113 | #define z_errmsg MOZ_Z_z_errmsg 114 | #define zcalloc MOZ_Z_zcalloc 115 | #define zcfree MOZ_Z_zcfree 116 | #define alloc_func MOZ_Z_alloc_func 117 | #define free_func MOZ_Z_free_func 118 | #define in_func MOZ_Z_in_func 119 | #define out_func MOZ_Z_out_func 120 | 121 | /* New as of libpng-1.2.3 */ 122 | #define adler32_combine MOZ_Z_adler32_combine 123 | #define crc32_combine MOZ_Z_crc32_combine 124 | #define deflateSetHeader MOZ_Z_deflateSetHeader 125 | #define deflateTune MOZ_Z_deflateTune 126 | #define gzdirect MOZ_Z_gzdirect 127 | #define inflatePrime MOZ_Z_inflatePrime 128 | #define inflateGetHeader MOZ_Z_inflateGetHeader 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /src/zlib/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /src/zlib/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: uncompr.c,v 3.6 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | This function can be used to decompress a whole file at once if the 20 | input file is mmap'ed. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 23 | enough memory, Z_BUF_ERROR if there was not enough room in the output 24 | buffer, or Z_DATA_ERROR if the input data was corrupted. 25 | */ 26 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 27 | Bytef *dest; 28 | uLongf *destLen; 29 | const Bytef *source; 30 | uLong sourceLen; 31 | { 32 | z_stream stream; 33 | int err; 34 | 35 | stream.next_in = (Bytef*)source; 36 | stream.avail_in = (uInt)sourceLen; 37 | /* Check for source > 64K on 16-bit machine: */ 38 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 39 | 40 | stream.next_out = dest; 41 | stream.avail_out = (uInt)*destLen; 42 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 43 | 44 | stream.zalloc = (alloc_func)0; 45 | stream.zfree = (free_func)0; 46 | 47 | err = inflateInit(&stream); 48 | if (err != Z_OK) return err; 49 | 50 | err = inflate(&stream, Z_FINISH); 51 | if (err != Z_STREAM_END) { 52 | inflateEnd(&stream); 53 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 54 | return Z_DATA_ERROR; 55 | return err; 56 | } 57 | *destLen = stream.total_out; 58 | 59 | err = inflateEnd(&stream); 60 | return err; 61 | } 62 | -------------------------------------------------------------------------------- /src/zlib/zconf.h: -------------------------------------------------------------------------------- 1 | /* zconf.h -- configuration of the zlib compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: zconf.h,v 3.9 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 7 | 8 | #ifndef ZCONF_H 9 | #define ZCONF_H 10 | 11 | /* This include does prefixing as below, but with an updated set of names */ 12 | #include "mozzconf.h" 13 | 14 | /* 15 | * If you *really* need a unique prefix for all types and library functions, 16 | * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. 17 | */ 18 | #ifdef Z_PREFIX 19 | # define deflateInit_ z_deflateInit_ 20 | # define deflate z_deflate 21 | # define deflateEnd z_deflateEnd 22 | # define inflateInit_ z_inflateInit_ 23 | # define inflate z_inflate 24 | # define inflateEnd z_inflateEnd 25 | # define deflateInit2_ z_deflateInit2_ 26 | # define deflateSetDictionary z_deflateSetDictionary 27 | # define deflateCopy z_deflateCopy 28 | # define deflateReset z_deflateReset 29 | # define deflateParams z_deflateParams 30 | # define deflateBound z_deflateBound 31 | # define deflatePrime z_deflatePrime 32 | # define inflateInit2_ z_inflateInit2_ 33 | # define inflateSetDictionary z_inflateSetDictionary 34 | # define inflateSync z_inflateSync 35 | # define inflateSyncPoint z_inflateSyncPoint 36 | # define inflateCopy z_inflateCopy 37 | # define inflateReset z_inflateReset 38 | # define inflateBack z_inflateBack 39 | # define inflateBackEnd z_inflateBackEnd 40 | # define compress z_compress 41 | # define compress2 z_compress2 42 | # define compressBound z_compressBound 43 | # define uncompress z_uncompress 44 | # define adler32 z_adler32 45 | # define crc32 z_crc32 46 | # define get_crc_table z_get_crc_table 47 | # define zError z_zError 48 | 49 | # define alloc_func z_alloc_func 50 | # define free_func z_free_func 51 | # define in_func z_in_func 52 | # define out_func z_out_func 53 | # define Byte z_Byte 54 | # define uInt z_uInt 55 | # define uLong z_uLong 56 | # define Bytef z_Bytef 57 | # define charf z_charf 58 | # define intf z_intf 59 | # define uIntf z_uIntf 60 | # define uLongf z_uLongf 61 | # define voidpf z_voidpf 62 | # define voidp z_voidp 63 | #endif 64 | 65 | #if defined(__MSDOS__) && !defined(MSDOS) 66 | # define MSDOS 67 | #endif 68 | #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) 69 | # define OS2 70 | #endif 71 | #if defined(_WINDOWS) && !defined(WINDOWS) 72 | # define WINDOWS 73 | #endif 74 | #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) 75 | # ifndef WIN32 76 | # define WIN32 77 | # endif 78 | #endif 79 | #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) 80 | # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) 81 | # ifndef SYS16BIT 82 | # define SYS16BIT 83 | # endif 84 | # endif 85 | #endif 86 | 87 | /* 88 | * Compile with -DMAXSEG_64K if the alloc function cannot allocate more 89 | * than 64k bytes at a time (needed on systems with 16-bit int). 90 | */ 91 | #ifdef SYS16BIT 92 | # define MAXSEG_64K 93 | #endif 94 | #ifdef MSDOS 95 | # define UNALIGNED_OK 96 | #endif 97 | 98 | #ifdef __STDC_VERSION__ 99 | # ifndef STDC 100 | # define STDC 101 | # endif 102 | # if __STDC_VERSION__ >= 199901L 103 | # ifndef STDC99 104 | # define STDC99 105 | # endif 106 | # endif 107 | #endif 108 | #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) 109 | # define STDC 110 | #endif 111 | #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) 112 | # define STDC 113 | #endif 114 | #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) 115 | # define STDC 116 | #endif 117 | #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) 118 | # define STDC 119 | #endif 120 | 121 | #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ 122 | # define STDC 123 | #endif 124 | 125 | #ifndef STDC 126 | # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ 127 | # define const /* note: need a more gentle solution here */ 128 | # endif 129 | #endif 130 | 131 | /* Some Mac compilers merge all .h files incorrectly: */ 132 | #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) 133 | # define NO_DUMMY_DECL 134 | #endif 135 | 136 | /* Maximum value for memLevel in deflateInit2 */ 137 | #ifndef MAX_MEM_LEVEL 138 | # ifdef MAXSEG_64K 139 | # define MAX_MEM_LEVEL 8 140 | # else 141 | # define MAX_MEM_LEVEL 9 142 | # endif 143 | #endif 144 | 145 | /* Maximum value for windowBits in deflateInit2 and inflateInit2. 146 | * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files 147 | * created by gzip. (Files created by minigzip can still be extracted by 148 | * gzip.) 149 | */ 150 | #ifndef MAX_WBITS 151 | # define MAX_WBITS 15 /* 32K LZ77 window */ 152 | #endif 153 | 154 | /* The memory requirements for deflate are (in bytes): 155 | (1 << (windowBits+2)) + (1 << (memLevel+9)) 156 | that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) 157 | plus a few kilobytes for small objects. For example, if you want to reduce 158 | the default memory requirements from 256K to 128K, compile with 159 | make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" 160 | Of course this will generally degrade compression (there's no free lunch). 161 | 162 | The memory requirements for inflate are (in bytes) 1 << windowBits 163 | that is, 32K for windowBits=15 (default value) plus a few kilobytes 164 | for small objects. 165 | */ 166 | 167 | /* Type declarations */ 168 | 169 | #ifndef OF /* function prototypes */ 170 | # ifdef STDC 171 | # define OF(args) args 172 | # else 173 | # define OF(args) () 174 | # endif 175 | #endif 176 | 177 | /* The following definitions for FAR are needed only for MSDOS mixed 178 | * model programming (small or medium model with some far allocations). 179 | * This was tested only with MSC; for other MSDOS compilers you may have 180 | * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, 181 | * just define FAR to be empty. 182 | */ 183 | #ifdef SYS16BIT 184 | # if defined(M_I86SM) || defined(M_I86MM) 185 | /* MSC small or medium model */ 186 | # define SMALL_MEDIUM 187 | # ifdef _MSC_VER 188 | # define FAR _far 189 | # else 190 | # define FAR far 191 | # endif 192 | # endif 193 | # if (defined(__SMALL__) || defined(__MEDIUM__)) 194 | /* Turbo C small or medium model */ 195 | # define SMALL_MEDIUM 196 | # ifdef __BORLANDC__ 197 | # define FAR _far 198 | # else 199 | # define FAR far 200 | # endif 201 | # endif 202 | #endif 203 | 204 | #if defined(WINDOWS) || defined(WIN32) 205 | /* If building or using zlib as a DLL, define ZLIB_DLL. 206 | * This is not mandatory, but it offers a little performance increase. 207 | */ 208 | # ifdef ZLIB_DLL 209 | # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) 210 | # ifdef ZLIB_INTERNAL 211 | # define ZEXTERN extern __declspec(dllexport) 212 | # else 213 | # define ZEXTERN extern __declspec(dllimport) 214 | # endif 215 | # endif 216 | # endif /* ZLIB_DLL */ 217 | /* If building or using zlib with the WINAPI/WINAPIV calling convention, 218 | * define ZLIB_WINAPI. 219 | * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. 220 | */ 221 | # ifdef ZLIB_WINAPI 222 | # ifdef FAR 223 | # undef FAR 224 | # endif 225 | # include 226 | /* No need for _export, use ZLIB.DEF instead. */ 227 | /* For complete Windows compatibility, use WINAPI, not __stdcall. */ 228 | # define ZEXPORT WINAPI 229 | # ifdef WIN32 230 | # define ZEXPORTVA WINAPIV 231 | # else 232 | # define ZEXPORTVA FAR CDECL 233 | # endif 234 | # endif 235 | #endif 236 | 237 | #if defined (__BEOS__) 238 | # ifdef ZLIB_DLL 239 | # ifdef ZLIB_INTERNAL 240 | # define ZEXPORT __declspec(dllexport) 241 | # define ZEXPORTVA __declspec(dllexport) 242 | # else 243 | # define ZEXPORT __declspec(dllimport) 244 | # define ZEXPORTVA __declspec(dllimport) 245 | # endif 246 | # endif 247 | #endif 248 | 249 | #ifndef ZEXTERN 250 | # define ZEXTERN extern 251 | #endif 252 | #ifndef ZEXPORT 253 | # define ZEXPORT 254 | #endif 255 | #ifndef ZEXPORTVA 256 | # define ZEXPORTVA 257 | #endif 258 | 259 | #ifndef FAR 260 | # define FAR 261 | #endif 262 | 263 | #if !defined(__MACTYPES__) 264 | typedef unsigned char Byte; /* 8 bits */ 265 | #endif 266 | typedef unsigned int uInt; /* 16 bits or more */ 267 | typedef unsigned long uLong; /* 32 bits or more */ 268 | 269 | #ifdef SMALL_MEDIUM 270 | /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ 271 | # define Bytef Byte FAR 272 | #else 273 | typedef Byte FAR Bytef; 274 | #endif 275 | typedef char FAR charf; 276 | typedef int FAR intf; 277 | typedef uInt FAR uIntf; 278 | typedef uLong FAR uLongf; 279 | 280 | #ifdef STDC 281 | typedef void const *voidpc; 282 | typedef void FAR *voidpf; 283 | typedef void *voidp; 284 | #else 285 | typedef Byte const *voidpc; 286 | typedef Byte FAR *voidpf; 287 | typedef Byte *voidp; 288 | #endif 289 | 290 | #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ 291 | # include /* for off_t */ 292 | # include /* for SEEK_* and off_t */ 293 | # ifdef VMS 294 | # include /* for off_t */ 295 | # endif 296 | # define z_off_t off_t 297 | #endif 298 | #ifndef SEEK_SET 299 | # define SEEK_SET 0 /* Seek from beginning of file. */ 300 | # define SEEK_CUR 1 /* Seek from current position. */ 301 | # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ 302 | #endif 303 | #ifndef z_off_t 304 | # define z_off_t long 305 | #endif 306 | 307 | #if defined(__OS400__) 308 | # define NO_vsnprintf 309 | #endif 310 | 311 | #if defined(__MVS__) 312 | # define NO_vsnprintf 313 | # ifdef FAR 314 | # undef FAR 315 | # endif 316 | #endif 317 | 318 | /* MVS linker does not support external names larger than 8 bytes */ 319 | #if defined(__MVS__) 320 | # pragma map(deflateInit_,"DEIN") 321 | # pragma map(deflateInit2_,"DEIN2") 322 | # pragma map(deflateEnd,"DEEND") 323 | # pragma map(deflateBound,"DEBND") 324 | # pragma map(inflateInit_,"ININ") 325 | # pragma map(inflateInit2_,"ININ2") 326 | # pragma map(inflateEnd,"INEND") 327 | # pragma map(inflateSync,"INSY") 328 | # pragma map(inflateSetDictionary,"INSEDI") 329 | # pragma map(compressBound,"CMBND") 330 | # pragma map(inflate_table,"INTABL") 331 | # pragma map(inflate_fast,"INFA") 332 | # pragma map(inflate_copyright,"INCOPY") 333 | #endif 334 | 335 | #endif /* ZCONF_H */ 336 | -------------------------------------------------------------------------------- /src/zlib/zlib.gyp: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | # Use of this source code is governed by a BSD-style license that can be 3 | # found in the LICENSE file. 4 | 5 | { 6 | 'variables': { 7 | 'use_system_zlib%': 0 8 | }, 9 | 'conditions': [ 10 | ['use_system_zlib==0', { 11 | 'targets': [ 12 | { 13 | 'target_name': 'zlib', 14 | 'type': 'static_library', 15 | 'sources': [ 16 | 'contrib/minizip/ioapi.c', 17 | 'contrib/minizip/ioapi.h', 18 | 'contrib/minizip/iowin32.c', 19 | 'contrib/minizip/iowin32.h', 20 | 'contrib/minizip/unzip.c', 21 | 'contrib/minizip/unzip.h', 22 | 'contrib/minizip/zip.c', 23 | 'contrib/minizip/zip.h', 24 | 'adler32.c', 25 | 'compress.c', 26 | 'crc32.c', 27 | 'crc32.h', 28 | 'deflate.c', 29 | 'deflate.h', 30 | 'gzio.c', 31 | 'infback.c', 32 | 'inffast.c', 33 | 'inffast.h', 34 | 'inffixed.h', 35 | 'inflate.c', 36 | 'inflate.h', 37 | 'inftrees.c', 38 | 'inftrees.h', 39 | 'mozzconf.h', 40 | 'trees.c', 41 | 'trees.h', 42 | 'uncompr.c', 43 | 'zconf.h', 44 | 'zlib.h', 45 | 'zutil.c', 46 | 'zutil.h', 47 | ], 48 | 'include_dirs': [ 49 | '.', 50 | # For contrib/minizip 51 | './contrib/minizip', 52 | ], 53 | 'direct_dependent_settings': { 54 | 'include_dirs': [ 55 | '.', 56 | ], 57 | }, 58 | 'conditions': [ 59 | ['OS!="win"', { 60 | 'product_name': 'chrome_zlib', 61 | 'cflags!': [ '-ansi' ], 62 | 'sources!': [ 63 | 'contrib/minizip/iowin32.c' 64 | ], 65 | }], 66 | ], 67 | }, 68 | ], 69 | }, { 70 | 'targets': [ 71 | { 72 | 'target_name': 'zlib', 73 | 'type': 'static_library', 74 | 'direct_dependent_settings': { 75 | 'defines': [ 76 | 'USE_SYSTEM_ZLIB', 77 | ], 78 | }, 79 | 'defines': [ 80 | 'USE_SYSTEM_ZLIB', 81 | ], 82 | 'sources': [ 83 | 'contrib/minizip/ioapi.c', 84 | 'contrib/minizip/ioapi.h', 85 | 'contrib/minizip/unzip.c', 86 | 'contrib/minizip/unzip.h', 87 | 'contrib/minizip/zip.c', 88 | 'contrib/minizip/zip.h', 89 | ], 90 | 'link_settings': { 91 | 'libraries': [ 92 | '-lz', 93 | ], 94 | }, 95 | }, 96 | ], 97 | }], 98 | ], 99 | } 100 | -------------------------------------------------------------------------------- /src/zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: zutil.c,v 3.11 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 7 | 8 | #include "zutil.h" 9 | 10 | #ifndef NO_DUMMY_DECL 11 | struct internal_state {int dummy;}; /* for buggy compilers */ 12 | #endif 13 | 14 | const char * const z_errmsg[10] = { 15 | "need dictionary", /* Z_NEED_DICT 2 */ 16 | "stream end", /* Z_STREAM_END 1 */ 17 | "", /* Z_OK 0 */ 18 | "file error", /* Z_ERRNO (-1) */ 19 | "stream error", /* Z_STREAM_ERROR (-2) */ 20 | "data error", /* Z_DATA_ERROR (-3) */ 21 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 22 | "buffer error", /* Z_BUF_ERROR (-5) */ 23 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 24 | ""}; 25 | 26 | 27 | const char * ZEXPORT zlibVersion() 28 | { 29 | return ZLIB_VERSION; 30 | } 31 | 32 | uLong ZEXPORT zlibCompileFlags() 33 | { 34 | uLong flags; 35 | 36 | flags = 0; 37 | switch (sizeof(uInt)) { 38 | case 2: break; 39 | case 4: flags += 1; break; 40 | case 8: flags += 2; break; 41 | default: flags += 3; 42 | } 43 | switch (sizeof(uLong)) { 44 | case 2: break; 45 | case 4: flags += 1 << 2; break; 46 | case 8: flags += 2 << 2; break; 47 | default: flags += 3 << 2; 48 | } 49 | switch (sizeof(voidpf)) { 50 | case 2: break; 51 | case 4: flags += 1 << 4; break; 52 | case 8: flags += 2 << 4; break; 53 | default: flags += 3 << 4; 54 | } 55 | switch (sizeof(z_off_t)) { 56 | case 2: break; 57 | case 4: flags += 1 << 6; break; 58 | case 8: flags += 2 << 6; break; 59 | default: flags += 3 << 6; 60 | } 61 | #ifdef DEBUG 62 | flags += 1 << 8; 63 | #endif 64 | #if defined(ASMV) || defined(ASMINF) 65 | flags += 1 << 9; 66 | #endif 67 | #ifdef ZLIB_WINAPI 68 | flags += 1 << 10; 69 | #endif 70 | #ifdef BUILDFIXED 71 | flags += 1 << 12; 72 | #endif 73 | #ifdef DYNAMIC_CRC_TABLE 74 | flags += 1 << 13; 75 | #endif 76 | #ifdef NO_GZCOMPRESS 77 | flags += 1L << 16; 78 | #endif 79 | #ifdef NO_GZIP 80 | flags += 1L << 17; 81 | #endif 82 | #ifdef PKZIP_BUG_WORKAROUND 83 | flags += 1L << 20; 84 | #endif 85 | #ifdef FASTEST 86 | flags += 1L << 21; 87 | #endif 88 | #ifdef STDC 89 | # ifdef NO_vsnprintf 90 | flags += 1L << 25; 91 | # ifdef HAS_vsprintf_void 92 | flags += 1L << 26; 93 | # endif 94 | # else 95 | # ifdef HAS_vsnprintf_void 96 | flags += 1L << 26; 97 | # endif 98 | # endif 99 | #else 100 | flags += 1L << 24; 101 | # ifdef NO_snprintf 102 | flags += 1L << 25; 103 | # ifdef HAS_sprintf_void 104 | flags += 1L << 26; 105 | # endif 106 | # else 107 | # ifdef HAS_snprintf_void 108 | flags += 1L << 26; 109 | # endif 110 | # endif 111 | #endif 112 | return flags; 113 | } 114 | 115 | #ifdef DEBUG 116 | 117 | # ifndef verbose 118 | # define verbose 0 119 | # endif 120 | int z_verbose = verbose; 121 | 122 | void z_error (m) 123 | char *m; 124 | { 125 | fprintf(stderr, "%s\n", m); 126 | exit(1); 127 | } 128 | #endif 129 | 130 | /* exported to allow conversion of error code to string for compress() and 131 | * uncompress() 132 | */ 133 | const char * ZEXPORT zError(err) 134 | int err; 135 | { 136 | return ERR_MSG(err); 137 | } 138 | 139 | #if defined(_WIN32_WCE) 140 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 141 | * errno. We define it as a global variable to simplify porting. 142 | * Its value is always 0 and should not be used. 143 | */ 144 | // Google Gears modification: zutil.h defines errno as z_errno for WinCE. 145 | //int errno = 0; 146 | int z_errno = 0; 147 | #endif 148 | 149 | #ifndef HAVE_MEMCPY 150 | 151 | void zmemcpy(dest, source, len) 152 | Bytef* dest; 153 | const Bytef* source; 154 | uInt len; 155 | { 156 | if (len == 0) return; 157 | do { 158 | *dest++ = *source++; /* ??? to be unrolled */ 159 | } while (--len != 0); 160 | } 161 | 162 | int zmemcmp(s1, s2, len) 163 | const Bytef* s1; 164 | const Bytef* s2; 165 | uInt len; 166 | { 167 | uInt j; 168 | 169 | for (j = 0; j < len; j++) { 170 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 171 | } 172 | return 0; 173 | } 174 | 175 | void zmemzero(dest, len) 176 | Bytef* dest; 177 | uInt len; 178 | { 179 | if (len == 0) return; 180 | do { 181 | *dest++ = 0; /* ??? to be unrolled */ 182 | } while (--len != 0); 183 | } 184 | #endif 185 | 186 | 187 | #ifdef SYS16BIT 188 | 189 | #ifdef __TURBOC__ 190 | /* Turbo C in 16-bit mode */ 191 | 192 | # define MY_ZCALLOC 193 | 194 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 195 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 196 | * must fix the pointer. Warning: the pointer must be put back to its 197 | * original form in order to free it, use zcfree(). 198 | */ 199 | 200 | #define MAX_PTR 10 201 | /* 10*64K = 640K */ 202 | 203 | local int next_ptr = 0; 204 | 205 | typedef struct ptr_table_s { 206 | voidpf org_ptr; 207 | voidpf new_ptr; 208 | } ptr_table; 209 | 210 | local ptr_table table[MAX_PTR]; 211 | /* This table is used to remember the original form of pointers 212 | * to large buffers (64K). Such pointers are normalized with a zero offset. 213 | * Since MSDOS is not a preemptive multitasking OS, this table is not 214 | * protected from concurrent access. This hack doesn't work anyway on 215 | * a protected system like OS/2. Use Microsoft C instead. 216 | */ 217 | 218 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 219 | { 220 | voidpf buf = opaque; /* just to make some compilers happy */ 221 | ulg bsize = (ulg)items*size; 222 | 223 | /* If we allocate less than 65520 bytes, we assume that farmalloc 224 | * will return a usable pointer which doesn't have to be normalized. 225 | */ 226 | if (bsize < 65520L) { 227 | buf = farmalloc(bsize); 228 | if (*(ush*)&buf != 0) return buf; 229 | } else { 230 | buf = farmalloc(bsize + 16L); 231 | } 232 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 233 | table[next_ptr].org_ptr = buf; 234 | 235 | /* Normalize the pointer to seg:0 */ 236 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 237 | *(ush*)&buf = 0; 238 | table[next_ptr++].new_ptr = buf; 239 | return buf; 240 | } 241 | 242 | void zcfree (voidpf opaque, voidpf ptr) 243 | { 244 | int n; 245 | if (*(ush*)&ptr != 0) { /* object < 64K */ 246 | farfree(ptr); 247 | return; 248 | } 249 | /* Find the original pointer */ 250 | for (n = 0; n < next_ptr; n++) { 251 | if (ptr != table[n].new_ptr) continue; 252 | 253 | farfree(table[n].org_ptr); 254 | while (++n < next_ptr) { 255 | table[n-1] = table[n]; 256 | } 257 | next_ptr--; 258 | return; 259 | } 260 | ptr = opaque; /* just to make some compilers happy */ 261 | Assert(0, "zcfree: ptr not found"); 262 | } 263 | 264 | #endif /* __TURBOC__ */ 265 | 266 | 267 | #ifdef M_I86 268 | /* Microsoft C in 16-bit mode */ 269 | 270 | # define MY_ZCALLOC 271 | 272 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 273 | # define _halloc halloc 274 | # define _hfree hfree 275 | #endif 276 | 277 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 278 | { 279 | if (opaque) opaque = 0; /* to make compiler happy */ 280 | return _halloc((long)items, size); 281 | } 282 | 283 | void zcfree (voidpf opaque, voidpf ptr) 284 | { 285 | if (opaque) opaque = 0; /* to make compiler happy */ 286 | _hfree(ptr); 287 | } 288 | 289 | #endif /* M_I86 */ 290 | 291 | #endif /* SYS16BIT */ 292 | 293 | 294 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 295 | 296 | #ifndef STDC 297 | extern voidp malloc OF((uInt size)); 298 | extern voidp calloc OF((uInt items, uInt size)); 299 | extern void free OF((voidpf ptr)); 300 | #endif 301 | 302 | voidpf zcalloc (opaque, items, size) 303 | voidpf opaque; 304 | unsigned items; 305 | unsigned size; 306 | { 307 | if (opaque) items += size - size; /* make compiler happy */ 308 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 309 | (voidpf)calloc(items, size); 310 | } 311 | 312 | void zcfree (opaque, ptr) 313 | voidpf opaque; 314 | voidpf ptr; 315 | { 316 | free(ptr); 317 | if (opaque) return; /* make compiler happy */ 318 | } 319 | 320 | #endif /* MY_ZCALLOC */ 321 | -------------------------------------------------------------------------------- /src/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id: zutil.h,v 3.10 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #define ZLIB_INTERNAL 17 | #include "zlib.h" 18 | 19 | #ifdef STDC 20 | # ifndef _WIN32_WCE 21 | # include 22 | # endif 23 | # include 24 | # include 25 | #endif 26 | #ifdef NO_ERRNO_H 27 | # ifdef _WIN32_WCE 28 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 29 | * errno. We define it as a global variable to simplify porting. 30 | * Its value is always 0 and should not be used. We rename it to 31 | * avoid conflict with other libraries that use the same workaround. 32 | */ 33 | # define errno z_errno 34 | # endif 35 | extern int errno; 36 | #else 37 | # ifndef _WIN32_WCE 38 | # include 39 | # endif 40 | #endif 41 | 42 | #ifndef local 43 | # define local static 44 | #endif 45 | /* compile with -Dlocal if your debugger can't find static symbols */ 46 | 47 | typedef unsigned char uch; 48 | typedef uch FAR uchf; 49 | typedef unsigned short ush; 50 | typedef ush FAR ushf; 51 | typedef unsigned long ulg; 52 | 53 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 54 | /* (size given to avoid silly warnings with Visual C++) */ 55 | 56 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 57 | 58 | #define ERR_RETURN(strm,err) \ 59 | return (strm->msg = (char*)ERR_MSG(err), (err)) 60 | /* To be used only when the state is known to be valid */ 61 | 62 | /* common constants */ 63 | 64 | #ifndef DEF_WBITS 65 | # define DEF_WBITS MAX_WBITS 66 | #endif 67 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 68 | 69 | #if MAX_MEM_LEVEL >= 8 70 | # define DEF_MEM_LEVEL 8 71 | #else 72 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 73 | #endif 74 | /* default memLevel */ 75 | 76 | #define STORED_BLOCK 0 77 | #define STATIC_TREES 1 78 | #define DYN_TREES 2 79 | /* The three kinds of block type */ 80 | 81 | #define MIN_MATCH 3 82 | #define MAX_MATCH 258 83 | /* The minimum and maximum match lengths */ 84 | 85 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 86 | 87 | /* target dependencies */ 88 | 89 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 90 | # define OS_CODE 0x00 91 | # if defined(__TURBOC__) || defined(__BORLANDC__) 92 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 93 | /* Allow compilation with ANSI keywords only enabled */ 94 | void _Cdecl farfree( void *block ); 95 | void *_Cdecl farmalloc( unsigned long nbytes ); 96 | # else 97 | # include 98 | # endif 99 | # else /* MSC or DJGPP */ 100 | # include 101 | # endif 102 | #endif 103 | 104 | #ifdef AMIGA 105 | # define OS_CODE 0x01 106 | #endif 107 | 108 | #if defined(VAXC) || defined(VMS) 109 | # define OS_CODE 0x02 110 | # define F_OPEN(name, mode) \ 111 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 112 | #endif 113 | 114 | #if defined(ATARI) || defined(atarist) 115 | # define OS_CODE 0x05 116 | #endif 117 | 118 | #ifdef OS2 119 | # define OS_CODE 0x06 120 | # ifdef M_I86 121 | #include 122 | # endif 123 | #endif 124 | 125 | #if defined(MACOS) || defined(TARGET_OS_MAC) 126 | # define OS_CODE 0x07 127 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 128 | # include /* for fdopen */ 129 | # else 130 | # ifndef fdopen 131 | # define fdopen(fd,mode) NULL /* No fdopen() */ 132 | # endif 133 | # endif 134 | #endif 135 | 136 | #ifdef TOPS20 137 | # define OS_CODE 0x0a 138 | #endif 139 | 140 | #ifdef WIN32 141 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 142 | # define OS_CODE 0x0b 143 | # endif 144 | #endif 145 | 146 | #ifdef __50SERIES /* Prime/PRIMOS */ 147 | # define OS_CODE 0x0f 148 | #endif 149 | 150 | #if defined(_BEOS_) || defined(RISCOS) 151 | # define fdopen(fd,mode) NULL /* No fdopen() */ 152 | #endif 153 | 154 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 155 | # if defined(_WIN32_WCE) 156 | # define fdopen(fd,mode) NULL /* No fdopen() */ 157 | # ifndef _PTRDIFF_T_DEFINED 158 | typedef int ptrdiff_t; 159 | # define _PTRDIFF_T_DEFINED 160 | # endif 161 | # else 162 | # define fdopen(fd,type) _fdopen(fd,type) 163 | # endif 164 | #endif 165 | 166 | /* common defaults */ 167 | 168 | #ifndef OS_CODE 169 | # define OS_CODE 0x03 /* assume Unix */ 170 | #endif 171 | 172 | #ifndef F_OPEN 173 | # define F_OPEN(name, mode) fopen((name), (mode)) 174 | #endif 175 | 176 | /* functions */ 177 | 178 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 179 | # ifndef HAVE_VSNPRINTF 180 | # define HAVE_VSNPRINTF 181 | # endif 182 | #endif 183 | #if defined(__CYGWIN__) 184 | # ifndef HAVE_VSNPRINTF 185 | # define HAVE_VSNPRINTF 186 | # endif 187 | #endif 188 | #ifndef HAVE_VSNPRINTF 189 | # ifdef MSDOS 190 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 191 | but for now we just assume it doesn't. */ 192 | # define NO_vsnprintf 193 | # endif 194 | # ifdef __TURBOC__ 195 | # define NO_vsnprintf 196 | # endif 197 | # ifdef WIN32 198 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 199 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 200 | # define vsnprintf _vsnprintf 201 | # endif 202 | # endif 203 | # ifdef __SASC 204 | # define NO_vsnprintf 205 | # endif 206 | #endif 207 | #ifdef VMS 208 | # define NO_vsnprintf 209 | #endif 210 | 211 | #if defined(pyr) 212 | # define NO_MEMCPY 213 | #endif 214 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 215 | /* Use our own functions for small and medium model with MSC <= 5.0. 216 | * You may have to use the same strategy for Borland C (untested). 217 | * The __SC__ check is for Symantec. 218 | */ 219 | # define NO_MEMCPY 220 | #endif 221 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 222 | # define HAVE_MEMCPY 223 | #endif 224 | #ifdef HAVE_MEMCPY 225 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 226 | # define zmemcpy _fmemcpy 227 | # define zmemcmp _fmemcmp 228 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 229 | # else 230 | # define zmemcpy memcpy 231 | # define zmemcmp memcmp 232 | # define zmemzero(dest, len) memset(dest, 0, len) 233 | # endif 234 | #else 235 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 236 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 237 | extern void zmemzero OF((Bytef* dest, uInt len)); 238 | #endif 239 | 240 | /* Diagnostic functions */ 241 | #ifdef DEBUG 242 | # include 243 | extern int z_verbose; 244 | extern void z_error OF((char *m)); 245 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 246 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 247 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 248 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 249 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 250 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 251 | #else 252 | # define Assert(cond,msg) 253 | # define Trace(x) 254 | # define Tracev(x) 255 | # define Tracevv(x) 256 | # define Tracec(c,x) 257 | # define Tracecv(c,x) 258 | #endif 259 | 260 | 261 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 262 | void zcfree OF((voidpf opaque, voidpf ptr)); 263 | 264 | #define ZALLOC(strm, items, size) \ 265 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 266 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 267 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 268 | 269 | #endif /* ZUTIL_H */ 270 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var ifile = require('./index.js') 2 | var zlib = require('zlib'); 3 | var path = require('path') 4 | 5 | 6 | ifile.add([ 7 | //["/static2",__dirname+path.sep+"test"], 8 | ['/test',__dirname], 9 | 10 | //["/static2/",__dirname+path.sep+"user",0], 11 | //["static","user",[]], 12 | //["static/sss/","user",['js','css']], 13 | //["/static/ss/","user"+path.sep+"fsdf",['js']], 14 | //["/static/saa","user"+path.sep+"fsdf"+path.sep,[]] 15 | 16 | ],function(req, res, isStatic){ 17 | //console.log(res) 18 | //res.end('isStatic: '+isStatic); 19 | res.statusCode = 404; 20 | 21 | res.end('404') 22 | 23 | }) 24 | 25 | var req= { 26 | url:'/static2/static2/aaa.js', 27 | method:'GET', 28 | headers:{ 29 | //"if-none-match":"1370955406_34", 30 | //"if-modified-since":"Thu, 13 Feb 2014 18:35:31 GMT", 31 | "accept-encoding":"gzip,deflate,sdch" 32 | } 33 | } 34 | var res = { 35 | end:function(buf){ 36 | 37 | /* 38 | zlib.gunzip(buf, function(err,buf2){ 39 | if(err) throw(err) 40 | console.log(buf2.length); 41 | console.log(buf2.toString()) 42 | 43 | }) 44 | */ 45 | console.log(buf.length) 46 | console.log(buf.toString()) 47 | }, 48 | setHeader:function(name,value){ 49 | console.log(name) 50 | console.log(value) 51 | } 52 | } 53 | 54 | ifile.route(req,res); 55 | 56 | 57 | 58 | 59 | 60 | var http = require('http'); 61 | http.createServer(function (request, response) { 62 | console.log(request.headers) 63 | ifile.route(request,response); 64 | }).listen(8124); 65 | 66 | console.log('Server running at http://127.0.0.1:8124/'); -------------------------------------------------------------------------------- /test/Static/Mount_Huangshan.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DoubleSpout/ifile/a769fa4f9c744ace0a8ec3df0c4f1c9085795043/test/Static/Mount_Huangshan.jpg -------------------------------------------------------------------------------- /test/Static/Mount_Huangshan2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DoubleSpout/ifile/a769fa4f9c744ace0a8ec3df0c4f1c9085795043/test/Static/Mount_Huangshan2.jpg -------------------------------------------------------------------------------- /test/build/config.gypi: -------------------------------------------------------------------------------- 1 | # Do not edit. File was generated by node-gyp's "configure" step 2 | { 3 | "target_defaults": { 4 | "cflags": [], 5 | "default_configuration": "Release", 6 | "defines": [], 7 | "include_dirs": [], 8 | "libraries": [] 9 | }, 10 | "variables": { 11 | "clang": 0, 12 | "gcc_version": 41, 13 | "host_arch": "ia32", 14 | "node_install_npm": "true", 15 | "node_prefix": "", 16 | "node_shared_cares": "false", 17 | "node_shared_http_parser": "false", 18 | "node_shared_libuv": "false", 19 | "node_shared_openssl": "false", 20 | "node_shared_v8": "false", 21 | "node_shared_zlib": "false", 22 | "node_tag": "", 23 | "node_unsafe_optimizations": 0, 24 | "node_use_dtrace": "false", 25 | "node_use_etw": "false", 26 | "node_use_openssl": "true", 27 | "node_use_perfctr": "false", 28 | "node_use_systemtap": "false", 29 | "python": "/usr/local/bin/python", 30 | "target_arch": "ia32", 31 | "v8_enable_gdbjit": 0, 32 | "v8_no_strict_aliasing": 1, 33 | "v8_use_snapshot": "true", 34 | "nodedir": "/root/.node-gyp/0.10.2", 35 | "copy_dev_lib": "true", 36 | "standalone_static_library": 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/pipe.js: -------------------------------------------------------------------------------- 1 | var ifile = require('../index.js'); 2 | var assert = require('assert'); 3 | var zlib = require('zlib'); 4 | 5 | ifile.options = { 6 | 7 | pipe_szie:1024 8 | expired:86400*1000*30, 9 | gzip:true, 10 | gzip_min_size:512, 11 | gzip_file:['js','xml'], 12 | gzip_level:0 13 | } 14 | 15 | 16 | ifile.add([ 17 | ["static3/static3/","static2",['js','css','xml']] 18 | ],function(req, res, isStatic){ 19 | 20 | //console.log(isStatic) 21 | if(isStatic) res.statusCode = 404; 22 | res.end('isStatic: '+isStatic); 23 | 24 | }) 25 | 26 | var http = require('http'); 27 | http.createServer(function (request, response) { 28 | ifile.route(request,response); 29 | }).listen(8125); 30 | 31 | console.log('Server running at http://127.0.0.1:8124/'); 32 | 33 | 34 | var fs = require('fs'); 35 | var path = require('path'); 36 | 37 | 38 | var testjs2 = fs.readFileSync(path.join(__dirname,'static2','static3','static3','test.xml')) 39 | var testjs2_stat = fs.statSync(path.join(__dirname,'static2','static3','static3','test.xml')) 40 | 41 | 42 | 43 | 44 | var n = 1; 45 | var back = function(m){ 46 | console.log(m) 47 | if(!--n){ 48 | process.exit(0); 49 | } 50 | } 51 | 52 | var request = function(path,head,cb,method){ 53 | 54 | 55 | var options = { 56 | hostname: '127.0.0.1', 57 | port: 8125, 58 | path: path, 59 | headers: head, 60 | method:method||'GET' 61 | }; 62 | 63 | var req = http.request(options, function(res) { 64 | 65 | //console.log('STATUS: ' + res.statusCode); 66 | //console.log('HEADERS: ' + JSON.stringify(res.headers)); 67 | var buf_list = []; 68 | var len=0; 69 | 70 | 71 | res.on('data', function (chunk) { 72 | 73 | buf_list.push(chunk); 74 | len += chunk.length; 75 | }); 76 | res.on('end',function(){ 77 | var buf = Buffer.concat(buf_list, len); 78 | //console.log(buf.toString()) 79 | cb(null, res, buf); 80 | }) 81 | 82 | 83 | }); 84 | 85 | req.on('error', function(e) { 86 | console.log('problem with request: ' + e.message); 87 | cb(e) 88 | }); 89 | req.end(); 90 | 91 | 92 | } 93 | 94 | 95 | http.globalAgent.maxSockets = 40; 96 | 97 | setTimeout(function(){ 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | },500) -------------------------------------------------------------------------------- /test/static2/static2/aaa.js: -------------------------------------------------------------------------------- 1 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.js -------------------------------------------------------------------------------- /test/static2/static2/test.css: -------------------------------------------------------------------------------- 1 | test.css 2 | test.css 3 | test.css 4 | test.css 5 | test.css 6 | test.css 7 | test.css 8 | test.css 9 | test.css 10 | test.css 11 | test.css 12 | test.css 13 | test.css 14 | test.css 15 | test.css 16 | test.css 17 | test.css 18 | test.css 19 | test.css 20 | test.css 21 | test.css 22 | test.css 23 | test.css 24 | test.css 25 | test.css 26 | test.css 27 | test.css 28 | test.css 29 | test.css 30 | test.css -------------------------------------------------------------------------------- /test/static2/static2/test.js: -------------------------------------------------------------------------------- 1 | test.js 2 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js -------------------------------------------------------------------------------- /test/static2/static3/static3/test.css: -------------------------------------------------------------------------------- 1 | test.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.csstest.css -------------------------------------------------------------------------------- /test/static2/static3/static3/test.txt: -------------------------------------------------------------------------------- 1 | test.js -------------------------------------------------------------------------------- /test/static2/static3/static3/test.xml: -------------------------------------------------------------------------------- 1 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 2 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 3 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 4 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 5 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 6 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 7 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 8 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 9 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 10 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js -------------------------------------------------------------------------------- /test/static2/static3/static3/test2.css: -------------------------------------------------------------------------------- 1 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 2 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 3 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 4 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 5 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 6 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 7 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 8 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 9 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 10 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js -------------------------------------------------------------------------------- /test/static2/static3/static3/test2.xml: -------------------------------------------------------------------------------- 1 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 2 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 3 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 4 | -------------------------------------------------------------------------------- /test/static2/static3/static3/test3.xml: -------------------------------------------------------------------------------- 1 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 2 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 3 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 4 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 5 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 6 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 7 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 8 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 9 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 10 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 11 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 12 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 13 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 14 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 15 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 16 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 17 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 18 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 19 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js 20 | test.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.jstest.js -------------------------------------------------------------------------------- /vendor.yml: -------------------------------------------------------------------------------- 1 | # Samples folders 2 | - ^test/ 3 | - ^build/ 4 | - ^benchmark/ --------------------------------------------------------------------------------