corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject incubator-corinthia git commit: Search for endRecord works in 32/64 bit
Date Fri, 31 Jul 2015 19:10:02 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/newZipExperiment 91a88b6d0 -> d0ceb0e00


Search for endRecord works in 32/64 bit


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/d0ceb0e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/d0ceb0e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/d0ceb0e0

Branch: refs/heads/newZipExperiment
Commit: d0ceb0e009f58527418f00dccf427aa4d0bd8d30
Parents: 91a88b6
Author: jani <jani@apache.org>
Authored: Fri Jul 31 21:09:16 2015 +0200
Committer: jani <jani@apache.org>
Committed: Fri Jul 31 21:09:16 2015 +0200

----------------------------------------------------------------------
 DocFormats/headers/DFPlatform.h       |  3 ++
 DocFormats/platform/src/Wrapper_zip.c | 51 ++++++++++++++----------------
 2 files changed, 26 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/d0ceb0e0/DocFormats/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h
index cd947b1..09e3b71 100644
--- a/DocFormats/headers/DFPlatform.h
+++ b/DocFormats/headers/DFPlatform.h
@@ -71,6 +71,9 @@ void DFInitOnce(DFOnce *once, DFOnceFunction fun);
 // Zip functions
 typedef struct {
 	FILE *zipFile;
+	int   zipFileCount;
+	int   zipDirSize;
+	int   zipDirOffset;
 } DFextZipHandle;
 typedef DFextZipHandle * DFextZipHandleP;
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/d0ceb0e0/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index 0066254..8da5664 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -34,13 +34,16 @@ typedef struct {
    	                                     // Followed by .ZIP file comment (variable size)
 } ZipEndRecord;
 #pragma pack()
-#define WORK_BUF_SIZE 65535
-     
+static const uint32_t ZipEndRecord_signature = 0x06054B50;
+
+
 
 static int readEndRecord(FILE *zipFile, DFextZipHandleP zipHandle)
 {
 	unsigned long fileSize, readBytes, i;
-	unsigned char workBuf[WORK_BUF_SIZE];
+	unsigned char workBuf[1024];
+	ZipEndRecord *rec;
+
 
 	// find end of file, and calculate size
 	if (fseek(zipFile, 0, SEEK_END))
@@ -49,12 +52,27 @@ static int readEndRecord(FILE *zipFile, DFextZipHandleP zipHandle)
 	if ( fileSize <= sizeof(ZipEndRecord) )
 		return -1;
 
-	// Read WORK_BUF_SIZE of filesize from end of file to locate EndRecord
+	// Read size of workBuf of filesize from end of file to locate EndRecord
 	readBytes = (fileSize < sizeof(workBuf)) ? fileSize : sizeof(workBuf);
 	if (fseek(zipFile, fileSize - readBytes, SEEK_SET))
 		return -1;
 	if (fread(workBuf, 1, readBytes, zipFile) < readBytes)
 		return -1;
+
+	// search for EndRecord signature
+	for (i = readBytes - sizeof(ZipEndRecord); i >= 0; i--) {
+		rec = (ZipEndRecord *)(workBuf + i);
+		if (rec->signature == ZipEndRecord_signature)
+			break;
+	}
+	if (i < 0)
+		return -1;
+
+	// update zipHandle
+	zipHandle->zipFileCount = rec->numEntries;
+	zipHandle->zipDirSize   = rec->centralDirectorySize;
+	zipHandle->zipDirOffset = rec->centralDirectoryOffset;
+	return 0;
 }
 
 
@@ -65,35 +83,12 @@ DFextZipHandleP DFextZipOpen(const char *zipFilename) {
 	// open zip file for reading
 	zipHandle->zipFile = fopen(zipFilename, "rb");
 	if (zipHandle->zipFile &&
-		readEndRecord(zipHandle->zipFile, zipHandle)) {
+		!readEndRecord(zipHandle->zipFile, zipHandle)) {
 		return zipHandle;
 	}
 
 
 
-#if 0
-		// Naively assume signature can only be found in one place...
-		for (i = readBytes - sizeof(JZEndRecord); i >= 0; i--) {
-			er = (JZEndRecord *)(jzBuffer + i);
-			if (er->signature == 0x06054B50)
-				break;
-		}
-
-		if (i < 0) {
-			fprintf(stderr, "End record signature not found in zip!");
-			return Z_ERRNO;
-		}
-
-		memcpy(endRecord, er, sizeof(JZEndRecord));
-
-		if (endRecord->diskNumber || endRecord->centralDirectoryDiskNumber ||
-			endRecord->numEntries != endRecord->numEntriesThisDisk) {
-			fprintf(stderr, "Multifile zips not supported!");
-			return Z_ERRNO;
-		}
-
-		return Z_OK;
-#endif
 
 
 	// release memory


Mime
View raw message