unzOpen 함수로 zip 파일을 열수 있습니다. 열린 zip 파일은 unzClose 함수로 닫아주어야 합니다.
unzGoToFirstFile 함수와 unzGoToNextFile 함수로 순차적으로 파일 목록에 접근할 수 있습니다.
현재 방문중인 파일 정보는 unzGetCurrentFileInfo 함수로 확인할 수 있습니다.
현재 방문중인 파일은 unzOpenCurrentFile 함수로 오픈할 수 있습니다.
오픈된 파일 목록은 unzReadCurrentFile 함수로 데이터를 읽어낼 수 있습니다.
오픈된 파일 목록은 unzCloseCurrentFile 함수로 닫아주어야 합니다.
//
#include "stdafx.h"
#include <LibZ/unzip.h>
#include <fstream>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
do {
unzFile uf = unzOpen("c.zip");
if(NULL == uf) break;
int ret = unzGoToFirstFile(uf);
if( UNZ_OK != ret){
unzClose(uf);
break;
}
/// 현재 방문중인 파일 목록 정보 추출
const int MAX_PATH = 256;
const int MAX_COMMENT = 256;
char filename[MAX_PATH];
char comment[MAX_COMMENT];
unz_file_info info;
unzGetCurrentFileInfo(uf,&info,filename, MAX_PATH, NULL, 0, comment, MAX_COMMENT);
std::cout<<"filename:"<< filename <<" Comment:"<<comment<<std::endl;
std::cout<<" compressed_size:"<< info.compressed_size<<" uncompressed_size:"<< info.uncompressed_size <<std::endl;
//현재 파일을 열기.
ret = unzOpenCurrentFile(uf);
const int BUF =1024;
Bytef in[BUF];
int readsize(0);
std::ofstream op;
op.open(filename, std::ios_base::binary);
do {
readsize = unzReadCurrentFile(uf,(void*) in, BUF);
op.write( (const char*) in, readsize);
} while( 0 != readsize);
op.close();
unzCloseCurrentFile(uf);
/////
unzClose(uf);
} while(false);
system("pause");
return 0;
}