Skip to content

Commit 5b8e1da

Browse files
isaacsry
authored andcommitted
Initial pass at zlib bindings
1 parent dcd911e commit 5b8e1da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+17615
-7
lines changed

LICENSE

+4
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,7 @@ The externally maintained libraries used by Node are:
7373

7474
- tools/gyp GYP is a meta-build system copyright 2009 Google Inc and
7575
licensed under the three clause BSD license. See tools/gyp/LICENSE.
76+
77+
- deps/zlib copyright 1995-2010 Jean-loup Gailly and Mark Adler
78+
licensed under a permissive free software license. See
79+
deps/zlib/LICENSE.

deps/zlib/LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
*/

deps/zlib/README.chromium

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.

deps/zlib/adler32.c

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
}

deps/zlib/compress.c

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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)

deps/zlib/contrib/minizip/Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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

0 commit comments

Comments
 (0)