Zip.cpp を用いた圧縮サンプル
#include <iostream>
#include <cstring>
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);
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;
}
cout << "compressed." << endl;
return 0;
}