Game Development Reference
In-Depth Information
How to do it...
1.
The following helper function does the job of ile extraction and is used in the Archiv
eReader::ExtractSingleFile() method:
int ExtractCurrentFile_ZIP( unzFile uf,
const char* password, const clPtr<iOStream>& fout )
{
char filename_inzip[256];
int err = UNZ_OK;
void* buf;
uInt size_buf;
unz_file_info64 file_info;
err = unzGetCurrentFileInfo64( uf, &file_info,
filename_inzip, sizeof( filename_inzip ),
NULL, 0, NULL, 0 );
if ( err != UNZ_OK ) { return err; }
uint64_t file_size = ( uint64_t )file_info.uncompressed_size;
uint64_t total_bytes = 0;
unsigned char _buf[WRITEBUFFERSIZE];
size_buf = WRITEBUFFERSIZE;
buf = ( void* )_buf;
if ( buf == NULL ) { return UNZ_INTERNALERROR; }
2.
Pass the supplied password to the zlib library:
err = unzOpenCurrentFilePassword( uf, password );
3.
The following is the actual decompression loop:
do
{
err = unzReadCurrentFile( uf, buf, size_buf );
if ( err < 0 )
{ break; }
if ( err > 0 )
{ total_bytes += err; fout->Write( buf, err ); }
}
while ( err > 0 );
int close_err = unzCloseCurrentFile ( uf );
}
4.
And the ExtractSingleFile() function performs the extraction of a single ile
from an archive into an output stream:
bool ArchiveReader::ExtractSingleFile( const string& FName,
const string& Password, const clPtr<iOStream>& FOut )
 
Search WWH ::




Custom Search