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:37 UTC

[1/5] incubator-corinthia git commit: zipCreate

Repository: incubator-corinthia
Updated Branches:
  refs/heads/newZipExperiment2 b80df2922 -> f0ebf4c34


zipCreate


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

Branch: refs/heads/newZipExperiment2
Commit: 7f0e44fb9575683621afcba881bbcf52eb972d56
Parents: b80df29
Author: jani <ja...@apache.org>
Authored: Sun Aug 2 11:29:09 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Sun Aug 2 11:29:09 2015 +0200

----------------------------------------------------------------------
 DocFormats/platform/src/Wrapper_zip.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/7f0e44fb/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index 272d3be..2ff53fe 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -279,21 +279,12 @@ unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zip
 DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 	DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
 
-#if 0
-	// no more memory
-	if (!zipHandle)
+	// Open file for write
+	if ((zipHandle->zipFile = fopen(zipFilename, "wb")) == NULL) {
+		free(zipHandle);
 		return NULL;
-
-	// Open file
-	zipHandle->zipFirst = 1;
-    zipHandle->handle = zipOpen(zipFilename, APPEND_STATUS_CREATE);
-
-	if (zipHandle->handle)
-		return zipHandle;
-
-	free(zipHandle);
-#endif
-	return NULL;
+	}
+	return zipHandle;
 }
 
 


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

Posted by ja...@apache.org.
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;
 }
 


[3/5] incubator-corinthia git commit: integrate new zipCreate in dfzip.c

Posted by ja...@apache.org.
integrate new zipCreate in dfzip.c


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

Branch: refs/heads/newZipExperiment2
Commit: c8c35ec4ba88ff11f173cf2606d6342232152f8d
Parents: 00878c3
Author: jani <ja...@apache.org>
Authored: Mon Aug 3 20:03:28 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Mon Aug 3 20:03:28 2015 +0200

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFZipFile.c   |  8 +----
 DocFormats/headers/DFPlatform.h       | 12 ++------
 DocFormats/platform/src/Wrapper_zip.c | 47 +++++-------------------------
 3 files changed, 11 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c8c35ec4/DocFormats/core/src/lib/DFZipFile.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFZipFile.c b/DocFormats/core/src/lib/DFZipFile.c
index b3dab37..61dcf1b 100644
--- a/DocFormats/core/src/lib/DFZipFile.c
+++ b/DocFormats/core/src/lib/DFZipFile.c
@@ -68,14 +68,8 @@ int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error)
 
 static int zipAddFile(DFextZipHandleP zipHandle, const char *dest, DFBuffer *content, DFError **error)
 {
-    if (DFextZipAppendNewFile(zipHandle, dest) < 0)
+    if (DFextZipWriteFile(zipHandle, dest, content->data, content->len) < 0)
         return zipError(error,"%s: Cannot create entry in zip file",dest);
-
-    if (DFextZipWriteCurrentFile(zipHandle, content->data, (unsigned int)content->len) < 0)
-        return zipError(error,"%s: Error writing to entry in zip file",dest);
-
-    if (DFextZipCloseFile(zipHandle) <0)
-        return zipError(error,"%s: Error closing entry in zip file",dest);
     return 1;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c8c35ec4/DocFormats/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h
index a6b4e2d..fb5f55f 100644
--- a/DocFormats/headers/DFPlatform.h
+++ b/DocFormats/headers/DFPlatform.h
@@ -89,19 +89,11 @@ typedef DFextZipHandle * DFextZipHandleP;
 DFextZipHandleP DFextZipOpen(const char *zipFilename);
 DFextZipHandleP DFextZipCreate(const char *zipFilename);
 
-unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zipEntry);
-
-
-
+unsigned char     *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zipEntry);
+DFextZipDirEntryP  DFextZipWriteFile(DFextZipHandleP zipHandle, const char *fileName, const void *buf, const int len);
 
 int DFextZipClose(DFextZipHandleP zipHandle);
 
-int DFextZipAppendNewFile(DFextZipHandleP zipHandle,
-                          const char *entryName);
-
-int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle,
-                             const void *buf,
-                             const int len);
 
 
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/c8c35ec4/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index a653019..5120787 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -176,8 +176,9 @@ static int readDirectory(FILE *zipFile, DFextZipHandleP zipHandle)
 
 static void releaseMemory(DFextZipHandleP zipHandle) {
 	if (zipHandle) {
-		if (zipHandle->zipFileEntries) {
-			for (int i = 0; i < zipHandle->zipFileCount; i++) {
+		int count = zipHandle->zipCreateMode ? zipHandle->zipCreateMode : zipHandle->zipFileEntries;
+		if (count) {
+			for (int i = 0; i < count; i++) {
 				DFextZipDirEntry *zipDirEntry = zipHandle->zipFileEntries + (i * sizeof(zipDirEntry));
 				if (zipDirEntry->fileName)
 					free(zipDirEntry->fileName);
@@ -292,48 +293,16 @@ DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 }
 
 
-int DFextZipClose(DFextZipHandleP zipHandle)
-{
-	fclose(zipHandle->zipFile);
-	releaseMemory(zipHandle);
-	return 0;
-}
-
-
 
-int DFextZipCloseFile(DFextZipHandleP zipHandle) {
-	return 0;
-}
-
-int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
-{
-#if 0
-    zip_fileinfo fileinfo;
-    memset(&fileinfo, 0, sizeof(fileinfo));
-
-   if (zipHandle->zipFlag)
-      return -1; // Zip file is open in read-only mode
-
-    if (zipOpenNewFileInZip(zipHandle->handle,
-                            entryName,
-                            &fileinfo,
-                            NULL, 0,
-                            NULL, 0,
-                            NULL,
-                            Z_DEFLATED,
-                            Z_DEFAULT_COMPRESSION) != ZIP_OK) {
-        return -1;
-    }
-#endif
-    return 1;
+DFextZipDirEntryP DFextZipWriteFile(DFextZipHandleP zipHandle, const char *fileName, const void *buf, const int len) {
+	return NULL;
 }
 
 
 
-int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len)
+int DFextZipClose(DFextZipHandleP zipHandle)
 {
-#if 0
-    return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1;
-#endif
+	fclose(zipHandle->zipFile);
+	releaseMemory(zipHandle);
 	return 0;
 }


[5/5] incubator-corinthia git commit: zipWrite done (untested) missing global dir and endrecord

Posted by ja...@apache.org.
zipWrite done (untested) missing global dir and endrecord


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

Branch: refs/heads/newZipExperiment2
Commit: f0ebf4c348bd62b4cc6b37032c3de5b09bdb54fa
Parents: 3714231
Author: jani <ja...@apache.org>
Authored: Mon Aug 3 21:59:17 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Mon Aug 3 21:59:17 2015 +0200

----------------------------------------------------------------------
 DocFormats/platform/src/Wrapper_zip.c | 43 +++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f0ebf4c3/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index 9cc4bcd..dfec5ce 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -293,6 +293,11 @@ DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 
 
 DFextZipDirEntryP DFextZipWriteFile(DFextZipHandleP zipHandle, const char *fileName, const void *buf, const int len) {
+	z_stream       strm;
+	unsigned char *outbuf;
+	ZipFileHeader  header;
+	int            fileNameLength = strlen(fileName);
+
 	// do we have space for one more entry ?
 	if (zipHandle->zipFileCount >= zipHandle->zipCreateMode) {
 		zipHandle->zipCreateMode += FILECOUNT_ALLOC_SIZE;
@@ -303,15 +308,41 @@ DFextZipDirEntryP DFextZipWriteFile(DFextZipHandleP zipHandle, const char *fileN
 	DFextZipDirEntryP entryPtr = &zipHandle->zipFileEntries[zipHandle->zipFileCount++];
 	entryPtr->offset           = ftell(zipHandle->zipFile);
 	entryPtr->uncompressedSize = len;
-	entryPtr->fileName         = xmalloc(strlen(fileName) + 1);
+	entryPtr->fileName         = xmalloc(fileNameLength + 1);
 	strcpy(entryPtr->fileName, fileName);
 
+	// prepare to deflate
+	strm.zalloc = Z_NULL;
+	strm.zfree  = strm.opaque = strm.next_in = Z_NULL;
+	strm.avail_in = 0;
+	if (deflateInit(&strm, Z_DEFLATED) != Z_OK)
+		return NULL;
 
-//	entryPtr->compressedSize
-
-
-
-	return NULL;
+	// deflate buffer
+	strm.avail_in = strm.avail_out = len;
+	strm.next_in  = buf;
+	strm.next_out = outbuf = xmalloc(len);
+	deflate(&strm, Z_FINISH);
+	deflateEnd(&strm);
+	entryPtr->compressedSize = len - strm.avail_out;
+
+	// prepare local header
+	header.versionNeededToExtract = header.generalPurposeBitFlag = header.lastModFileTime =
+	header.lastModFileDate        = header.extraFieldLength      = header.crc32 = 0;
+	header.signature              = ZipFileHeader_signature;
+	header.compressionMethod      = Z_DEFLATED;
+	header.compressedSize         = entryPtr->compressedSize;
+	header.uncompressedSize       = len;
+	header.fileNameLength         = fileNameLength;
+
+	// put data to file
+	fwrite(&header, 1, sizeof(header), zipHandle->zipFile);
+	fwrite(entryPtr->fileName, 1, fileNameLength, zipHandle->zipFile);
+
+	// cleanup
+	free(outbuf);
+
+	return entryPtr;
 }
 
 


[2/5] incubator-corinthia git commit: zipCreate main finished

Posted by ja...@apache.org.
zipCreate main finished


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

Branch: refs/heads/newZipExperiment2
Commit: 00878c339edb8d22fa9b3e46a7b38ba1dc2705e7
Parents: 7f0e44f
Author: jani <ja...@apache.org>
Authored: Mon Aug 3 19:25:05 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Mon Aug 3 19:25:05 2015 +0200

----------------------------------------------------------------------
 DocFormats/headers/DFPlatform.h       |  1 +
 DocFormats/platform/src/Wrapper_zip.c | 12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/00878c33/DocFormats/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h
index e8ed0d7..a6b4e2d 100644
--- a/DocFormats/headers/DFPlatform.h
+++ b/DocFormats/headers/DFPlatform.h
@@ -80,6 +80,7 @@ typedef DFextZipDirEntry * DFextZipDirEntryP;
 typedef struct {
 	void             *zipFile;        // file handle to zip file
 	int               zipFileCount;   // number of entries in array
+	int               zipCreateMode;  // > 0 signals create mode, # is allocation of array
 	DFextZipDirEntry *zipFileEntries; // array with filenames in zip
 } DFextZipHandle;
 typedef DFextZipHandle * DFextZipHandleP;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/00878c33/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index 2ff53fe..a653019 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -194,7 +194,8 @@ DFextZipHandleP DFextZipOpen(const char *zipFilename) {
     DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
 
 	// open zip file for reading
-	zipHandle->zipFile = fopen(zipFilename, "rb");
+	zipHandle->zipCreateMode = 0;
+	zipHandle->zipFile       = fopen(zipFilename, "rb");
 	if (zipHandle->zipFile
 		&& !readDirectory(zipHandle->zipFile, zipHandle))
 		return zipHandle;
@@ -273,9 +274,6 @@ unsigned char *DFextZipReadFile(DFextZipHandleP zipHandle, DFextZipDirEntryP zip
 
 
 
-
-
-
 DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 	DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
 
@@ -284,6 +282,12 @@ DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 		free(zipHandle);
 		return NULL;
 	}
+
+	// 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));
 	return zipHandle;
 }