|
kusano |
fc6ab3 |
/*
|
|
kusano |
fc6ab3 |
* Test program for gzifstream and gzofstream
|
|
kusano |
fc6ab3 |
*
|
|
kusano |
fc6ab3 |
* by Ludwig Schwardt <schwardt@sun.ac.za></schwardt@sun.ac.za>
|
|
kusano |
fc6ab3 |
* original version by Kevin Ruland <kevin@rodin.wustl.edu></kevin@rodin.wustl.edu>
|
|
kusano |
fc6ab3 |
*/
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
#include "zfstream.h"
|
|
kusano |
fc6ab3 |
#include <iostream> // for cout</iostream>
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
int main() {
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
gzofstream outf;
|
|
kusano |
fc6ab3 |
gzifstream inf;
|
|
kusano |
fc6ab3 |
char buf[80];
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
outf.open("test1.txt.gz");
|
|
kusano |
fc6ab3 |
outf << "The quick brown fox sidestepped the lazy canine\n"
|
|
kusano |
fc6ab3 |
<< 1.3 << "\nPlan " << 9 << std::endl;
|
|
kusano |
fc6ab3 |
outf.close();
|
|
kusano |
fc6ab3 |
std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n"
|
|
kusano |
fc6ab3 |
<< "The quick brown fox sidestepped the lazy canine\n"
|
|
kusano |
fc6ab3 |
<< 1.3 << "\nPlan " << 9 << std::endl;
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n";
|
|
kusano |
fc6ab3 |
inf.open("test1.txt.gz");
|
|
kusano |
fc6ab3 |
while (inf.getline(buf,80,'\n')) {
|
|
kusano |
fc6ab3 |
std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
|
|
kusano |
fc6ab3 |
}
|
|
kusano |
fc6ab3 |
inf.close();
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
outf.rdbuf()->pubsetbuf(0,0);
|
|
kusano |
fc6ab3 |
outf.open("test2.txt.gz");
|
|
kusano |
fc6ab3 |
outf << setcompression(Z_NO_COMPRESSION)
|
|
kusano |
fc6ab3 |
<< "The quick brown fox sidestepped the lazy canine\n"
|
|
kusano |
fc6ab3 |
<< 1.3 << "\nPlan " << 9 << std::endl;
|
|
kusano |
fc6ab3 |
outf.close();
|
|
kusano |
fc6ab3 |
std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form";
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n";
|
|
kusano |
fc6ab3 |
inf.rdbuf()->pubsetbuf(0,0);
|
|
kusano |
fc6ab3 |
inf.open("test2.txt.gz");
|
|
kusano |
fc6ab3 |
while (inf.getline(buf,80,'\n')) {
|
|
kusano |
fc6ab3 |
std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n";
|
|
kusano |
fc6ab3 |
}
|
|
kusano |
fc6ab3 |
inf.close();
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
return 0;
|
|
kusano |
fc6ab3 |
|
|
kusano |
fc6ab3 |
}
|