Version 1.5.0
Big Refactor
This commit is contained in:
parent
3b2a0f4de8
commit
d2f7796b79
49 changed files with 5306 additions and 3590 deletions
|
@ -1,7 +1,7 @@
|
|||
/* unzip.c -- IO for uncompress .zip files using zlib
|
||||
Version 1.01h, December 28th, 2009
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2009 Gilles Vollant
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
|
||||
Read unzip.h for more info
|
||||
*/
|
||||
|
@ -103,9 +103,6 @@ typedef struct
|
|||
{
|
||||
char *read_buffer; /* internal buffer for compressed data */
|
||||
z_stream stream; /* zLib stream structure for inflate */
|
||||
#ifdef HAVE_BZIP2
|
||||
bz_stream bstream; /* bzLib stream structure for bziped */
|
||||
#endif
|
||||
|
||||
uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
|
||||
uLong stream_initialised; /* flag set if stream structure is initialised*/
|
||||
|
@ -207,7 +204,7 @@ local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
|
|||
uLong *pX;
|
||||
{
|
||||
uLong x ;
|
||||
int i = 0;
|
||||
int i;
|
||||
int err;
|
||||
|
||||
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
|
@ -235,7 +232,7 @@ local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
|
|||
uLong *pX;
|
||||
{
|
||||
uLong x ;
|
||||
int i = 0;
|
||||
int i;
|
||||
int err;
|
||||
|
||||
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
|
||||
|
@ -494,11 +491,8 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
|
|||
|
||||
|
||||
s=(unz_s*)ALLOC(sizeof(unz_s));
|
||||
if (s!=NULL)
|
||||
{
|
||||
*s=us;
|
||||
unzGoToFirstFile((unzFile)s);
|
||||
}
|
||||
*s=us;
|
||||
unzGoToFirstFile((unzFile)s);
|
||||
return (unzFile)s;
|
||||
}
|
||||
|
||||
|
@ -614,12 +608,10 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
|
|||
|
||||
/* we check the magic */
|
||||
if (err==UNZ_OK)
|
||||
{
|
||||
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
|
||||
err=UNZ_ERRNO;
|
||||
else if (uMagic!=0x02014b50)
|
||||
err=UNZ_BADZIPFILE;
|
||||
}
|
||||
|
||||
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
|
||||
err=UNZ_ERRNO;
|
||||
|
@ -696,13 +688,10 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
|
|||
uSizeRead = extraFieldBufferSize;
|
||||
|
||||
if (lSeek!=0)
|
||||
{
|
||||
if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
|
||||
lSeek=0;
|
||||
else
|
||||
err=UNZ_ERRNO;
|
||||
}
|
||||
|
||||
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
|
||||
if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead)
|
||||
err=UNZ_ERRNO;
|
||||
|
@ -724,13 +713,10 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
|
|||
uSizeRead = commentBufferSize;
|
||||
|
||||
if (lSeek!=0)
|
||||
{
|
||||
if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
|
||||
lSeek=0;
|
||||
else
|
||||
err=UNZ_ERRNO;
|
||||
}
|
||||
|
||||
if ((file_info.size_file_comment>0) && (commentBufferSize>0))
|
||||
if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
|
||||
err=UNZ_ERRNO;
|
||||
|
@ -991,12 +977,10 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
|
|||
|
||||
|
||||
if (err==UNZ_OK)
|
||||
{
|
||||
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
|
||||
err=UNZ_ERRNO;
|
||||
else if (uMagic!=0x04034b50)
|
||||
err=UNZ_BADZIPFILE;
|
||||
}
|
||||
|
||||
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
|
||||
err=UNZ_ERRNO;
|
||||
|
@ -1013,9 +997,6 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
|
|||
err=UNZ_BADZIPFILE;
|
||||
|
||||
if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
|
||||
/* #ifdef HAVE_BZIP2 */
|
||||
(s->cur_file_info.compression_method!=Z_BZIP2ED) &&
|
||||
/* #endif */
|
||||
(s->cur_file_info.compression_method!=Z_DEFLATED))
|
||||
err=UNZ_BADZIPFILE;
|
||||
|
||||
|
@ -1130,9 +1111,6 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
|
|||
}
|
||||
|
||||
if ((s->cur_file_info.compression_method!=0) &&
|
||||
/* #ifdef HAVE_BZIP2 */
|
||||
(s->cur_file_info.compression_method!=Z_BZIP2ED) &&
|
||||
/* #endif */
|
||||
(s->cur_file_info.compression_method!=Z_DEFLATED))
|
||||
err=UNZ_BADZIPFILE;
|
||||
|
||||
|
@ -1146,34 +1124,6 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
|
|||
|
||||
pfile_in_zip_read_info->stream.total_out = 0;
|
||||
|
||||
if ((s->cur_file_info.compression_method==Z_BZIP2ED) &&
|
||||
(!raw))
|
||||
{
|
||||
#ifdef HAVE_BZIP2
|
||||
pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
|
||||
pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
|
||||
pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
|
||||
pfile_in_zip_read_info->bstream.state = (voidpf)0;
|
||||
|
||||
pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
|
||||
pfile_in_zip_read_info->stream.zfree = (free_func)0;
|
||||
pfile_in_zip_read_info->stream.opaque = (voidpf)0;
|
||||
pfile_in_zip_read_info->stream.next_in = (voidpf)0;
|
||||
pfile_in_zip_read_info->stream.avail_in = 0;
|
||||
|
||||
err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
|
||||
if (err == Z_OK)
|
||||
pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
|
||||
else
|
||||
{
|
||||
TRYFREE(pfile_in_zip_read_info);
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
pfile_in_zip_read_info->raw=1;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
|
||||
(!raw))
|
||||
{
|
||||
|
@ -1185,7 +1135,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
|
|||
|
||||
err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
|
||||
if (err == Z_OK)
|
||||
pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
|
||||
pfile_in_zip_read_info->stream_initialised=1;
|
||||
else
|
||||
{
|
||||
TRYFREE(pfile_in_zip_read_info);
|
||||
|
@ -1213,8 +1163,6 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
|
|||
|
||||
s->pfile_in_zip_read = pfile_in_zip_read_info;
|
||||
|
||||
s->encrypted = 0;
|
||||
|
||||
# ifndef NOUNCRYPT
|
||||
if (password != NULL)
|
||||
{
|
||||
|
@ -1386,53 +1334,6 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
|
|||
iRead += uDoCopy;
|
||||
}
|
||||
else
|
||||
if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
|
||||
{
|
||||
#ifdef HAVE_BZIP2
|
||||
uLong uTotalOutBefore,uTotalOutAfter;
|
||||
const Bytef *bufBefore;
|
||||
uLong uOutThis;
|
||||
|
||||
pfile_in_zip_read_info->bstream.next_in = pfile_in_zip_read_info->stream.next_in;
|
||||
pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
|
||||
pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
|
||||
pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
|
||||
pfile_in_zip_read_info->bstream.next_out = pfile_in_zip_read_info->stream.next_out;
|
||||
pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
|
||||
pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
|
||||
pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
|
||||
|
||||
uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
|
||||
bufBefore = pfile_in_zip_read_info->bstream.next_out;
|
||||
|
||||
err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
|
||||
|
||||
uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
|
||||
uOutThis = uTotalOutAfter-uTotalOutBefore;
|
||||
|
||||
pfile_in_zip_read_info->crc32 =
|
||||
crc32(pfile_in_zip_read_info->crc32,bufBefore,
|
||||
(uInt)(uOutThis));
|
||||
|
||||
pfile_in_zip_read_info->rest_read_uncompressed -=
|
||||
uOutThis;
|
||||
|
||||
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
|
||||
|
||||
pfile_in_zip_read_info->stream.next_in = pfile_in_zip_read_info->bstream.next_in;
|
||||
pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
|
||||
pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
|
||||
pfile_in_zip_read_info->stream.next_out = pfile_in_zip_read_info->bstream.next_out;
|
||||
pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
|
||||
pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
|
||||
|
||||
if (err==BZ_STREAM_END)
|
||||
return (iRead==0) ? UNZ_EOF : iRead;
|
||||
if (err!=BZ_OK)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
uLong uTotalOutBefore,uTotalOutAfter;
|
||||
const Bytef *bufBefore;
|
||||
|
@ -1611,12 +1512,8 @@ extern int ZEXPORT unzCloseCurrentFile (file)
|
|||
|
||||
TRYFREE(pfile_in_zip_read_info->read_buffer);
|
||||
pfile_in_zip_read_info->read_buffer = NULL;
|
||||
if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
|
||||
if (pfile_in_zip_read_info->stream_initialised)
|
||||
inflateEnd(&pfile_in_zip_read_info->stream);
|
||||
#ifdef HAVE_BZIP2
|
||||
else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
|
||||
BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
|
||||
#endif
|
||||
|
||||
pfile_in_zip_read_info->stream_initialised = 0;
|
||||
TRYFREE(pfile_in_zip_read_info);
|
||||
|
@ -1637,6 +1534,7 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
|
|||
char *szComment;
|
||||
uLong uSizeBuf;
|
||||
{
|
||||
int err=UNZ_OK;
|
||||
unz_s* s;
|
||||
uLong uReadThis ;
|
||||
if (file==NULL)
|
||||
|
@ -1669,7 +1567,7 @@ extern uLong ZEXPORT unzGetOffset (file)
|
|||
unz_s* s;
|
||||
|
||||
if (file==NULL)
|
||||
return 0;
|
||||
return UNZ_PARAMERROR;
|
||||
s=(unz_s*)file;
|
||||
if (!s->current_file_ok)
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue