38 #include <minizip/unzip.h> 39 #include <minizip/zip.h> 41 #include <geogram/basic/file_system.h> 45 #define MAX_FILENAME 512 46 #define READ_SIZE 8192 58 Impl(
const std::string& filename )
60 zip_file_ = zipOpen( filename.c_str(), APPEND_STATUS_CREATE );
64 "ZipFile",
"Could not read file ", filename );
76 filename.c_str(), std::ios::in | std::ios::binary );
77 file.seekg( 0, std::ios::end );
78 auto size =
static_cast< index_t
>( file.tellg() );
79 file.seekg( 0, std::ios::beg );
80 std::vector< char > buffer( size );
81 file.read( &buffer[0], size );
82 zipOpenNewFileInZip(
zip_file_, filename.c_str(),
nullptr,
nullptr,
83 0,
nullptr, 0,
nullptr, Z_DEFLATED, Z_DEFAULT_COMPRESSION );
84 zipWriteInFileInZip(
zip_file_, size == 0 ?
"" : &buffer[0], size );
103 impl_->add_file( filename );
109 Impl(
const std::string& filename )
111 zip_file_ = unzOpen( filename.c_str() );
112 if( zip_file_ ==
nullptr )
115 "UnZipFile",
"Could not read file ", filename );
121 unzClose( zip_file_ );
126 unzLocateFile( zip_file_, filename.c_str(), 0 );
127 unzip_current_file( zip_file_, filename );
132 if( unzGoToFirstFile( zip_file_ ) != UNZ_OK )
135 "UnZipFile",
"Unable to uncompress the first file" );
141 unzip_current_file( zip_file_, get_current_filename().c_str() );
147 if( unzGetCurrentFileInfo64( zip_file_,
nullptr, char_file_name,
152 "UnZipFile",
"Unable to get file name" );
154 return { char_file_name };
159 return unzGoToNextFile( zip_file_ ) == UNZ_OK;
166 if( unzOpenCurrentFile( uz ) != UNZ_OK )
171 FILE* out{ fopen( filename.c_str(),
"wb" ) };
174 unzCloseCurrentFile( uz );
177 "UnZipFile",
"Could not open destination file" );
185 unzCloseCurrentFile( uz );
189 "UnZipFile",
"Invalid error: ",
error );
193 fwrite( read_buffer, static_cast< std::size_t >(
error ),
194 std::size_t( 1 ), out );
196 }
while(
error > 0 );
198 unzCloseCurrentFile( uz );
202 unzFile zip_file_{
nullptr };
215 impl_->get_file( filename );
220 impl_->start_extract();
225 impl_->get_current_file();
230 return impl_->get_current_filename();
235 return impl_->next_file();
void get_file(const std::string &filename)
void add_file(const std::string &filename)
void add_file(const std::string &filename)
std::string get_current_filename()
std::string get_current_filename()
Impl(const std::string &filename)
UnZipFile(const std::string &filename)
void unzip_current_file(unzFile uz, const std::string &filename)
Classes to build GeoModel from various inputs.
void get_file(const std::string &filename)
ZipFile(const std::string &filename)
void error(index_t vertex_id_in_mesh_entity, index_t vertex_id_in_geomodel_mesh, const gmme_id &mesh_entity_gmme_id)
Impl(const std::string &filename)