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