static int save_archive(char *filename, char *buffer, int size) { zipFile fd = NULL; int ret = 0; fd=zipOpen(filename,0); if(!fd) { printf("Failed to create zip\r\n"); return (0); } ret=zipOpenNewFileInZip(fd,"SNAPSHOT", NULL, NULL,0, NULL,0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION); if(ret != ZIP_OK) { zipClose(fd,NULL); printf("Failed to create file in zip\r\n"); return (0); } ret=zipWriteInFileInZip(fd,buffer,size); if(ret != ZIP_OK) { zipCloseFileInZip(fd); zipClose(fd,NULL); printf("Failed to write file in zip\r\n"); return (0); } ret=zipCloseFileInZip(fd); if(ret != ZIP_OK) { zipClose(fd,NULL); printf("Failed to close file in zip\r\n"); return (0); } ret=zipClose(fd,NULL); if(ret != ZIP_OK) { printf("Failed to close zip\r\n"); return (0); } return(1); }
void ZipFileHandler::OnHandleDestroy(HandleType_t, void *object) { if (NULL != object) { zipClose((zipFile)object, NULL); } }
/* Trying to write offset and vertices data to file. */ void CPathEstimator::WriteFile(string name) { // We need this directory to exist boost::filesystem::path f("./maps/paths"); if (!boost::filesystem::exists(f)) boost::filesystem::create_directories(f); unsigned int hash = Hash(); char hashString[50]; sprintf(hashString,"%u",hash); string filename = string("maps/paths/") + stupidGlobalMapname.substr(0, stupidGlobalMapname.find('.') + 1) + hashString + "." + name + ".zip"; zipFile file = zipOpen(filename.c_str(), APPEND_STATUS_CREATE); if (file) { zipOpenNewFileInZip(file, "pathinfo", NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION); //Write hash. unsigned int hash = Hash(); zipWriteInFileInZip(file, (void*)&hash, 4); //Write block-center-offsets. int blocknr; for(blocknr = 0; blocknr < nbrOfBlocks; blocknr++) { zipWriteInFileInZip(file, (void*)blockState[blocknr].sqrCenter, moveinfo->moveData.size() * sizeof(int2)); //file.write((char*)blockState[blocknr].sqrCenter, moveinfo->moveData.size() * sizeof(int2)); } //Write vertices. zipWriteInFileInZip(file, (void*)vertex, nbrOfVertices * sizeof(float)); //file.write((char*)vertex, nbrOfVertices * sizeof(float)); zipCloseFileInZip(file); zipClose(file, NULL); } }
bool ZipFile::SwitchMode(short mode) { if(mode == ZipFile::OPEN) { if(zFile) { zipClose(zFile, NULL); zFile = 0; } if(!uzFile) uzFile = unzOpen(ZipFilePath.c_str()); return (uzFile != 0); } else if(mode == ZipFile::CREATE || mode == ZipFile::APPEND) { if(uzFile) { unzClose(uzFile); uzFile = 0; } if(!zFile) zFile = zipOpen(ZipFilePath.c_str(), mode); return (zFile != 0); } return false; }
bool ZipCreator::SaveAs(const WCHAR *zipFilePath) { if (d->pathsAndZipNames.Count() == 0) return false; zlib_filefunc64_def ffunc; fill_win32_filefunc64(&ffunc); zipFile zf = zipOpen2_64(zipFilePath, 0, NULL, &ffunc); if (!zf) return false; bool result = true; for (size_t i = 0; i < d->pathsAndZipNames.Count(); i += 2) { const WCHAR *fileName = d->pathsAndZipNames.At(i); const WCHAR *nameInZip = d->pathsAndZipNames.At(i + 1); size_t fileSize; ScopedMem<char> fileData(file::ReadAll(fileName, &fileSize)); if (!fileData) { result = false; break; } result = AppendFileToZip(zf, nameInZip, fileData, fileSize); if (!result) break; } int err = zipClose(zf, NULL); if (err != ZIP_OK) result = false; return result; }
void FileUtils::addToZip(const char* archivePath, const char* path, const char* content, int length) throw (IOException) { int result = ZIP_OK; int appendMode = fileExists(archivePath) ? APPEND_STATUS_ADDINZIP : APPEND_STATUS_CREATE; zipFile archive = zipOpen(archivePath, appendMode); result = zipOpenNewFileInZip(archive, path, 0 /* file attributes */, 0 /* extra field */, 0 /* extra field size */, 0/* global extra field */, 0 /* global extra field size */, 0 /* comment */, Z_DEFLATED /* method */, Z_DEFAULT_COMPRESSION /* level */); if (result != ZIP_OK) { throw IOException("Unable to add new file to zip archive"); } result = zipWriteInFileInZip(archive, content, static_cast<unsigned int>(length)); if (result != ZIP_OK) { throw IOException("Unable to write file data to zip archive"); } result = zipCloseFileInZip(archive); if (result != ZIP_OK) { throw IOException("Unable to close file in zip archive"); } result = zipClose(archive, 0 /* global comment */); if (result != ZIP_OK) { throw IOException("Unable to close zip archive"); } }
//----------------------------------------------------------------------------- // CZLib::Close // // Close open zip file // void CZLib::Close() { if (m_zf) zipClose(m_zf, NULL); m_zf = 0; }
void QuaZip::close() { p->zipError=UNZ_OK; switch(p->mode) { case mdNotOpen: qWarning("QuaZip::close(): ZIP is not open"); return; case mdUnzip: p->zipError=unzClose(p->unzFile_f); break; case mdCreate: case mdAppend: case mdAdd: p->zipError=zipClose(p->zipFile_f, p->commentCodec->fromUnicode(p->comment).constData()); break; default: qWarning("QuaZip::close(): unknown mode: %d", (int)p->mode); return; } // opened by name, need to delete the internal IO device if (!p->zipName.isEmpty()) delete p->ioDevice; if(p->zipError==UNZ_OK) p->mode=mdNotOpen; }
// TODO: using this for XPS files results in documents that Microsoft XPS Viewer can't read IStream *OpenDirAsZipStream(const WCHAR *dirPath, bool recursive) { if (!dir::Exists(dirPath)) return NULL; ScopedComPtr<IStream> stream; if (FAILED(CreateStreamOnHGlobal(NULL, TRUE, &stream))) return NULL; zlib_filefunc64_def ffunc; fill_win32s_filefunc64(&ffunc); zipFile zf = zipOpen2_64(stream, 0, NULL, &ffunc); if (!zf) return NULL; size_t dirLen = str::Len(dirPath); if (!path::IsSep(dirPath[dirLen - 1])) dirLen++; bool ok = true; DirIter di(dirPath, recursive); for (const WCHAR *filePath = di.First(); filePath && ok; filePath = di.Next()) { CrashIf(!str::StartsWith(filePath, dirPath)); const WCHAR *nameInZip = filePath + dirLen; size_t fileSize; ScopedMem<char> fileData(file::ReadAll(filePath, &fileSize)); ok = fileData && AppendFileToZip(zf, nameInZip, fileData, fileSize); } int err = zipClose(zf, NULL); if (!ok || err != ZIP_OK) return NULL; stream->AddRef(); return stream; }
bool ZipFile::Close(QString comment) { if (!zf) return false; bool success = zipClose(zf, comment.toAscii().constData()) == ZIP_OK; zf = NULL; return success; }
ZipFile::~ZipFile() { ClearList(); if(uzFile) unzClose(uzFile); if(zFile) zipClose(zFile, NULL); }
void ZipArchive::close() { if (!isOpen()) return; zipClose(d->zip, 0); d->zip = 0; }
void close_ZIP_archive(void) { if (unzipping) unzClose(unzip_handle); else zipClose(zip_handle, NULL); }
ZipArchiveImpl::~ZipArchiveImpl() { int r = ZIP_OK; if (m_File) r = zipClose(m_File, ":)"); m_File = nullptr; m_Info = ArchiveInfo(); }
BOOL fsUploadMgr::ZipFiles () { if (m_bZipFileCreated) return TRUE; Event (UMGRE_ZIP_FILES_START); char szTmpFile [MAX_PATH]; char szTmpPath [MAX_PATH]; GetTempPath (MAX_PATH, szTmpPath); GetTempFileName (szTmpPath, "tmp", 0, szTmpFile); m_strUploadFile = szTmpFile; zipFile zip = zipOpen (m_strUploadFile, 0); BOOL bOk = TRUE; m_strZipContentsDescHtml = "<ul>"; for (size_t i = 0; i < m_pkg.m_vPathes.size () && bOk && m_bNeedStop == false; i++) { LPCSTR psz = m_pkg.m_vPathes [i]; char szName [1000] = ""; fsGetFileName (psz, szName); if (GetFileAttributes (psz) & FILE_ATTRIBUTE_DIRECTORY) { AddItemToZipContentsDescHtml (szName, _UI64_MAX); m_strZipContentsDescHtml += "<ul>"; bOk = bOk && Zip_AddFolder (zip, psz, NULL, 1); m_strZipContentsDescHtml += "</ul>"; } else { bOk = bOk && Zip_AddFile (zip, psz, NULL); if (bOk) { WIN32_FILE_ATTRIBUTE_DATA wfad; GetFileAttributesEx (psz, GetFileExInfoStandard, &wfad); AddItemToZipContentsDescHtml (szName, ((UINT64)wfad.nFileSizeHigh << 32) + wfad.nFileSizeLow); } } } m_strZipContentsDescHtml += "</ul>"; zipClose (zip, NULL); if (m_bNeedStop || bOk == FALSE) DeleteFile (m_strUploadFile); else m_bZipFileCreated = TRUE; if (m_bNeedStop == false) Event (bOk ? UMGRE_ZIP_FILES_DONE : UMGRE_ZIP_FILES_FAILED); return m_bZipFileCreated; }
bool Zip::Close() { if (m_zipFile) { m_errcode = zipClose(m_zipFile, nullptr); m_zipFile = nullptr; return m_errcode == ZIP_OK; } return true; }
void ZipWriter::Close() { if (IsOpen()) { zipClose(pimpl_->file_, "Created by Orthanc"); pimpl_->file_ = NULL; hasFileInZip_ = false; } }
//by stone bool FileSystemZip::Init_zMemory(std::string NameInZip, unsigned char* buf, int size, int append) { unzFile zf; zip_fileinfo zi; time_t tm_t; struct tm* filedate; int opt_compress_level = Z_BEST_COMPRESSION; //use best compress if( m_compress_buf ) { delete m_compress_buf; m_compress_buf = NULL; } m_compress_buf = new byte[size]; zf = ZipOpen_Memory(m_compress_buf, size, append); if (!zf) { LogError("Cannot create memory using"); return false; } LogMsg("deflate zip as memory"); memset(&zi,0,sizeof(zip_fileinfo)); tm_t = time(NULL); filedate = localtime(&tm_t); zi.tmz_date.tm_sec = filedate->tm_sec; zi.tmz_date.tm_min = filedate->tm_min; zi.tmz_date.tm_hour = filedate->tm_hour; zi.tmz_date.tm_mday = filedate->tm_mday; zi.tmz_date.tm_mon = filedate->tm_mon ; zi.tmz_date.tm_year = filedate->tm_year; zipOpenNewFileInZip(zf, NameInZip.c_str(), &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, opt_compress_level); zipWriteInFileInZip(zf,buf,size); zipCloseFileInZip(zf); m_zip_size = zipClose(zf, NULL); //m_zipFileName = zipFileName; //save it in case we need to spawn more zip readers for streaming operations //CacheIndex(); return true; //success }
// //////////////////////////////////////////////////////////////////////////////// // @public @static 将指定文件名打包成指定 zip // bool ZipTools::Zip(LPCWSTR wzDirPath, LPCWSTR wzDestName) { // // 检查指定路径是否存在 // if ( !FileTools::Exist(wzDirPath) ) { DebugTools::OutputDebugPrintfW(L"[ZipTools] [Zip] Path Not Exist. [%s]\r\n", wzDirPath); return false; } WCHAR wzDestDir[MAX_PATH] = {0}; FileTools::GetFileDir(wzDestName, wzDestDir, L'\\'); if ( !FileTools::Exist(wzDestDir) ) { DebugTools::OutputDebugPrintfW(L"[ZipTools] [Zip] Path Not Exist. [%s]\r\n", wzDestDir); return false; } // 设置当前工作目录 SetCurrentDirectoryW(wzDirPath); WCHAR wzParentDir[MAX_PATH] = {0}; wcscpy_s(wzParentDir, wzDirPath); //FileTools::GetFileDir(wzDirPath, wzParentDir, L'\\'); wcscat_s(wzParentDir, L"\\"); // // 创建 zip 文件 // zlib_filefunc64_def ffunc; fill_win32_filefunc64W(&ffunc); zipFile zf; zf = zipOpen2_64(wzDestName, 0, NULL, &ffunc); if ( NULL == zf ) { DebugTools::OutputDebugPrintfW( L"[ZipTools] [Zip] Create Zip File Failed. [%s] \r\n", wzDestName); return false; } unsigned long size_read = 0; unsigned long size_buf = WRITEBUFFERSIZE; PBYTE buf = new BYTE [size_buf]; // // 将文件夹下所有文件添加进 zip // AddFileToZip(zf, wzDirPath, wzParentDir, buf); zipClose(zf,NULL); delete [] buf; return true; }
int hts_extract_meta(const char* path) { char catbuff[CATBUFF_SIZE]; unzFile zFile = unzOpen(fconcat(catbuff,path,"hts-cache/new.zip")); zipFile zFileOut = zipOpen(fconcat(catbuff,path,"hts-cache/meta.zip"), 0); if (zFile != NULL && zFileOut != NULL) { if (unzGoToFirstFile(zFile) == Z_OK) { zip_fileinfo fi; unz_file_info ufi; char BIGSTK filename[HTS_URLMAXSIZE * 4]; char BIGSTK comment[8192]; memset(comment, 0, sizeof(comment)); // for truncated reads memset(&fi, 0, sizeof(fi)); memset(&ufi, 0, sizeof(ufi)); do { int readSizeHeader; filename[0] = '\0'; comment[0] = '\0'; if (unzOpenCurrentFile(zFile) == Z_OK) { if ( (readSizeHeader = unzGetLocalExtrafield(zFile, comment, sizeof(comment) - 2)) > 0 && unzGetCurrentFileInfo(zFile, &ufi, filename, sizeof(filename) - 2, NULL, 0, NULL, 0) == Z_OK ) { comment[readSizeHeader] = '\0'; fi.dosDate = ufi.dosDate; fi.internal_fa = ufi.internal_fa; fi.external_fa = ufi.external_fa; if (zipOpenNewFileInZip(zFileOut, filename, &fi, NULL, 0, NULL, 0, NULL, /* comment */ Z_DEFLATED, Z_DEFAULT_COMPRESSION) == Z_OK) { if (zipWriteInFileInZip(zFileOut, comment, (int) strlen(comment)) != Z_OK) { } if (zipCloseFileInZip(zFileOut) != Z_OK) { } } } unzCloseCurrentFile(zFile); } } while( unzGoToNextFile(zFile) == Z_OK ); } zipClose(zFileOut, "Meta-data extracted by HTTrack/"HTTRACK_VERSION); unzClose(zFile); return 1; } return 0; }
static HB_GARBAGE_FUNC( hb_zipfile_destructor ) { zipFile * phZip = ( zipFile * ) Cargo; if( *phZip ) { zipClose( *phZip, NULL ); *phZip = NULL; } }
void MkInterfaceForZipFileWriting::Clear(void) { if (m_ZipFile != NULL) { m_CurrentFilePath.Clear(); zipClose(m_ZipFile, NULL); m_ZipFile = NULL; } }
/* ======================== idZipBuilder::CleanSourceFolder this folder is assumed to be a path under FSPATH_BASE ======================== */ void idZipBuilder::CloseZipFile( zipFile zf ) { // close the zip file int closeError = zipClose( zf, zipFileName ); if( closeError != ZIP_OK ) { idLib::Warning( "[%s] - error closing file '%s'!", __FUNCTION__, zipFileName.c_str() ); } idLib::PrintfIf( zip_verbosity.GetBool(), "Done.\n" ); }
// ---------------------------------------------------------------------------- // Compress // ---------------------------------------------------------------------------- bool archive_Compress(std::string zipFilename, std::string filename, const byte* data, uint size) { if(zipFilename.empty( ) || zipFilename.size( ) == 0) { logger_LogError("Zip filename is invalid.", ARCHIVE_SOURCE); return false; } if(filename.empty( ) || filename.size( ) == 0) { logger_LogError("Filename is invalid.", ARCHIVE_SOURCE); return false; } if(data == NULL) { logger_LogError("Data parameter is invalid.", ARCHIVE_SOURCE); return false; } zipFile file = zipOpen(zipFilename.c_str( ), APPEND_STATUS_CREATE); if(file == NULL) { logger_LogInfo("Failed to create the zip file " + zipFilename + ".", ARCHIVE_SOURCE); return false; } zip_fileinfo fileInfo = {0}; fileInfo.dosDate = 1; int result = zipOpenNewFileInZip(file, filename.c_str( ), &fileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION); if(result != ZIP_OK) { logger_LogInfo("Failed to open a new file within the zip file " + filename + ".", ARCHIVE_SOURCE); logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); zipClose(file, "Failed to compress."); return false; } result = zipWriteInFileInZip(file, data, size); if(result != ZIP_OK) { logger_LogInfo("Failed to write data to the zip file " + filename + ".", ARCHIVE_SOURCE); zipCloseFileInZip(file); zipClose(file, "Failed to compress."); return false; } zipCloseFileInZip(file); zipClose(file, "Comment"); return true; }
void ZipArchiveWriter::Close() { m_errCode = Z_ERRNO; if (m_hZip) { zipClose(m_hZip, nullptr); m_hZip = nullptr; } }
bool CZipper::CloseZip() { int nRet = m_uzFile ? zipClose(m_uzFile, NULL) : ZIP_OK; m_uzFile = NULL; m_szRootFolder[0] = 0; ZeroMemory(&m_info, sizeof(m_info)); return (nRet == ZIP_OK); }
static int writezip_cb(lua_State* L) { const char* zipname = luaL_checkstring(L, 1); luaL_checktype(L, 2, LUA_TTABLE); int result = 0; zipFile zf = zipOpen(zipname, APPEND_STATUS_CREATE); if (zf) { result = 1; lua_pushnil(L); while (lua_next(L, 2) != 0) { const char* key = lua_tostring(L, -2); size_t valuelen; const char* value = lua_tolstring(L, -1, &valuelen); int i = zipOpenNewFileInZip(zf, key, NULL, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION); if (i != ZIP_OK) { result = 0; break; } i = zipWriteInFileInZip(zf, value, valuelen); if (i != ZIP_OK) { result = 0; break; } i = zipCloseFileInZip(zf); if (i != ZIP_OK) { result = 0; break; } lua_pop(L, 1); /* leave key on stack */ } zipClose(zf, NULL); } if (!result) return 0; lua_pushboolean(L, true); return 1; }
void QZipFile::close() { if (m_unzFile) { unzClose(m_unzFile); m_unzFile = 0; } if (m_zipFile) { zipClose(m_zipFile, NULL); m_zipFile = NULL; } }
int FILE_compress_dir(const string& src_path, const string& dst_path, const string& prefix) { zipFile archive = zipOpen(dst_path.c_str(), 0); if(archive == NULL) return -1; int r = compress_recursive(archive, src_path,prefix); zipClose(archive, NULL); return r; }
bool CompressFiles(const wchar_t* zip_file_path, const RequestFileCallback& callback, void* pParam, int compression_level) { zipFile zip_file_handle = zipOpenHelp(zip_file_path); if(NULL != zip_file_handle) { zip_fileinfo zi = {0}; #if defined(_WIN32) || defined (_WIN64) SYSTEMTIME currTime; GetLocalTime( &currTime ); zi.tmz_date.tm_sec = currTime.wSecond; zi.tmz_date.tm_min = currTime.wMinute; zi.tmz_date.tm_hour = currTime.wHour; zi.tmz_date.tm_mday = currTime.wDay; zi.tmz_date.tm_mon = currTime.wMonth; zi.tmz_date.tm_year = currTime.wYear; #endif BYTE* pData = NULL; long nSize; std::wstring in_zip_filename; while(callback(in_zip_filename, pData, nSize, pParam)) { std::string in_zip_filenameA = codepage_issue_fixToOEM(in_zip_filename); if (ZIP_OK != zipOpenNewFileInZip( zip_file_handle, in_zip_filenameA.c_str(), &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, compression_level ) || ZIP_OK != zipWriteInFileInZip(zip_file_handle, pData, nSize) || ZIP_OK != zipCloseFileInZip(zip_file_handle)) { zipClose(zip_file_handle, NULL); return false; } } zipClose(zip_file_handle, NULL); return true; } return false; }