├── .gitignore ├── CHANGELOG ├── LICENSE ├── README.md ├── binding.gyp ├── deps └── zlib │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── 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 ├── index.js ├── package.json ├── src └── compress-buffer.cc └── test └── node-compress-buffer-test.js /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | lib/compress-buffer/compress-buffer-bindings.node 3 | .lock-wscript 4 | nbproject/ 5 | node_modules/* 6 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | 1.2.2: May 8, 2014 2 | * binding.gyp instead of bindings.gyp, also fix lib exporting if buildtype=debug, credits anru@github 3 | 4 | 1.2.1: Nov 3, 2013 5 | * bundled zlib in order to improve compatibility with systems with no zlib installed (windows) 6 | 7 | 1.2.0: Mar 22, 2013 8 | * compatibility with node 0.10.0 (converted to GYP) 9 | 10 | 1.1.0: Jul 1, 2012 11 | * compatibility with node 0.8.0 12 | 13 | 1.0.0: May 27, 2012 14 | * it's perfect now 15 | 16 | 0.5.1: November 7, 2011 17 | * uncompress memory management bug fixed 18 | 19 | 0.5.0: November 5, 2011 20 | * uncompress is now cyclic: allocs as much memory as needed, not just 1GB for all cases 21 | 22 | 0.4.2: October 31, 2011 23 | * remove include of node_events.h (depricated) 24 | 25 | 0.4.1: September 21, 2011 26 | * support for string compression was eliminated. It's just not right. Want it back? See the source code. 27 | 28 | 0.4.0: September 18, 2011 29 | * fixed major bug with the compression of extremely small buffers 30 | 31 | 0.3.2: September 17, 2011 32 | * build system fixed 33 | 34 | 0.3.1: September 14, 2011 35 | * node 0.5.x support 36 | 37 | 0.2.0: March 20, 2011 38 | * single initialization of strm (a few times faster for multiple compressions) 39 | * got rid of C++ object, make methods direct 40 | * got rid of JS Class layer, call C++ functions directly 41 | * move Strings/Buffers logic to C++ 42 | * thanks to Konstantin Käfer! 43 | 44 | 0.1.0: March 20, 2011 45 | * initial release 46 | 47 | 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | node-compress-buffer (C) 2011-2013 Egor Egorov 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated a long time ago 2 | 3 | This project has been created when no compression library existed for Node.js. This isn't the case for years. This repository is mainly kept for backward compatibility with some of the very ancient software of mine. 4 | 5 | ## node-compress-buffer 6 | 7 | Synchronous zlib Buffer compression library for Node.js. 8 | 9 | 10 | ## Synopsis 11 | 12 | ```javascript 13 | compress = require('compress-buffer').compress; 14 | uncompress = require('compress-buffer').uncompress; 15 | 16 | var rawData = fs.readFileSync("/etc/passwd"); 17 | 18 | var compressed = compress(rawData); 19 | var uncompressed = uncompress(compressed); 20 | 21 | uncompressed == rawData // true! 22 | ``` 23 | 24 | 25 | ## Why? 26 | 27 | For the sake of the KISS principle. Most of the time you don't need a streaming compression, you need to compress an existing and already complete data. 28 | 29 | 30 | ## Options 31 | 32 | compress() takes two arguments: the data (must be a Buffer()) and optional compression level which must be within 1..9. It returns compressed Buffer() or undefined on error. 33 | 34 | uncompress() takes a single argument: the data (must be a Buffer()) and returns uncompressed Buffer() or undefined on error. 35 | 36 | Both functions could throw exceptions in the following cases: 37 | 38 | * zlib initialisation fails; 39 | * first argument is not a Buffer instance. 40 | 41 | 42 | ## Installation 43 | 44 | npm install compress-buffer 45 | 46 | or 47 | 48 | npm install . 49 | 50 | 51 | ## License 52 | 53 | See LICENSE file. Basically, it's a kind of "do-whatever-you-want-for-free" license. 54 | 55 | 56 | ## Thanks to 57 | 58 | * A lot of thanks for important suggestions goes to Konstantin Käfer who implemented a nice similar module node-zlib (https://github.com/kkaefer/node-zlib) earlier than me; 59 | * Oleg Kertanov, pccowboy, addisonj, David Swift 60 | 61 | ## Author 62 | 63 | Egor Egorov . 64 | 65 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "compress_buffer_bindings", 5 | "sources": [ "src/compress-buffer.cc" ], 6 | "dependencies": [ 7 | "deps/zlib/zlib.gyp:zlib" 8 | ] 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /deps/zlib/.gitignore: -------------------------------------------------------------------------------- 1 | configure.log 2 | *.o 3 | example 4 | example64 5 | foo.gz 6 | libz.a 7 | minigzip 8 | minigzip64 9 | zlib.pc 10 | 11 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/zlib/Makefile: -------------------------------------------------------------------------------- 1 | ZLIBS=contrib/minizip/ioapi.o \ 2 | contrib/minizip/unzip.o \ 3 | contrib/minizip/zip.o \ 4 | adler32.o \ 5 | compress.o \ 6 | crc32.o \ 7 | deflate.o \ 8 | gzio.o \ 9 | infback.o \ 10 | inffast.o \ 11 | inflate.o \ 12 | inftrees.o \ 13 | trees.o \ 14 | uncompr.o \ 15 | zutil.o 16 | 17 | libz.a: ${ZLIBS} 18 | $(AR) rvs libz.a ${ZLIBS} 19 | 20 | %.o: %.c 21 | $(CC) -c $< -o $@ 22 | 23 | clean: 24 | rm -f *.o *.a 25 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/zlib/crc32.c: -------------------------------------------------------------------------------- 1 | /* crc32.c -- compute the CRC-32 of a data stream 2 | * Copyright (C) 1995-2005 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | * 5 | * Thanks to Rodney Brown for his contribution of faster 6 | * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing 7 | * tables for updating the shift register in one step with three exclusive-ors 8 | * instead of four steps with four exclusive-ors. This results in about a 9 | * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. 10 | */ 11 | 12 | /* @(#) $Id: crc32.c,v 3.6 2005/08/04 19:14:14 tor%cs.brown.edu Exp $ */ 13 | 14 | /* 15 | Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore 16 | protection on the static variables used to control the first-use generation 17 | of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should 18 | first call get_crc_table() to initialize the tables before allowing more than 19 | one thread to use crc32(). 20 | */ 21 | 22 | #ifdef MAKECRCH 23 | # include 24 | # ifndef DYNAMIC_CRC_TABLE 25 | # define DYNAMIC_CRC_TABLE 26 | # endif /* !DYNAMIC_CRC_TABLE */ 27 | #endif /* MAKECRCH */ 28 | 29 | #include "zutil.h" /* for STDC and FAR definitions */ 30 | 31 | #define local static 32 | 33 | /* Find a four-byte integer type for crc32_little() and crc32_big(). */ 34 | #ifndef NOBYFOUR 35 | # ifdef STDC /* need ANSI C limits.h to determine sizes */ 36 | # include 37 | # define BYFOUR 38 | # if (UINT_MAX == 0xffffffffUL) 39 | typedef unsigned int u4; 40 | # else 41 | # if (ULONG_MAX == 0xffffffffUL) 42 | typedef unsigned long u4; 43 | # else 44 | # if (USHRT_MAX == 0xffffffffUL) 45 | typedef unsigned short u4; 46 | # else 47 | # undef BYFOUR /* can't find a four-byte integer type! */ 48 | # endif 49 | # endif 50 | # endif 51 | # endif /* STDC */ 52 | #endif /* !NOBYFOUR */ 53 | 54 | /* Definitions for doing the crc four data bytes at a time. */ 55 | #ifdef BYFOUR 56 | # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \ 57 | (((w)&0xff00)<<8)+(((w)&0xff)<<24)) 58 | local unsigned long crc32_little OF((unsigned long, 59 | const unsigned char FAR *, unsigned)); 60 | local unsigned long crc32_big OF((unsigned long, 61 | const unsigned char FAR *, unsigned)); 62 | # define TBLS 8 63 | #else 64 | # define TBLS 1 65 | #endif /* BYFOUR */ 66 | 67 | /* Local functions for crc concatenation */ 68 | local unsigned long gf2_matrix_times OF((unsigned long *mat, 69 | unsigned long vec)); 70 | local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); 71 | 72 | #ifdef DYNAMIC_CRC_TABLE 73 | 74 | local volatile int crc_table_empty = 1; 75 | local unsigned long FAR crc_table[TBLS][256]; 76 | local void make_crc_table OF((void)); 77 | #ifdef MAKECRCH 78 | local void write_table OF((FILE *, const unsigned long FAR *)); 79 | #endif /* MAKECRCH */ 80 | /* 81 | Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: 82 | x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. 83 | 84 | Polynomials over GF(2) are represented in binary, one bit per coefficient, 85 | with the lowest powers in the most significant bit. Then adding polynomials 86 | is just exclusive-or, and multiplying a polynomial by x is a right shift by 87 | one. If we call the above polynomial p, and represent a byte as the 88 | polynomial q, also with the lowest power in the most significant bit (so the 89 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 90 | where a mod b means the remainder after dividing a by b. 91 | 92 | This calculation is done using the shift-register method of multiplying and 93 | taking the remainder. The register is initialized to zero, and for each 94 | incoming bit, x^32 is added mod p to the register if the bit is a one (where 95 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 96 | x (which is shifting right by one and adding x^32 mod p if the bit shifted 97 | out is a one). We start with the highest power (least significant bit) of 98 | q and repeat for all eight bits of q. 99 | 100 | The first table is simply the CRC of all possible eight bit values. This is 101 | all the information needed to generate CRCs on data a byte at a time for all 102 | combinations of CRC register values and incoming bytes. The remaining tables 103 | allow for word-at-a-time CRC calculation for both big-endian and little- 104 | endian machines, where a word is four bytes. 105 | */ 106 | local void make_crc_table() 107 | { 108 | unsigned long c; 109 | int n, k; 110 | unsigned long poly; /* polynomial exclusive-or pattern */ 111 | /* terms of polynomial defining this crc (except x^32): */ 112 | static volatile int first = 1; /* flag to limit concurrent making */ 113 | static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 114 | 115 | /* See if another task is already doing this (not thread-safe, but better 116 | than nothing -- significantly reduces duration of vulnerability in 117 | case the advice about DYNAMIC_CRC_TABLE is ignored) */ 118 | if (first) { 119 | first = 0; 120 | 121 | /* make exclusive-or pattern from polynomial (0xedb88320UL) */ 122 | poly = 0UL; 123 | for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) 124 | poly |= 1UL << (31 - p[n]); 125 | 126 | /* generate a crc for every 8-bit value */ 127 | for (n = 0; n < 256; n++) { 128 | c = (unsigned long)n; 129 | for (k = 0; k < 8; k++) 130 | c = c & 1 ? poly ^ (c >> 1) : c >> 1; 131 | crc_table[0][n] = c; 132 | } 133 | 134 | #ifdef BYFOUR 135 | /* generate crc for each value followed by one, two, and three zeros, 136 | and then the byte reversal of those as well as the first table */ 137 | for (n = 0; n < 256; n++) { 138 | c = crc_table[0][n]; 139 | crc_table[4][n] = REV(c); 140 | for (k = 1; k < 4; k++) { 141 | c = crc_table[0][c & 0xff] ^ (c >> 8); 142 | crc_table[k][n] = c; 143 | crc_table[k + 4][n] = REV(c); 144 | } 145 | } 146 | #endif /* BYFOUR */ 147 | 148 | crc_table_empty = 0; 149 | } 150 | else { /* not first */ 151 | /* wait for the other guy to finish (not efficient, but rare) */ 152 | while (crc_table_empty) 153 | ; 154 | } 155 | 156 | #ifdef MAKECRCH 157 | /* write out CRC tables to crc32.h */ 158 | { 159 | FILE *out; 160 | 161 | out = fopen("crc32.h", "w"); 162 | if (out == NULL) return; 163 | fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); 164 | fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); 165 | fprintf(out, "local const unsigned long FAR "); 166 | fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); 167 | write_table(out, crc_table[0]); 168 | # ifdef BYFOUR 169 | fprintf(out, "#ifdef BYFOUR\n"); 170 | for (k = 1; k < 8; k++) { 171 | fprintf(out, " },\n {\n"); 172 | write_table(out, crc_table[k]); 173 | } 174 | fprintf(out, "#endif\n"); 175 | # endif /* BYFOUR */ 176 | fprintf(out, " }\n};\n"); 177 | fclose(out); 178 | } 179 | #endif /* MAKECRCH */ 180 | } 181 | 182 | #ifdef MAKECRCH 183 | local void write_table(out, table) 184 | FILE *out; 185 | const unsigned long FAR *table; 186 | { 187 | int n; 188 | 189 | for (n = 0; n < 256; n++) 190 | fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], 191 | n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); 192 | } 193 | #endif /* MAKECRCH */ 194 | 195 | #else /* !DYNAMIC_CRC_TABLE */ 196 | /* ======================================================================== 197 | * Tables of CRC-32s of all single-byte values, made by make_crc_table(). 198 | */ 199 | #include "crc32.h" 200 | #endif /* DYNAMIC_CRC_TABLE */ 201 | 202 | /* ========================================================================= 203 | * This function can be used by asm versions of crc32() 204 | */ 205 | const unsigned long FAR * ZEXPORT get_crc_table() 206 | { 207 | #ifdef DYNAMIC_CRC_TABLE 208 | if (crc_table_empty) 209 | make_crc_table(); 210 | #endif /* DYNAMIC_CRC_TABLE */ 211 | return (const unsigned long FAR *)crc_table; 212 | } 213 | 214 | /* ========================================================================= */ 215 | #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) 216 | #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 217 | 218 | /* ========================================================================= */ 219 | unsigned long ZEXPORT crc32(crc, buf, len) 220 | unsigned long crc; 221 | const unsigned char FAR *buf; 222 | unsigned len; 223 | { 224 | if (buf == Z_NULL) return 0UL; 225 | 226 | #ifdef DYNAMIC_CRC_TABLE 227 | if (crc_table_empty) 228 | make_crc_table(); 229 | #endif /* DYNAMIC_CRC_TABLE */ 230 | 231 | #ifdef BYFOUR 232 | if (sizeof(void *) == sizeof(ptrdiff_t)) { 233 | u4 endian; 234 | 235 | endian = 1; 236 | if (*((unsigned char *)(&endian))) 237 | return crc32_little(crc, buf, len); 238 | else 239 | return crc32_big(crc, buf, len); 240 | } 241 | #endif /* BYFOUR */ 242 | crc = crc ^ 0xffffffffUL; 243 | while (len >= 8) { 244 | DO8; 245 | len -= 8; 246 | } 247 | if (len) do { 248 | DO1; 249 | } while (--len); 250 | return crc ^ 0xffffffffUL; 251 | } 252 | 253 | #ifdef BYFOUR 254 | 255 | /* ========================================================================= */ 256 | #define DOLIT4 c ^= *buf4++; \ 257 | c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ 258 | crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] 259 | #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 260 | 261 | /* ========================================================================= */ 262 | local unsigned long crc32_little(crc, buf, len) 263 | unsigned long crc; 264 | const unsigned char FAR *buf; 265 | unsigned len; 266 | { 267 | register u4 c; 268 | register const u4 FAR *buf4; 269 | 270 | c = (u4)crc; 271 | c = ~c; 272 | while (len && ((ptrdiff_t)buf & 3)) { 273 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 274 | len--; 275 | } 276 | 277 | buf4 = (const u4 FAR *)(const void FAR *)buf; 278 | while (len >= 32) { 279 | DOLIT32; 280 | len -= 32; 281 | } 282 | while (len >= 4) { 283 | DOLIT4; 284 | len -= 4; 285 | } 286 | buf = (const unsigned char FAR *)buf4; 287 | 288 | if (len) do { 289 | c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 290 | } while (--len); 291 | c = ~c; 292 | return (unsigned long)c; 293 | } 294 | 295 | /* ========================================================================= */ 296 | #define DOBIG4 c ^= *++buf4; \ 297 | c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ 298 | crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] 299 | #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 300 | 301 | /* ========================================================================= */ 302 | local unsigned long crc32_big(crc, buf, len) 303 | unsigned long crc; 304 | const unsigned char FAR *buf; 305 | unsigned len; 306 | { 307 | register u4 c; 308 | register const u4 FAR *buf4; 309 | 310 | c = REV((u4)crc); 311 | c = ~c; 312 | while (len && ((ptrdiff_t)buf & 3)) { 313 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 314 | len--; 315 | } 316 | 317 | buf4 = (const u4 FAR *)(const void FAR *)buf; 318 | buf4--; 319 | while (len >= 32) { 320 | DOBIG32; 321 | len -= 32; 322 | } 323 | while (len >= 4) { 324 | DOBIG4; 325 | len -= 4; 326 | } 327 | buf4++; 328 | buf = (const unsigned char FAR *)buf4; 329 | 330 | if (len) do { 331 | c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 332 | } while (--len); 333 | c = ~c; 334 | return (unsigned long)(REV(c)); 335 | } 336 | 337 | #endif /* BYFOUR */ 338 | 339 | #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ 340 | 341 | /* ========================================================================= */ 342 | local unsigned long gf2_matrix_times(mat, vec) 343 | unsigned long *mat; 344 | unsigned long vec; 345 | { 346 | unsigned long sum; 347 | 348 | sum = 0; 349 | while (vec) { 350 | if (vec & 1) 351 | sum ^= *mat; 352 | vec >>= 1; 353 | mat++; 354 | } 355 | return sum; 356 | } 357 | 358 | /* ========================================================================= */ 359 | local void gf2_matrix_square(square, mat) 360 | unsigned long *square; 361 | unsigned long *mat; 362 | { 363 | int n; 364 | 365 | for (n = 0; n < GF2_DIM; n++) 366 | square[n] = gf2_matrix_times(mat, mat[n]); 367 | } 368 | 369 | /* ========================================================================= */ 370 | uLong ZEXPORT crc32_combine(crc1, crc2, len2) 371 | uLong crc1; 372 | uLong crc2; 373 | z_off_t len2; 374 | { 375 | int n; 376 | unsigned long row; 377 | unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ 378 | unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ 379 | 380 | /* degenerate case */ 381 | if (len2 == 0) 382 | return crc1; 383 | 384 | /* put operator for one zero bit in odd */ 385 | odd[0] = 0xedb88320L; /* CRC-32 polynomial */ 386 | row = 1; 387 | for (n = 1; n < GF2_DIM; n++) { 388 | odd[n] = row; 389 | row <<= 1; 390 | } 391 | 392 | /* put operator for two zero bits in even */ 393 | gf2_matrix_square(even, odd); 394 | 395 | /* put operator for four zero bits in odd */ 396 | gf2_matrix_square(odd, even); 397 | 398 | /* apply len2 zeros to crc1 (first square will put the operator for one 399 | zero byte, eight zero bits, in even) */ 400 | do { 401 | /* apply zeros operator for this bit of len2 */ 402 | gf2_matrix_square(even, odd); 403 | if (len2 & 1) 404 | crc1 = gf2_matrix_times(even, crc1); 405 | len2 >>= 1; 406 | 407 | /* if no more bits set, then done */ 408 | if (len2 == 0) 409 | break; 410 | 411 | /* another iteration of the loop with odd and even swapped */ 412 | gf2_matrix_square(odd, even); 413 | if (len2 & 1) 414 | crc1 = gf2_matrix_times(odd, crc1); 415 | len2 >>= 1; 416 | 417 | /* if no more bits set, then done */ 418 | } while (len2 != 0); 419 | 420 | /* return combined crc */ 421 | crc1 ^= crc2; 422 | return crc1; 423 | } 424 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/zlib/inftrees.c: -------------------------------------------------------------------------------- 1 | /* inftrees.c -- generate Huffman trees for efficient decoding 2 | * Copyright (C) 1995-2005 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 | 9 | #define MAXBITS 15 10 | 11 | const char inflate_copyright[] = 12 | " inflate 1.2.3 Copyright 1995-2005 Mark Adler "; 13 | /* 14 | If you use the zlib library in a product, an acknowledgment is welcome 15 | in the documentation of your product. If for some reason you cannot 16 | include such an acknowledgment, I would appreciate that you keep this 17 | copyright string in the executable of your product. 18 | */ 19 | 20 | /* 21 | Build a set of tables to decode the provided canonical Huffman code. 22 | The code lengths are lens[0..codes-1]. The result starts at *table, 23 | whose indices are 0..2^bits-1. work is a writable array of at least 24 | lens shorts, which is used as a work area. type is the type of code 25 | to be generated, CODES, LENS, or DISTS. On return, zero is success, 26 | -1 is an invalid code, and +1 means that ENOUGH isn't enough. table 27 | on return points to the next available entry's address. bits is the 28 | requested root table index bits, and on return it is the actual root 29 | table index bits. It will differ if the request is greater than the 30 | longest code or if it is less than the shortest code. 31 | */ 32 | int inflate_table(type, lens, codes, table, bits, work) 33 | codetype type; 34 | unsigned short FAR *lens; 35 | unsigned codes; 36 | code FAR * FAR *table; 37 | unsigned FAR *bits; 38 | unsigned short FAR *work; 39 | { 40 | unsigned len; /* a code's length in bits */ 41 | unsigned sym; /* index of code symbols */ 42 | unsigned min, max; /* minimum and maximum code lengths */ 43 | unsigned root; /* number of index bits for root table */ 44 | unsigned curr; /* number of index bits for current table */ 45 | unsigned drop; /* code bits to drop for sub-table */ 46 | int left; /* number of prefix codes available */ 47 | unsigned used; /* code entries in table used */ 48 | unsigned huff; /* Huffman code */ 49 | unsigned incr; /* for incrementing code, index */ 50 | unsigned fill; /* index for replicating entries */ 51 | unsigned low; /* low bits for current root entry */ 52 | unsigned mask; /* mask for low root bits */ 53 | code this; /* table entry for duplication */ 54 | code FAR *next; /* next available space in table */ 55 | const unsigned short FAR *base; /* base value table to use */ 56 | const unsigned short FAR *extra; /* extra bits table to use */ 57 | int end; /* use base and extra for symbol > end */ 58 | unsigned short count[MAXBITS+1]; /* number of codes of each length */ 59 | unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ 60 | static const unsigned short lbase[31] = { /* Length codes 257..285 base */ 61 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 62 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; 63 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 64 | 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 65 | 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196}; 66 | static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 67 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 68 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 69 | 8193, 12289, 16385, 24577, 0, 0}; 70 | static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ 71 | 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 72 | 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 73 | 28, 28, 29, 29, 64, 64}; 74 | 75 | /* 76 | Process a set of code lengths to create a canonical Huffman code. The 77 | code lengths are lens[0..codes-1]. Each length corresponds to the 78 | symbols 0..codes-1. The Huffman code is generated by first sorting the 79 | symbols by length from short to long, and retaining the symbol order 80 | for codes with equal lengths. Then the code starts with all zero bits 81 | for the first code of the shortest length, and the codes are integer 82 | increments for the same length, and zeros are appended as the length 83 | increases. For the deflate format, these bits are stored backwards 84 | from their more natural integer increment ordering, and so when the 85 | decoding tables are built in the large loop below, the integer codes 86 | are incremented backwards. 87 | 88 | This routine assumes, but does not check, that all of the entries in 89 | lens[] are in the range 0..MAXBITS. The caller must assure this. 90 | 1..MAXBITS is interpreted as that code length. zero means that that 91 | symbol does not occur in this code. 92 | 93 | The codes are sorted by computing a count of codes for each length, 94 | creating from that a table of starting indices for each length in the 95 | sorted table, and then entering the symbols in order in the sorted 96 | table. The sorted table is work[], with that space being provided by 97 | the caller. 98 | 99 | The length counts are used for other purposes as well, i.e. finding 100 | the minimum and maximum length codes, determining if there are any 101 | codes at all, checking for a valid set of lengths, and looking ahead 102 | at length counts to determine sub-table sizes when building the 103 | decoding tables. 104 | */ 105 | 106 | /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ 107 | for (len = 0; len <= MAXBITS; len++) 108 | count[len] = 0; 109 | for (sym = 0; sym < codes; sym++) 110 | count[lens[sym]]++; 111 | 112 | /* bound code lengths, force root to be within code lengths */ 113 | root = *bits; 114 | for (max = MAXBITS; max >= 1; max--) 115 | if (count[max] != 0) break; 116 | if (root > max) root = max; 117 | if (max == 0) { /* no symbols to code at all */ 118 | this.op = (unsigned char)64; /* invalid code marker */ 119 | this.bits = (unsigned char)1; 120 | this.val = (unsigned short)0; 121 | *(*table)++ = this; /* make a table to force an error */ 122 | *(*table)++ = this; 123 | *bits = 1; 124 | return 0; /* no symbols, but wait for decoding to report error */ 125 | } 126 | for (min = 1; min <= MAXBITS; min++) 127 | if (count[min] != 0) break; 128 | if (root < min) root = min; 129 | 130 | /* check for an over-subscribed or incomplete set of lengths */ 131 | left = 1; 132 | for (len = 1; len <= MAXBITS; len++) { 133 | left <<= 1; 134 | left -= count[len]; 135 | if (left < 0) return -1; /* over-subscribed */ 136 | } 137 | if (left > 0 && (type == CODES || max != 1)) 138 | return -1; /* incomplete set */ 139 | 140 | /* generate offsets into symbol table for each length for sorting */ 141 | offs[1] = 0; 142 | for (len = 1; len < MAXBITS; len++) 143 | offs[len + 1] = offs[len] + count[len]; 144 | 145 | /* sort symbols by length, by symbol order within each length */ 146 | for (sym = 0; sym < codes; sym++) 147 | if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; 148 | 149 | /* 150 | Create and fill in decoding tables. In this loop, the table being 151 | filled is at next and has curr index bits. The code being used is huff 152 | with length len. That code is converted to an index by dropping drop 153 | bits off of the bottom. For codes where len is less than drop + curr, 154 | those top drop + curr - len bits are incremented through all values to 155 | fill the table with replicated entries. 156 | 157 | root is the number of index bits for the root table. When len exceeds 158 | root, sub-tables are created pointed to by the root entry with an index 159 | of the low root bits of huff. This is saved in low to check for when a 160 | new sub-table should be started. drop is zero when the root table is 161 | being filled, and drop is root when sub-tables are being filled. 162 | 163 | When a new sub-table is needed, it is necessary to look ahead in the 164 | code lengths to determine what size sub-table is needed. The length 165 | counts are used for this, and so count[] is decremented as codes are 166 | entered in the tables. 167 | 168 | used keeps track of how many table entries have been allocated from the 169 | provided *table space. It is checked when a LENS table is being made 170 | against the space in *table, ENOUGH, minus the maximum space needed by 171 | the worst case distance code, MAXD. This should never happen, but the 172 | sufficiency of ENOUGH has not been proven exhaustively, hence the check. 173 | This assumes that when type == LENS, bits == 9. 174 | 175 | sym increments through all symbols, and the loop terminates when 176 | all codes of length max, i.e. all codes, have been processed. This 177 | routine permits incomplete codes, so another loop after this one fills 178 | in the rest of the decoding tables with invalid code markers. 179 | */ 180 | 181 | /* set up for code type */ 182 | switch (type) { 183 | case CODES: 184 | base = extra = work; /* dummy value--not used */ 185 | end = 19; 186 | break; 187 | case LENS: 188 | base = lbase; 189 | base -= 257; 190 | extra = lext; 191 | extra -= 257; 192 | end = 256; 193 | break; 194 | default: /* DISTS */ 195 | base = dbase; 196 | extra = dext; 197 | end = -1; 198 | } 199 | 200 | /* initialize state for loop */ 201 | huff = 0; /* starting code */ 202 | sym = 0; /* starting code symbol */ 203 | len = min; /* starting code length */ 204 | next = *table; /* current table to fill in */ 205 | curr = root; /* current table index bits */ 206 | drop = 0; /* current bits to drop from code for index */ 207 | low = (unsigned)(-1); /* trigger new sub-table when len > root */ 208 | used = 1U << root; /* use root table entries */ 209 | mask = used - 1; /* mask for comparing low */ 210 | 211 | /* check available table space */ 212 | if (type == LENS && used >= ENOUGH - MAXD) 213 | return 1; 214 | 215 | /* process all codes and make table entries */ 216 | for (;;) { 217 | /* create table entry */ 218 | this.bits = (unsigned char)(len - drop); 219 | if ((int)(work[sym]) < end) { 220 | this.op = (unsigned char)0; 221 | this.val = work[sym]; 222 | } 223 | else if ((int)(work[sym]) > end) { 224 | this.op = (unsigned char)(extra[work[sym]]); 225 | this.val = base[work[sym]]; 226 | } 227 | else { 228 | this.op = (unsigned char)(32 + 64); /* end of block */ 229 | this.val = 0; 230 | } 231 | 232 | /* replicate for those indices with low len bits equal to huff */ 233 | incr = 1U << (len - drop); 234 | fill = 1U << curr; 235 | min = fill; /* save offset to next table */ 236 | do { 237 | fill -= incr; 238 | next[(huff >> drop) + fill] = this; 239 | } while (fill != 0); 240 | 241 | /* backwards increment the len-bit code huff */ 242 | incr = 1U << (len - 1); 243 | while (huff & incr) 244 | incr >>= 1; 245 | if (incr != 0) { 246 | huff &= incr - 1; 247 | huff += incr; 248 | } 249 | else 250 | huff = 0; 251 | 252 | /* go to next symbol, update count, len */ 253 | sym++; 254 | if (--(count[len]) == 0) { 255 | if (len == max) break; 256 | len = lens[work[sym]]; 257 | } 258 | 259 | /* create new sub-table if needed */ 260 | if (len > root && (huff & mask) != low) { 261 | /* if first time, transition to sub-tables */ 262 | if (drop == 0) 263 | drop = root; 264 | 265 | /* increment past last table */ 266 | next += min; /* here min is 1 << curr */ 267 | 268 | /* determine length of next table */ 269 | curr = len - drop; 270 | left = (int)(1 << curr); 271 | while (curr + drop < max) { 272 | left -= count[curr + drop]; 273 | if (left <= 0) break; 274 | curr++; 275 | left <<= 1; 276 | } 277 | 278 | /* check for enough space */ 279 | used += 1U << curr; 280 | if (type == LENS && used >= ENOUGH - MAXD) 281 | return 1; 282 | 283 | /* point entry in root table to sub-table */ 284 | low = huff & mask; 285 | (*table)[low].op = (unsigned char)curr; 286 | (*table)[low].bits = (unsigned char)root; 287 | (*table)[low].val = (unsigned short)(next - *table); 288 | } 289 | } 290 | 291 | /* 292 | Fill in rest of table for incomplete codes. This loop is similar to the 293 | loop above in incrementing huff for table indices. It is assumed that 294 | len is equal to curr + drop, so there is no loop needed to increment 295 | through high index bits. When the current sub-table is filled, the loop 296 | drops back to the root table to fill in any remaining entries there. 297 | */ 298 | this.op = (unsigned char)64; /* invalid code marker */ 299 | this.bits = (unsigned char)(len - drop); 300 | this.val = (unsigned short)0; 301 | while (huff != 0) { 302 | /* when done with sub-table, drop back to root table */ 303 | if (drop != 0 && (huff & mask) != low) { 304 | drop = 0; 305 | len = root; 306 | next = *table; 307 | this.bits = (unsigned char)len; 308 | } 309 | 310 | /* put invalid code marker in table */ 311 | next[huff >> drop] = this; 312 | 313 | /* backwards increment the len-bit code huff */ 314 | incr = 1U << (len - 1); 315 | while (huff & incr) 316 | incr >>= 1; 317 | if (incr != 0) { 318 | huff &= incr - 1; 319 | huff += incr; 320 | } 321 | else 322 | huff = 0; 323 | } 324 | 325 | /* set return parameters */ 326 | *table += used; 327 | *bits = root; 328 | return 0; 329 | } 330 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | # For contrib/minizip 57 | './contrib/minizip', 58 | ], 59 | }, 60 | 'conditions': [ 61 | ['OS!="win"', { 62 | 'product_name': 'chrome_zlib', 63 | 'cflags!': [ '-ansi' ], 64 | 'sources!': [ 65 | 'contrib/minizip/iowin32.c' 66 | ], 67 | }], 68 | ], 69 | }, 70 | ], 71 | }, { 72 | 'targets': [ 73 | { 74 | 'target_name': 'zlib', 75 | 'type': 'static_library', 76 | 'direct_dependent_settings': { 77 | 'defines': [ 78 | 'USE_SYSTEM_ZLIB', 79 | ], 80 | }, 81 | 'defines': [ 82 | 'USE_SYSTEM_ZLIB', 83 | ], 84 | 'sources': [ 85 | 'contrib/minizip/ioapi.c', 86 | 'contrib/minizip/ioapi.h', 87 | 'contrib/minizip/unzip.c', 88 | 'contrib/minizip/unzip.h', 89 | 'contrib/minizip/zip.c', 90 | 'contrib/minizip/zip.h', 91 | ], 92 | 'link_settings': { 93 | 'libraries': [ 94 | '-lz', 95 | ], 96 | }, 97 | }, 98 | ], 99 | }], 100 | ], 101 | } 102 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /deps/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 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('bindings')('compress_buffer_bindings'); 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "compress-buffer", 3 | "description": "Synchronous Buffer compression library for Node.js", 4 | "homepage": "http://egorfine.github.com/node-compress-buffer", 5 | "bugs": { 6 | "url": "http://github.com/egorFiNE/node-compress-buffer/issues" 7 | }, 8 | "version": "1.2.2", 9 | "author": "Egor Egorov", 10 | "repository": { 11 | "type": "git", 12 | "url": "http://github.com/egorfine/node-compress-buffer.git" 13 | }, 14 | "main": "./index", 15 | "devDependencies": { 16 | "nodeunit": ">=0.5.4" 17 | }, 18 | "dependencies": { 19 | "bindings": "~1.2.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/compress-buffer.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #ifdef __APPLE__ 9 | #include 10 | #endif 11 | #include 12 | 13 | // zlib magic something 14 | #define WBITS 16+MAX_WBITS 15 | 16 | #define CHUNK 1024*100 17 | 18 | z_stream strmCompress; 19 | 20 | using namespace v8; 21 | using namespace node; 22 | 23 | Handle ThrowNodeError(const char* what = NULL) { 24 | return ThrowException(Exception::Error(String::New(what))); 25 | } 26 | 27 | Handle compress(const Arguments& args) { 28 | HandleScope scope; 29 | size_t bytesIn=0; 30 | size_t bytesCompressed=0; 31 | char *dataPointer=NULL; 32 | bool shouldFreeDataPointer=false; 33 | 34 | if (args.Length() < 1) { 35 | return Undefined(); 36 | } 37 | 38 | if (!Buffer::HasInstance(args[0])) { 39 | ThrowNodeError("First argument must be a Buffer"); 40 | return Undefined(); 41 | } 42 | 43 | Local bufferIn=args[0]->ToObject(); 44 | bytesIn=Buffer::Length(bufferIn); 45 | 46 | dataPointer=Buffer::Data(bufferIn); 47 | 48 | int compressionLevel = Z_DEFAULT_COMPRESSION; 49 | if (args.Length() > 1) { 50 | compressionLevel = args[1]->IntegerValue(); 51 | if (compressionLevel <= 0 || compressionLevel > 9) { 52 | compressionLevel = Z_DEFAULT_COMPRESSION; 53 | } 54 | } 55 | 56 | deflateParams(&strmCompress, compressionLevel, Z_DEFAULT_STRATEGY); 57 | 58 | bytesCompressed=compressBound(bytesIn); 59 | 60 | // compressBound mistakes when estimating extremely small data blocks (like few bytes), so 61 | // here is the stub. Otherwise smaller buffers (like 10 bytes) would not compress. 62 | if (bytesCompressed<1024) { 63 | bytesCompressed=1024; 64 | } 65 | 66 | char *bufferOut=(char*) malloc(bytesCompressed); 67 | 68 | strmCompress.next_in=(Bytef*) dataPointer; 69 | strmCompress.avail_in=bytesIn; 70 | strmCompress.next_out=(Bytef*) bufferOut; 71 | strmCompress.avail_out=bytesCompressed; 72 | 73 | if (deflate(&strmCompress, Z_FINISH) != Z_STREAM_END) { 74 | deflateReset(&strmCompress); 75 | if (shouldFreeDataPointer) { 76 | free(dataPointer); 77 | dataPointer = NULL; 78 | } 79 | return Undefined(); 80 | } 81 | 82 | bytesCompressed=strmCompress.total_out; 83 | deflateReset(&strmCompress); 84 | 85 | Buffer *BufferOut=Buffer::New(bufferOut, bytesCompressed); 86 | free(bufferOut); 87 | 88 | if (shouldFreeDataPointer) { 89 | free(dataPointer); 90 | dataPointer = NULL; 91 | } 92 | 93 | return scope.Close(BufferOut->handle_); 94 | } 95 | 96 | 97 | Handle uncompress(const Arguments &args) { 98 | if (args.Length() < 1) { 99 | return Undefined(); 100 | } 101 | 102 | if (!Buffer::HasInstance(args[0])) { 103 | ThrowNodeError("First argument must be a Buffer"); 104 | return Undefined(); 105 | } 106 | 107 | z_stream strmUncompress; 108 | 109 | strmUncompress.zalloc=Z_NULL; 110 | strmUncompress.zfree=Z_NULL; 111 | strmUncompress.opaque=Z_NULL; 112 | strmUncompress.avail_in = 0; 113 | strmUncompress.next_in = Z_NULL; 114 | 115 | int rci = inflateInit2(&strmUncompress, WBITS); 116 | 117 | if (rci != Z_OK) { 118 | ThrowNodeError("zlib initialization error."); 119 | return Undefined(); 120 | } 121 | 122 | Local bufferIn=args[0]->ToObject(); 123 | 124 | strmUncompress.next_in = (Bytef*) Buffer::Data(bufferIn); 125 | strmUncompress.avail_in = Buffer::Length(bufferIn); 126 | 127 | Bytef *bufferOut = NULL; 128 | uint32_t malloc_size=0; 129 | uint32_t currentPosition=0; 130 | 131 | int ret; 132 | 133 | do { 134 | Bytef *tmp = (Bytef*)malloc(CHUNK); 135 | strmUncompress.avail_out = CHUNK; 136 | strmUncompress.next_out = tmp; 137 | 138 | ret = inflate(&strmUncompress, Z_NO_FLUSH); 139 | assert(ret != Z_STREAM_ERROR); 140 | switch (ret) { 141 | case Z_NEED_DICT: 142 | ret = Z_DATA_ERROR; /* and fall through */ 143 | case Z_DATA_ERROR: 144 | case Z_MEM_ERROR: 145 | (void)inflateEnd(&strmUncompress); 146 | if (bufferOut!=NULL) { 147 | free(bufferOut); 148 | } 149 | if (tmp!=NULL) { 150 | free(tmp); 151 | } 152 | return Undefined(); 153 | } 154 | 155 | uint32_t have = CHUNK - strmUncompress.avail_out; 156 | if (have>0) { 157 | bufferOut = (Bytef *) realloc(bufferOut, malloc_size+have); 158 | malloc_size=malloc_size+have; 159 | } 160 | 161 | memcpy(bufferOut+currentPosition, tmp, have); 162 | currentPosition+=have; 163 | free(tmp); 164 | } while (strmUncompress.avail_out == 0 && ret != Z_STREAM_END); 165 | 166 | inflateEnd(&strmUncompress); 167 | 168 | if (ret != Z_STREAM_END) { 169 | if (bufferOut!=NULL) { 170 | free(bufferOut); 171 | } 172 | return Undefined(); 173 | } 174 | 175 | Buffer *BufferOut=Buffer::New((char *)bufferOut, malloc_size); 176 | free(bufferOut); 177 | 178 | HandleScope scope; 179 | return scope.Close(BufferOut->handle_); 180 | } 181 | 182 | extern "C" void 183 | init (Handle target) { 184 | strmCompress.zalloc=Z_NULL; 185 | strmCompress.zfree=Z_NULL; 186 | strmCompress.opaque=Z_NULL; 187 | 188 | int rcd = deflateInit2(&strmCompress, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 189 | WBITS, 8L, Z_DEFAULT_STRATEGY); 190 | 191 | if (rcd != Z_OK) { 192 | ThrowNodeError("zlib initialization error."); 193 | return; 194 | } 195 | 196 | NODE_SET_METHOD(target, "compress", compress); 197 | NODE_SET_METHOD(target, "uncompress", uncompress); 198 | } 199 | 200 | NODE_MODULE(compress_buffer_bindings, init); 201 | 202 | -------------------------------------------------------------------------------- /test/node-compress-buffer-test.js: -------------------------------------------------------------------------------- 1 | util = require('util'); 2 | fs = require('fs'); 3 | crypto=require('crypto'); 4 | compress = require('../index').compress; 5 | uncompress = require('../index').uncompress; 6 | 7 | function md5(data) { 8 | var md5=crypto.createHash('md5'); 9 | md5.update(data); 10 | return md5.digest('hex'); 11 | } 12 | 13 | var loremIpsum="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; 14 | 15 | exports['basic compress']= function(test) { 16 | test.expect(2); 17 | var uncompressed = new Buffer(loremIpsum); 18 | var compressed = compress(uncompressed); 19 | test.equal(compressed.length,282); 20 | test.equal(md5(compressed), "6e31946d851b7cab51e058653a16b666"); 21 | test.done(); 22 | } 23 | 24 | exports['basic uncompress']= function(test) { 25 | test.expect(2); 26 | var uncompressed = new Buffer(loremIpsum); 27 | var compressed = compress(uncompressed); 28 | uncompressed = uncompress(compressed); 29 | test.equal(uncompressed.length,loremIpsum.length); 30 | test.equal(md5(uncompressed), "fa5c89f3c88b81bfd5e821b0316569af"); 31 | test.done(); 32 | } 33 | 34 | exports['compress with compression levels']= function(test) { 35 | test.expect(1); 36 | var uncompressedBuffer = fs.readFileSync(__dirname+"/node-compress-buffer-test.js"); 37 | 38 | var compressed1 = compress(uncompressedBuffer, 1); 39 | var compressed9 = compress(uncompressedBuffer, 9); 40 | test.ok(compressed1.length>compressed9.length); 41 | 42 | test.done(); 43 | } 44 | 45 | exports['string exceptions']= function(test) { 46 | test.expect(2); 47 | 48 | test.throws(function() { 49 | compress(loremIpsum); 50 | }); 51 | 52 | test.throws(function() { 53 | uncompress(loremIpsum); 54 | }); 55 | 56 | test.done(); 57 | } 58 | 59 | exports['compress short']= function(test) { 60 | test.expect(2); 61 | var buffer, compressed; 62 | 63 | buffer = new Buffer("too short"); 64 | compressed = compress(buffer); 65 | test.notEqual(compressed,buffer); 66 | test.notEqual(compressed.length,buffer.length); 67 | 68 | test.done(); 69 | } 70 | 71 | exports['errors']= function(test) { 72 | test.expect(2); 73 | var compressed = compress(new Buffer("")); 74 | test.ok(compressed.length>=0); 75 | 76 | var nothing = uncompress(new Buffer(" sfsdcfgdfgsdgfdsgdgdsgdfgsdfgsdfgdfgfsfd ")); 77 | test.ok(nothing==null); 78 | 79 | test.done(); 80 | } 81 | --------------------------------------------------------------------------------