2
0

unzipLIB.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // unzipLIB - Arduino unzip library
  3. // based on zlib and contrib/minizip/unzip
  4. // written by Larry Bank
  5. // bitbank@pobox.com
  6. //
  7. // Copyright 2021 BitBank Software, Inc. All Rights Reserved.
  8. // Licensed under the Apache License, Version 2.0 (the "License");
  9. // you may not use this file except in compliance with the License.
  10. // You may obtain a copy of the License at
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //===========================================================================
  18. #include "unzipLIB.h"
  19. int UNZIP::openZIP(uint8_t *pData, int iDataSize)
  20. {
  21. _zip.zHandle = unzOpen(NULL, pData, iDataSize, &_zip, NULL, NULL, NULL, NULL);
  22. if (_zip.zHandle == NULL) {
  23. // printf("Error opening file: %s\n", argv[1]);
  24. return -1;
  25. }
  26. return 0;
  27. } /* open() */
  28. int UNZIP::openZIP(const char *szFilename, ZIP_OPEN_CALLBACK *pfnOpen, ZIP_CLOSE_CALLBACK *pfnClose, ZIP_READ_CALLBACK *pfnRead, ZIP_SEEK_CALLBACK *pfnSeek)
  29. {
  30. _zip.zHandle = unzOpen(szFilename, NULL, 0, &_zip, pfnOpen, pfnRead, pfnSeek, pfnClose);
  31. if (_zip.zHandle == NULL) {
  32. // printf("Error opening file: %s\n", argv[1]);
  33. return -1;
  34. }
  35. return 0;
  36. } /* open() */
  37. int UNZIP::closeZIP()
  38. {
  39. _zip.iLastError = unzClose((unzFile)_zip.zHandle);
  40. return _zip.iLastError;
  41. } /* closeZIP() */
  42. int UNZIP::openCurrentFile()
  43. {
  44. _zip.iLastError = unzOpenCurrentFile((unzFile)_zip.zHandle);
  45. return _zip.iLastError;
  46. } /* openCurrentFile() */
  47. int UNZIP::closeCurrentFile()
  48. {
  49. _zip.iLastError = unzCloseCurrentFile((unzFile)_zip.zHandle);
  50. return _zip.iLastError;
  51. } /* closeCurrentFile() */
  52. int UNZIP::readCurrentFile(uint8_t *buffer, int iLength)
  53. {
  54. return unzReadCurrentFile((unzFile)_zip.zHandle, buffer, iLength);
  55. } /* readCurrentFile() */
  56. int UNZIP::getCurrentFilePos()
  57. {
  58. return (int)unztell((unzFile)_zip.zHandle);
  59. } /* getCurrentFilePos() */
  60. int UNZIP::gotoFirstFile()
  61. {
  62. return unzGoToFirstFile((unzFile)_zip.zHandle);
  63. } /* gotoFirstFile() */
  64. int UNZIP::gotoNextFile()
  65. {
  66. _zip.iLastError = unzGoToNextFile((unzFile)_zip.zHandle);
  67. return _zip.iLastError;
  68. } /* gotoNextFile() */
  69. int UNZIP::locateFile(const char *szFilename)
  70. {
  71. _zip.iLastError = unzLocateFile((unzFile)_zip.zHandle, szFilename, 2);
  72. return _zip.iLastError;
  73. } /* locateFile() */
  74. int UNZIP::getFileInfo(unz_file_info *pFileInfo, char *szFileName, int iFileNameBufferSize, void *extraField, int iExtraFieldBufferSize, char *szComment, int iCommentBufferSize) // get info about the current file
  75. {
  76. return unzGetCurrentFileInfo((unzFile)_zip.zHandle,
  77. pFileInfo,
  78. szFileName,
  79. iFileNameBufferSize,
  80. extraField,
  81. iExtraFieldBufferSize,
  82. szComment,
  83. iCommentBufferSize);
  84. } /* getFileInfo() */
  85. int UNZIP::getLastError()
  86. {
  87. return _zip.iLastError;
  88. } /* getLastError() */
  89. int UNZIP::getGlobalComment(char *destBuffer, int iBufferSize)
  90. {
  91. _zip.iLastError = unzGetGlobalComment((unzFile)_zip.zHandle, destBuffer, iBufferSize);
  92. return _zip.iLastError;
  93. } /* getComment() */