corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [5/5] incubator-corinthia git commit: zipWrite done (untested) missing global dir and endrecord
Date Mon, 03 Aug 2015 19:59:41 GMT
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 <jani@apache.org>
Authored: Mon Aug 3 21:59:17 2015 +0200
Committer: jani <jani@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;
 }
 
 


Mime
View raw message