You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/08/02 09:59:39 UTC
incubator-corinthia git commit: Inflate made,
but localDirectory does not contain same info as global dir
Repository: incubator-corinthia
Updated Branches:
refs/heads/newZipExperiment2 9e243f2cd -> ab5f29b1d
Inflate made, but localDirectory does not contain same info as global dir
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/ab5f29b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/ab5f29b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/ab5f29b1
Branch: refs/heads/newZipExperiment2
Commit: ab5f29b1df33773f3774f20e3f63fb82d40737db
Parents: 9e243f2
Author: jani <ja...@apache.org>
Authored: Sun Aug 2 09:59:21 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Sun Aug 2 09:59:21 2015 +0200
----------------------------------------------------------------------
DocFormats/platform/src/Wrapper_zip.c | 101 +++++++++++---------------
DocFormats/platform/tests/WrapperTests.c | 2 +-
2 files changed, 44 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ab5f29b1/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index cccc75f..c4cc2e3 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -208,6 +208,8 @@ DFextZipHandleP DFextZipOpen(const char *zipFilename) {
unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zipEntry) {
unsigned char *fileBuf = xmalloc(zipEntry->uncompressedSize);
+ z_stream strm;
+
// Position in front of file
if (fseek(zipHandle->zipFile, zipEntry->offset, SEEK_SET)) {
@@ -216,75 +218,58 @@ unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zip
}
// interesting a zip file that is uncompressed, have to handle that
- if (zipEntry->compressionMethod == 0
- && (fread(fileBuf, 1, zipEntry->uncompressedSize, zipHandle->zipFile) < (unsigned long)zipEntry->uncompressedSize
- || ferror(zipHandle->zipFile))) {
+ if (zipEntry->compressionMethod == 0) {
+ if (fread(fileBuf, 1, zipEntry->uncompressedSize, zipHandle->zipFile) < (unsigned long)zipEntry->uncompressedSize
+ || ferror(zipHandle->zipFile)) {
+ free(fileBuf);
+ fileBuf = NULL;
+ }
+ return fileBuf;
+ }
+
+ // we only handle the zlib method
+ if (zipEntry->compressionMethod != 8) {
free(fileBuf);
return NULL;
}
-#if 0
- unsigned char *bytes = (unsigned char *)buffer; // cast
- long compressedLeft, uncompressedLeft;
- z_stream strm;
- int ret;
-
- else if (header->compressionMethod == 8) { // Deflate - using zlib
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
-
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
-
- // Use inflateInit2 with negative window bits to indicate raw data
- if ((ret = inflateInit2(&strm, -MAX_WBITS)) != Z_OK)
- return ret; // Zlib errors are negative
-
- // Inflate compressed data
- for (compressedLeft = header->compressedSize,
- uncompressedLeft = header->uncompressedSize;
- compressedLeft && uncompressedLeft && ret != Z_STREAM_END;
- compressedLeft -= strm.avail_in) {
- // Read next chunk
- strm.avail_in = fread(jzBuffer, 1,
- (sizeof(jzBuffer) < compressedLeft) ?
- sizeof(jzBuffer) : compressedLeft, zip);
-
- if (strm.avail_in == 0 || ferror(zip)) {
- inflateEnd(&strm);
- return Z_ERRNO;
- }
- strm.next_in = jzBuffer;
- strm.avail_out = uncompressedLeft;
- strm.next_out = bytes;
+ //***** Handle zlib inflate *****
- compressedLeft -= strm.avail_in; // inflate will change avail_in
- ret = inflate(&strm, Z_NO_FLUSH);
+ strm.zalloc = Z_NULL;
+ strm.zfree = strm.opaque = strm.next_in = Z_NULL;
+ strm.avail_in = 0;
- if (ret == Z_STREAM_ERROR) return ret; // shouldn't happen
-
- switch (ret) {
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
- case Z_DATA_ERROR: case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
- return ret;
- }
-
- bytes += uncompressedLeft - strm.avail_out; // bytes uncompressed
- uncompressedLeft = strm.avail_out;
- }
+ // Use inflateInit2 with negative window bits to indicate raw data
+ if (inflateInit2(&strm, -MAX_WBITS) != Z_OK) {
+ free(fileBuf);
+ return NULL;
+ }
- inflateEnd(&strm);
+ // Read compressed data
+ unsigned char *comprBuf = xmalloc(zipEntry->compressedSize);
+ if (fread(comprBuf, 1, zipEntry->compressedSize, zipHandle->zipFile) < (unsigned long)zipEntry->compressedSize
+ || ferror(zipHandle->zipFile)) {
+ free(fileBuf);
+ free(comprBuf);
+ return NULL;
}
- else {
- return Z_ERRNO;
+
+ // and inflate data
+ strm.avail_in = zipEntry->compressedSize;
+ strm.next_in = comprBuf;
+ strm.avail_out = zipEntry->uncompressedSize;
+ strm.next_out = fileBuf;
+ if (inflate(&strm, Z_NO_FLUSH) == Z_STREAM_ERROR) {
+ free(fileBuf);
+ free(comprBuf);
+ return NULL;
}
-#endif
- return NULL;
+
+ free(comprBuf);
+ inflateEnd(&strm);
+ return fileBuf;
}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/ab5f29b1/DocFormats/platform/tests/WrapperTests.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/tests/WrapperTests.c b/DocFormats/platform/tests/WrapperTests.c
index 213e0b9..0af1599 100644
--- a/DocFormats/platform/tests/WrapperTests.c
+++ b/DocFormats/platform/tests/WrapperTests.c
@@ -34,7 +34,7 @@ static void test_DFextZipOpen(void)
log = fopen("docx_log.txt", "w");
for (i = 0; i < zip->zipFileCount; i++) {
fileBuf = DFextZipReadFile(zip, &zip->zipFileEntries[i]);
- fprintf(log, "id(%d) name(%s)\n", i, zip->zipFileEntries[i].fileName);
+ fprintf(log, "id(%d) method(%d) name(%s)\n", i, zip->zipFileEntries[i].compressionMethod, zip->zipFileEntries[i].fileName);
if (fileBuf) {
sprintf(tmpName, "odt_%d.xxx", i);
dmp = fopen(tmpName, "wb");