1*aaf4ece6Schristos /* 2*aaf4ece6Schristos * Test program for gzifstream and gzofstream 3*aaf4ece6Schristos * 4*aaf4ece6Schristos * by Ludwig Schwardt <schwardt@sun.ac.za> 5*aaf4ece6Schristos * original version by Kevin Ruland <kevin@rodin.wustl.edu> 6*aaf4ece6Schristos */ 7*aaf4ece6Schristos 8*aaf4ece6Schristos #include "zfstream.h" 9*aaf4ece6Schristos #include <iostream> // for cout 10*aaf4ece6Schristos main()11*aaf4ece6Schristosint main() { 12*aaf4ece6Schristos 13*aaf4ece6Schristos gzofstream outf; 14*aaf4ece6Schristos gzifstream inf; 15*aaf4ece6Schristos char buf[80]; 16*aaf4ece6Schristos 17*aaf4ece6Schristos outf.open("test1.txt.gz"); 18*aaf4ece6Schristos outf << "The quick brown fox sidestepped the lazy canine\n" 19*aaf4ece6Schristos << 1.3 << "\nPlan " << 9 << std::endl; 20*aaf4ece6Schristos outf.close(); 21*aaf4ece6Schristos std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" 22*aaf4ece6Schristos << "The quick brown fox sidestepped the lazy canine\n" 23*aaf4ece6Schristos << 1.3 << "\nPlan " << 9 << std::endl; 24*aaf4ece6Schristos 25*aaf4ece6Schristos std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; 26*aaf4ece6Schristos inf.open("test1.txt.gz"); 27*aaf4ece6Schristos while (inf.getline(buf,80,'\n')) { 28*aaf4ece6Schristos std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; 29*aaf4ece6Schristos } 30*aaf4ece6Schristos inf.close(); 31*aaf4ece6Schristos 32*aaf4ece6Schristos outf.rdbuf()->pubsetbuf(0,0); 33*aaf4ece6Schristos outf.open("test2.txt.gz"); 34*aaf4ece6Schristos outf << setcompression(Z_NO_COMPRESSION) 35*aaf4ece6Schristos << "The quick brown fox sidestepped the lazy canine\n" 36*aaf4ece6Schristos << 1.3 << "\nPlan " << 9 << std::endl; 37*aaf4ece6Schristos outf.close(); 38*aaf4ece6Schristos std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; 39*aaf4ece6Schristos 40*aaf4ece6Schristos std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; 41*aaf4ece6Schristos inf.rdbuf()->pubsetbuf(0,0); 42*aaf4ece6Schristos inf.open("test2.txt.gz"); 43*aaf4ece6Schristos while (inf.getline(buf,80,'\n')) { 44*aaf4ece6Schristos std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; 45*aaf4ece6Schristos } 46*aaf4ece6Schristos inf.close(); 47*aaf4ece6Schristos 48*aaf4ece6Schristos return 0; 49*aaf4ece6Schristos 50*aaf4ece6Schristos } 51