github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/make/tools/ziptime/ZipFile.h (about)

     1  /*
     2   * Copyright (C) 2006 The Android Open Source Project
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  //
    18  // Class to rewrite zip file headers to remove dynamic timestamps.
    19  //
    20  #ifndef __LIBS_ZIPFILE_H
    21  #define __LIBS_ZIPFILE_H
    22  
    23  #include <stdio.h>
    24  
    25  #include "ZipEntry.h"
    26  
    27  namespace android {
    28  
    29  /*
    30   * Manipulate a Zip archive.
    31   */
    32  class ZipFile {
    33  public:
    34      ZipFile(void) : mZipFp(NULL) {}
    35      ~ZipFile(void) {
    36          if (mZipFp != NULL)
    37              fclose(mZipFp);
    38      }
    39  
    40      /*
    41       * Rewrite an archive's headers to remove dynamic timestamps.
    42       */
    43      status_t rewrite(const char* zipFileName);
    44  
    45  private:
    46      /* these are private and not defined */
    47      ZipFile(const ZipFile& src);
    48      ZipFile& operator=(const ZipFile& src);
    49  
    50      class EndOfCentralDir {
    51      public:
    52          EndOfCentralDir(void) : mTotalNumEntries(0), mCentralDirOffset(0) {}
    53  
    54          status_t readBuf(const uint8_t* buf, int len);
    55  
    56          uint16_t mTotalNumEntries;
    57          uint32_t mCentralDirOffset;      // offset from first disk
    58  
    59          enum {
    60              kSignature      = 0x06054b50,
    61              kEOCDLen        = 22,       // EndOfCentralDir len, excl. comment
    62  
    63              kMaxCommentLen  = 65535,    // longest possible in ushort
    64              kMaxEOCDSearch  = kMaxCommentLen + EndOfCentralDir::kEOCDLen,
    65  
    66          };
    67      };
    68  
    69      /* read all entries in the central dir */
    70      status_t rewriteCentralDir(void);
    71  
    72      /*
    73       * We use stdio FILE*, which gives us buffering but makes dealing
    74       * with files >2GB awkward.  Until we support Zip64, we're fine.
    75       */
    76      FILE*           mZipFp;             // Zip file pointer
    77  
    78      /* one of these per file */
    79      EndOfCentralDir mEOCD;
    80  };
    81  
    82  }; // namespace android
    83  
    84  #endif // __LIBS_ZIPFILE_H