1275793eaSopenharmony_ci/* 2275793eaSopenharmony_ci * Test program for gzifstream and gzofstream 3275793eaSopenharmony_ci * 4275793eaSopenharmony_ci * by Ludwig Schwardt <schwardt@sun.ac.za> 5275793eaSopenharmony_ci * original version by Kevin Ruland <kevin@rodin.wustl.edu> 6275793eaSopenharmony_ci */ 7275793eaSopenharmony_ci 8275793eaSopenharmony_ci#include "zfstream.h" 9275793eaSopenharmony_ci#include <iostream> // for cout 10275793eaSopenharmony_ci 11275793eaSopenharmony_ciint main() { 12275793eaSopenharmony_ci 13275793eaSopenharmony_ci gzofstream outf; 14275793eaSopenharmony_ci gzifstream inf; 15275793eaSopenharmony_ci char buf[80]; 16275793eaSopenharmony_ci 17275793eaSopenharmony_ci outf.open("test1.txt.gz"); 18275793eaSopenharmony_ci outf << "The quick brown fox sidestepped the lazy canine\n" 19275793eaSopenharmony_ci << 1.3 << "\nPlan " << 9 << std::endl; 20275793eaSopenharmony_ci outf.close(); 21275793eaSopenharmony_ci std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" 22275793eaSopenharmony_ci << "The quick brown fox sidestepped the lazy canine\n" 23275793eaSopenharmony_ci << 1.3 << "\nPlan " << 9 << std::endl; 24275793eaSopenharmony_ci 25275793eaSopenharmony_ci std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; 26275793eaSopenharmony_ci inf.open("test1.txt.gz"); 27275793eaSopenharmony_ci while (inf.getline(buf,80,'\n')) { 28275793eaSopenharmony_ci std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; 29275793eaSopenharmony_ci } 30275793eaSopenharmony_ci inf.close(); 31275793eaSopenharmony_ci 32275793eaSopenharmony_ci outf.rdbuf()->pubsetbuf(0,0); 33275793eaSopenharmony_ci outf.open("test2.txt.gz"); 34275793eaSopenharmony_ci outf << setcompression(Z_NO_COMPRESSION) 35275793eaSopenharmony_ci << "The quick brown fox sidestepped the lazy canine\n" 36275793eaSopenharmony_ci << 1.3 << "\nPlan " << 9 << std::endl; 37275793eaSopenharmony_ci outf.close(); 38275793eaSopenharmony_ci std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; 39275793eaSopenharmony_ci 40275793eaSopenharmony_ci std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; 41275793eaSopenharmony_ci inf.rdbuf()->pubsetbuf(0,0); 42275793eaSopenharmony_ci inf.open("test2.txt.gz"); 43275793eaSopenharmony_ci while (inf.getline(buf,80,'\n')) { 44275793eaSopenharmony_ci std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; 45275793eaSopenharmony_ci } 46275793eaSopenharmony_ci inf.close(); 47275793eaSopenharmony_ci 48275793eaSopenharmony_ci return 0; 49275793eaSopenharmony_ci 50275793eaSopenharmony_ci} 51