趣味で作ってるロボット用ソフトウェア
 All Classes Files Functions Enumerations Enumerator Friends Pages
zip_unzip.cpp

Zip.cpp を用いたファイルへの展開

#include <iostream>
#include <fstream>
#include "Zip.h"
using namespace hrk;
using namespace std;
int main(int argc, char *argv[])
{
string zip_file = "text_1_2.zip";
if (argc >= 2) {
zip_file = argv[1];
}
Zip zip;
if (!zip.uncompress(zip_file)) {
return 1;
}
vector<Zip::header_t> headers = zip.headers();
for (Zip::Headers::iterator it = headers.begin();
it != headers.end(); ++it) {
const Zip::header_t& header = *it;
zip.open_read_header(header.name);
enum { Buffer_size = 4096 };
char buffer[Buffer_size];
ofstream fout(header.name.c_str(), ios_base::binary);
while (!zip.eof()) {
int n = zip.read(buffer, Buffer_size);
if (n >= 0) {
fout.write(buffer, n);
}
}
}
return 0;
}