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