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

Zip.cpp を用いた圧縮サンプル

#include <iostream>
#include <cstring>
#include "Zip.h"
using namespace hrk;
using namespace std;
namespace
{
bool write(Zip& zip, const char* data, int data_size)
{
int n = zip.write(data, data_size);
if (n < 0) {
cerr << "write fail: " << n << endl;
return false;
}
return true;
}
}
int main(int argc, char *argv[])
{
static_cast<void>(argc);
static_cast<void>(argv);
Zip zip;
if (!zip.compress("test.zip")) {
cerr << "open fail." << endl;
return 1;
}
if (!write(zip, "abcABC", 6)) {
return 1;
}
if (!write(zip, "\n", 1)) {
return 1;
}
if (!write(zip, "123456", 6)) {
return 1;
}
if (!write(zip, "\n", 1)) {
return 1;
}
#if 1
const char message[] =
"iroha nihohedo tirinuruwo "
"wagayo tareso tunenaramu "
"kyo no okuyama kehu koete "
"asaki yumemishi eimo sezu.";
#else
const char message[] = "1";
#endif
const int message_size = strlen(message);
if (!write(zip, message, message_size)) {
return 1;
}
zip.close();
cout << "compressed." << endl;
return 0;
}