/* ** ** $id:$ ** ** File: ex1.cpp -- example of using ZPP library to read a file from a .ZIP ** archive. ** ** Copyright (C) 1999 Michael Cuddy, Fen's Ende Software. All Rights Reserved ** ** Permission to redistribute this code in source or binary format is ** granted for commercial and non-commercial use, provided that the ** above copyright notice is left intact. ** ** Please send email to mcuddy@fensende.com if you are using this code. ** check http://www.fensende.com/zpp for the latest version ** of the code. ** ** Change Log ** ---------- ** $Log: EX1.CPP $ ** Revision 1.2 1999/08/22 05:21:08 mcuddy ** Revision 1.1 1999/06/10 03:34:43 mcuddy ** Initial revision ** */ #include "zpp.h" ///////////////////////////////////////////////////////////////////////// // // test harness // // this program assumes that a zip file called "zpp.zip" exists in // the directory that you are running it in. it assumes that a file // "readme.htm" exists in that .ZIP file. it also assumes that there's // a file called "notinzip.txt" in the current directory which is NOT // in the ZIP file (to test filesystem fallback) // // this program does not illustrate opening of all zip files, attributes, // etc. it's pretty basic. // ///////////////////////////////////////////////////////////////////////// int main() { int i; #ifdef ZPP_INCLUDE_OPENALL zppZipArchive::openAll ("*.zip"); zppZipArchive::dumpGlobalMap(); #endif /* ZPP_INCLUDE_OPENALL */ try { #ifndef ZPP_INCLUDE_OPENALL zppZipArchive zf1(string("zpp.zip")); #endif /* ZPP_INCLUDE_OPENALL */ izppstream fp; fp.open("readme.htm"); if (fp.fail()) { cerr << "can't open readme.htm" << endl; } cout << "<>" << endl; while (!fp.eof() && !fp.fail()) { char c; // do raw read of file so that newlines get read. // alternately, we could do fp->rdbuf() and use the // zppstreambuf object instead. fp.read(&c,1); cout << c; } cout << "<>" << endl; // EOF will be set here, so we need to clear it. fp.clear(ios::goodbit); // we can seek to the BEGINNING of a file, but nowhere // else, currently. fp.seekg(0,ios::beg); i = 0; while (i++ < 1000 && !fp.eof() && !fp.fail()) { char c; fp.read(&c,1); cout << c; } cout << "<>" << endl; fp.close(); fp.open("notinzip.txt"); if (fp.fail()) { cerr << "can't open notinzip.txt" << endl; exit (1); } cout << "<>" << endl; while (!fp.fail() && !fp.eof()) { char c; // do raw read of file so that newlines get read. // alternately, we could do fp->rdbuf() and use the // zppstreambuf object instead. fp.read(&c,1); cout << c; } cout << "<>" << endl; // EOF will be set here, so we need to clear it. fp.clear(ios::goodbit); // we can seek to the BEGINNING of a file, but nowhere // else, currently. fp.seekg(0,ios::beg); i = 0; while (i++ < 1000 && !fp.eof() && !fp.fail()) { char c; fp.read(&c,1); cout << c; } cout << "<>" << endl; } catch ( zppError e ) { cerr << "zppError: " << e.str << endl; } return 0; }