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/02/23 12:39:17 UTC
[14/31] incubator-corinthia git commit: Added new zip files (back to
square one)
Added new zip files (back to square one)
Prepared files for new zip interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/9989d9b0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/9989d9b0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/9989d9b0
Branch: refs/heads/experimentzip
Commit: 9989d9b04df394f2bd82ea4f7432da161aab3281
Parents: c06aaa5
Author: jani <ja...@apache.org>
Authored: Fri Feb 13 10:27:29 2015 +0100
Committer: jani <ja...@apache.org>
Committed: Fri Feb 13 10:27:29 2015 +0100
----------------------------------------------------------------------
DocFormats/platform/CMakeLists.txt | 1 +
DocFormats/platform/src/ZipWrapper.c | 144 ++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/9989d9b0/DocFormats/platform/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/DocFormats/platform/CMakeLists.txt b/DocFormats/platform/CMakeLists.txt
index f3ba68b..cd7c28f 100644
--- a/DocFormats/platform/CMakeLists.txt
+++ b/DocFormats/platform/CMakeLists.txt
@@ -93,6 +93,7 @@ set(GroupSrc
src/Linux.c
src/Unix.c
src/Win32.c
+ src/ZipWrapper.c
src/Wrapper.c)
set(GroupTests
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/9989d9b0/DocFormats/platform/src/ZipWrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/ZipWrapper.c b/DocFormats/platform/src/ZipWrapper.c
new file mode 100644
index 0000000..827a7d1
--- /dev/null
+++ b/DocFormats/platform/src/ZipWrapper.c
@@ -0,0 +1,144 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#include <string.h>
+#include <stdlib.h>
+#include "DFPlatform.h"
+#include "unzip.h"
+#include "zip.h"
+
+
+DFextZipHandleP DFextZipOpen(const char *zipFilename, int doUnzip) {
+ DFextZipHandleP zipHandle = malloc(sizeof(DFextZipHandle));
+
+ // no more memory
+ if (!zipHandle)
+ return NULL;
+
+ // Open file
+ zipHandle->zipFirst = 1;
+ zipHandle->zipFlag = doUnzip;
+ if (doUnzip)
+ zipHandle->handle = unzOpen(zipFilename);
+ else
+ zipHandle->handle = zipOpen(zipFilename, APPEND_STATUS_CREATE);
+
+ if (zipHandle->handle)
+ return zipHandle;
+
+ free(zipHandle);
+ return NULL;
+}
+
+
+
+int DFextZipClose(DFextZipHandleP zipHandle)
+{
+ int rc = 0;
+
+ if (zipHandle->handle) {
+ if (zipHandle->zipFlag)
+ rc = (unzClose(zipHandle->handle) == UNZ_OK);
+ else
+ rc = (zipClose(zipHandle->handle, NULL) == ZIP_OK);
+ zipHandle->handle = NULL;
+ }
+
+ free(zipHandle);
+ return rc ? 1 : -1;
+}
+
+
+
+int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName)
+{
+ int rc;
+
+
+ if (zipHandle->zipFlag) {
+ unz_file_info info;
+
+ // handling of first file and all others are different
+ if (zipHandle->zipFirst) {
+ rc = unzGoToFirstFile(zipHandle->handle);
+ zipHandle->zipFirst = 0;
+ }
+ else
+ rc = unzGoToNextFile(zipHandle->handle);
+
+ // Error or past last file
+ if (rc != UNZ_OK)
+ return (rc == UNZ_END_OF_LIST_OF_FILE) ? 0 : -1;
+
+ // get file name
+ if (unzGetCurrentFileInfo(zipHandle->handle, &info, entryName, maxName, NULL, 0, NULL, 0) != UNZ_OK)
+ return -1;
+
+ // check for prefix "/" and if present skip file
+ if (entryName[strlen(entryName) - 1] == '/')
+ return DFextZipOpenNextFile(zipHandle, entryName, maxName);
+
+ // open Regular file
+ if (unzOpenCurrentFile(zipHandle->handle) != UNZ_OK)
+ return -1;
+ }
+ else {
+ return -1; // Zip file is open in write-only mode
+ }
+
+ // ready to read
+ return 1;
+}
+
+int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
+{
+ 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;
+ }
+
+ return 1;
+}
+
+int DFextZipCloseFile(DFextZipHandleP zipHandle)
+{
+ if (zipHandle->zipFlag)
+ return (unzCloseCurrentFile(zipHandle->handle) != UNZ_OK) ? -1 : 1;
+ else
+ return (zipCloseFileInZip(zipHandle->handle) != UNZ_OK) ? -1 : 1;
+}
+
+
+
+
+int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, void *buf, const int maxLen)
+{
+ return unzReadCurrentFile(zipHandle->handle, buf, maxLen);
+}
+
+
+
+int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len)
+{
+ return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1;
+}