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