Skip to content

Commit

Permalink
fix 64 bit zip support
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Bright committed Jan 11, 2011
1 parent 0062f71 commit b427a20
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
27 changes: 14 additions & 13 deletions etc/c/zlib.d
Expand Up @@ -79,11 +79,11 @@ struct z_stream
{
ubyte *next_in; /* next input byte */
uint avail_in; /* number of bytes available at next_in */
uint total_in; /* total nb of input bytes read so far */
size_t total_in; /* total nb of input bytes read so far */

ubyte *next_out; /* next output byte should be put there */
uint avail_out; /* remaining free space at next_out */
uint total_out; /* total nb of bytes output so far */
size_t total_out; /* total nb of bytes output so far */

char *msg; /* last error message, NULL if no error */
void* state; /* not visible by applications */
Expand All @@ -93,8 +93,8 @@ struct z_stream
void* opaque; /* private data object passed to zalloc and zfree */

int data_type; /* best guess about the data type: binary or text */
uint adler; /* adler32 value of the uncompressed data */
uint reserved; /* reserved for future use */
size_t adler; /* adler32 value of the uncompressed data */
size_t reserved; /* reserved for future use */
}

alias z_stream* z_streamp;
Expand Down Expand Up @@ -163,7 +163,8 @@ enum
Z_SYNC_FLUSH = 2,
Z_FULL_FLUSH = 3,
Z_FINISH = 4,
Z_BLOCK = 5
Z_BLOCK = 5,
Z_TREES = 6,
}
/* Allowed flush values; see deflate() and inflate() below for details */

Expand Down Expand Up @@ -706,7 +707,7 @@ int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
*/

int deflateBound(z_streamp strm, uint sourceLen);
int deflateBound(z_streamp strm, size_t sourceLen);
/*
deflateBound() returns an upper bound on the compressed size after
deflation of sourceLen bytes. It must be called after deflateInit()
Expand Down Expand Up @@ -1013,9 +1014,9 @@ uint zlibCompileFlags();
*/

int compress(ubyte* dest,
uint* destLen,
size_t* destLen,
ubyte* source,
uint sourceLen);
size_t sourceLen);
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
Expand All @@ -1030,9 +1031,9 @@ int compress(ubyte* dest,
*/

int compress2(ubyte* dest,
uint* destLen,
size_t* destLen,
ubyte* source,
uint sourceLen,
size_t sourceLen,
int level);
/*
Compresses the source buffer into the destination buffer. The level
Expand All @@ -1047,17 +1048,17 @@ int compress2(ubyte* dest,
Z_STREAM_ERROR if the level parameter is invalid.
*/

uint compressBound(uint sourceLen);
size_t compressBound(size_t sourceLen);
/*
compressBound() returns an upper bound on the compressed size after
compress() or compress2() on sourceLen bytes. It would be used before
a compress() or compress2() call to allocate the destination buffer.
*/

int uncompress(ubyte* dest,
uint* destLen,
size_t* destLen,
ubyte* source,
uint sourceLen);
size_t sourceLen);
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
Expand Down
40 changes: 14 additions & 26 deletions std/zlib.d
Expand Up @@ -114,13 +114,9 @@ in
}
body
{
int err;
ubyte[] destbuf;
uint destlen;

destlen = cast(uint)(srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12);
destbuf = new ubyte[destlen];
err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *)srcbuf, cast(uint)srcbuf.length, level);
auto destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12;
auto destbuf = new ubyte[destlen];
auto err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *)srcbuf.ptr, srcbuf.length, level);
if (err)
{ delete destbuf;
throw new ZlibException(err);
Expand Down Expand Up @@ -149,25 +145,22 @@ void[] compress(void[] buf)

void[] uncompress(void[] srcbuf, size_t destlen = 0u, int winbits = 15)
{
int err;
ubyte[] destbuf;

if (!destlen)
destlen = srcbuf.length * 2 + 1;

while (1)
{
etc.c.zlib.z_stream zs;

destbuf = new ubyte[destlen];
auto destbuf = new ubyte[destlen];

zs.next_in = cast(ubyte*) srcbuf;
zs.avail_in = cast(typeof(zs.avail_in))srcbuf.length;

zs.next_out = destbuf.ptr;
zs.avail_out = cast(typeof(zs.avail_in))destlen;

err = etc.c.zlib.inflateInit2(&zs, winbits);
auto err = etc.c.zlib.inflateInit2(&zs, winbits);
if (err)
{ delete destbuf;
throw new ZlibException(err);
Expand Down Expand Up @@ -286,21 +279,19 @@ class Compress
* returned from successive calls to this should be concatenated together.
*/
void[] compress(void[] buf)
{ int err;
ubyte[] destbuf;

{
if (buf.length == 0)
return null;

if (!inited)
{
err = deflateInit(&zs, level);
auto err = deflateInit(&zs, level);
if (err)
error(err);
inited = 1;
}

destbuf = new ubyte[zs.avail_in + buf.length];
auto destbuf = new ubyte[zs.avail_in + buf.length];
zs.next_out = destbuf.ptr;
zs.avail_out = cast(typeof(zs.avail_out))destbuf.length;

Expand All @@ -310,7 +301,7 @@ class Compress
zs.next_in = cast(ubyte*) buf.ptr;
zs.avail_in = cast(typeof(zs.avail_in))buf.length;

err = deflate(&zs, Z_NO_FLUSH);
auto err = deflate(&zs, Z_NO_FLUSH);
if (err != Z_STREAM_END && err != Z_OK)
{ delete destbuf;
error(err);
Expand Down Expand Up @@ -449,23 +440,21 @@ class UnCompress
assert(!done);
}
body
{ int err;
ubyte[] destbuf;

{
if (buf.length == 0)
return null;

if (!inited)
{
err = inflateInit(&zs);
auto err = inflateInit(&zs);
if (err)
error(err);
inited = 1;
}

if (!destbufsize)
destbufsize = buf.length * 2;
destbuf = new ubyte[zs.avail_in * 2 + destbufsize];
auto destbuf = new ubyte[zs.avail_in * 2 + destbufsize];
zs.next_out = destbuf.ptr;
zs.avail_out = cast(typeof(zs.avail_out))destbuf.length;

Expand All @@ -475,7 +464,7 @@ class UnCompress
zs.next_in = cast(ubyte*) buf;
zs.avail_in = cast(typeof(zs.avail_in))buf.length;

err = inflate(&zs, Z_NO_FLUSH);
auto err = inflate(&zs, Z_NO_FLUSH);
if (err != Z_STREAM_END && err != Z_OK)
{ delete destbuf;
error(err);
Expand All @@ -502,7 +491,6 @@ class UnCompress
{
ubyte[] extra;
ubyte[] destbuf;
int err;

done = 1;
if (!inited)
Expand All @@ -513,7 +501,7 @@ class UnCompress
zs.next_out = destbuf.ptr;
zs.avail_out = cast(typeof(zs.avail_out))destbuf.length;

err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH);
auto err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH);
if (err == Z_OK && zs.avail_out == 0)
{
extra ~= destbuf;
Expand Down

0 comments on commit b427a20

Please sign in to comment.