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