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