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/03 21:59:40 UTC

[4/5] incubator-corinthia git commit: small adjustments after test

small adjustments after test


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

Branch: refs/heads/newZipExperiment2
Commit: 3714231f2948248b322fb4b8df808231834bbad4
Parents: c8c35ec
Author: jani <ja...@apache.org>
Authored: Mon Aug 3 20:43:52 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Mon Aug 3 20:43:52 2015 +0200

----------------------------------------------------------------------
 DocFormats/platform/src/Wrapper_zip.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/3714231f/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index 5120787..9cc4bcd 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -75,6 +75,7 @@ typedef struct {
 } ZipFileHeader;
 #pragma pack()
 static const uint32_t ZipFileHeader_signature = 0x04034B50;
+static const int FILECOUNT_ALLOC_SIZE = 5;
 
 
 
@@ -176,7 +177,7 @@ static int readDirectory(FILE *zipFile, DFextZipHandleP zipHandle)
 
 static void releaseMemory(DFextZipHandleP zipHandle) {
 	if (zipHandle) {
-		int count = zipHandle->zipCreateMode ? zipHandle->zipCreateMode : zipHandle->zipFileEntries;
+		int count = zipHandle->zipCreateMode ? zipHandle->zipCreateMode : zipHandle->zipFileCount;
 		if (count) {
 			for (int i = 0; i < count; i++) {
 				DFextZipDirEntry *zipDirEntry = zipHandle->zipFileEntries + (i * sizeof(zipDirEntry));
@@ -219,7 +220,7 @@ unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zip
 	}
 
 	// interesting a zip file that is uncompressed, have to handle that
-	if (zipEntry->compressionMethod == 0) {
+	if (zipEntry->compressionMethod != Z_DEFLATED) {
 		if (fread(fileBuf, 1, zipEntry->uncompressedSize, zipHandle->zipFile) < (unsigned long)zipEntry->uncompressedSize
 			|| ferror(zipHandle->zipFile)) {
 			free(fileBuf);
@@ -229,7 +230,7 @@ unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zip
 	}
 
 	// we only handle the zlib method
-	if (zipEntry->compressionMethod != 8) {
+	if (zipEntry->compressionMethod != Z_DEFLATED) {
 		free(fileBuf);
 		return NULL;
 	}
@@ -285,16 +286,31 @@ DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 	}
 
 	// prepare to add files
-	zipHandle->zipFileCount   = 0;
-	zipHandle->zipCreateMode  = 5;
-	zipHandle->zipFileEntries = xmalloc(zipHandle->zipCreateMode * sizeof(DFextZipDirEntry));
-	memset(zipHandle->zipFileEntries, 1, zipHandle->zipCreateMode * sizeof(DFextZipDirEntry));
+	zipHandle->zipFileCount = 0;
 	return zipHandle;
 }
 
 
 
 DFextZipDirEntryP DFextZipWriteFile(DFextZipHandleP zipHandle, const char *fileName, const void *buf, const int len) {
+	// do we have space for one more entry ?
+	if (zipHandle->zipFileCount >= zipHandle->zipCreateMode) {
+		zipHandle->zipCreateMode += FILECOUNT_ALLOC_SIZE;
+		zipHandle->zipFileEntries = xrealloc(zipHandle->zipFileEntries, zipHandle->zipCreateMode * sizeof(DFextZipDirEntryP));
+	}
+
+	// prepare local and global file entry
+	DFextZipDirEntryP entryPtr = &zipHandle->zipFileEntries[zipHandle->zipFileCount++];
+	entryPtr->offset           = ftell(zipHandle->zipFile);
+	entryPtr->uncompressedSize = len;
+	entryPtr->fileName         = xmalloc(strlen(fileName) + 1);
+	strcpy(entryPtr->fileName, fileName);
+
+
+//	entryPtr->compressedSize
+
+
+
 	return NULL;
 }