corinthia-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Fisher <dave2w...@comcast.net>
Subject Re: [3/3] incubator-corinthia git commit: added wrapper for zip.
Date Thu, 12 Feb 2015 20:20:31 GMT
JanI -

A question. Why is there a copyright in this file?

Did this file come from UX Productivity as part of the initial grant or did you write it to
contribute?

Depending on the answer action should be taken to comply with http://www.apache.org/legal/src-headers.html

Regards,
Dave

On Feb 11, 2015, at 10:56 AM, jani@apache.org wrote:

> added wrapper for zip.
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
> Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/768c5aad
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/768c5aad
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/768c5aad
> 
> Branch: refs/heads/experimentzip
> Commit: 768c5aad43a31a2e30c0cda101ffa12cf276fa23
> Parents: 0fbd721
> Author: jani <jani@apache.org>
> Authored: Wed Feb 11 19:55:38 2015 +0100
> Committer: jani <jani@apache.org>
> Committed: Wed Feb 11 19:55:38 2015 +0100
> 
> ----------------------------------------------------------------------
> DocFormats/platform/src/ZipWrapper.c | 146 ++++++++++++++++++++++++++++++
> 1 file changed, 146 insertions(+)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/768c5aad/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..14ed093
> --- /dev/null
> +++ b/DocFormats/platform/src/ZipWrapper.c
> @@ -0,0 +1,146 @@
> +// Copyright 2012-2014 UX Productivity Pty Ltd
> +//
> +// 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;
> +}
> 


Mime
View raw message