corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/3] incubator-corinthia git commit: ready for test cases
Date Tue, 04 Aug 2015 11:44:38 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/newZipExperiment2 f0ebf4c34 -> 6451ac0fe


ready for test cases


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

Branch: refs/heads/newZipExperiment2
Commit: d5c2bc0fce312cbbe634702e93a144da7edbd918
Parents: f0ebf4c
Author: jani <jani@apache.org>
Authored: Tue Aug 4 09:58:55 2015 +0200
Committer: jani <jani@apache.org>
Committed: Tue Aug 4 09:58:55 2015 +0200

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


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/d5c2bc0f/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index dfec5ce..adc9b47 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -192,6 +192,46 @@ static void releaseMemory(DFextZipHandleP zipHandle) {
 
 
 
+static void writeGlobalDirAndEndRecord(DFextZipHandleP zipHandle) {
+	static const char comment[] = "generated by Corinthia";
+	ZipDirectoryRecord dirRecord;
+	ZipEndRecord	   endRecord;
+	int                i;
+
+
+	// Prepare constant part of records
+	endRecord.signature              = ZipEndRecord_signature;
+	endRecord.diskNumber             = endRecord.centralDirectoryDiskNumber = endRecord.numEntriesThisDisk
= 0;
+	endRecord.numEntries             = zipHandle->zipFileCount;
+	endRecord.centralDirectoryOffset = ftell(zipHandle->zipFile);
+	endRecord.zipCommentLength       = strlen(comment);
+
+	dirRecord.signature              = ZipDirectoryRecord_signature;
+	dirRecord.versionMadeBy          = ZLIB_VERNUM;
+	dirRecord.versionNeededToExtract = dirRecord.generalPurposeBitFlag = dirRecord.lastModFileTime
       =
+	dirRecord.lastModFileDate        = dirRecord.crc32                 = dirRecord.extraFieldLength
      =
+	dirRecord.fileCommentLength      = dirRecord.diskNumberStart       = dirRecord.internalFileAttributes
=
+	dirRecord.externalFileAttributes = 0;
+
+	// loop through all directory entries, write to disk while collecting size
+	endRecord.centralDirectorySize = 0;
+	for (i = 0; i < zipHandle->zipFileCount; i++) {
+		dirRecord.compressionMethod           = zipHandle->zipFileEntries[i].compressionMethod;
+		dirRecord.compressedSize              = zipHandle->zipFileEntries[i].compressedSize;
+		dirRecord.uncompressedSize            = zipHandle->zipFileEntries[i].uncompressedSize;
+		dirRecord.fileNameLength              = strlen(zipHandle->zipFileEntries[i].fileName);
+		dirRecord.relativeOffsetOflocalHeader = zipHandle->zipFileEntries[i].offset;
+		endRecord.centralDirectorySize       += sizeof(ZipDirectoryRecord) + dirRecord.fileNameLength;
+		fwrite(&dirRecord, 1, sizeof(ZipDirectoryRecord), zipHandle->zipFile);
+		fwrite(zipHandle->zipFileEntries[i].fileName, 1, dirRecord.fileNameLength, zipHandle->zipFile);
+	}
+
+	// and finally the end record
+	fwrite(&endRecord, 1, sizeof(ZipEndRecord), zipHandle->zipFile);
+}
+
+
+
 DFextZipHandleP DFextZipOpen(const char *zipFilename) {
     DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
 
@@ -349,6 +389,9 @@ DFextZipDirEntryP DFextZipWriteFile(DFextZipHandleP zipHandle, const char
*fileN
 
 int DFextZipClose(DFextZipHandleP zipHandle)
 {
+	if (zipHandle->zipFileCount)
+		writeGlobalDirAndEndRecord(zipHandle);
+
 	fclose(zipHandle->zipFile);
 	releaseMemory(zipHandle);
 	return 0;


Mime
View raw message