XStream C++ flexible stream library 0.0.1 Introduction This library is supposed to help the developer's work by making easy doing the following things using C++'s standard iostream/streambuf architecture: Compressing and decompressing data using zlib and bzlib Encode and decode base64 data Serialize and deserialize structures to XDR Calculate digests of data Fork data written to a stream to several others Use file descriptors using a iostream interface (where available) All this by just creating some new streambufs (and iostream like classes for the xdr operations) that can be coupled to any C++ standard iostream, like cin, ifstream, ofstream, stringstream, or any others defined by this library or the user. Pre-requisites zlib for gzip deflate/inflate compression (gzip compression currently not supported, only decompression), adler32 and crc32 digests bz2lib for bzip2 compression and decompressing modern c++ compiler and a compliant io library (g++ >= 3.3 should be enough) POSIX system for file descriptor classes Usage Note: unless written otherwise, all this section is supposed to be using the std namespace. If you're in a hurry you should check the examples directory. There you will find simple examples of almost all the library's functionalities. The test directory also contains some more examples on how to use the library. Philosophy C++ standard io facilites are istreams, ostreams and iostreams. cin is an istream (used for input) cout is an ostream (use for output) and an fstream openned for both reading and writting is an iostream (allows for both input and output) iostreams by themselfs don't read or write any data to any files, or input/output "channels" (standard input/output/error), instead they delegate all these tasks to streambufs. These are responsible for buffering data that iostreams ask them to read/write and actually manage the "physical" reading/writting as well as seeking, flushing, closing and whatever low-level work necessary. Every ios object has a streambuf member used for reading/writting, this can be reached via the rdbuf() method, so: streambuf* buf = cin.rdbuf(); retireves the streambuf that cin uses to read data. It's also possible to change the streambuf of an ios object by using the same method with the new streambuf* as an argument. So, //buf is a streambuf* initialized before cin.rdbuf(buf); now makes cin use buf for reading data, so you can do a kind of standard input redirection from within C++. From now onward, when you write cin>>var; you read var from data suplied by buf and not standard input. Understanding this is crucial to using this library and grasping it's goal. What does XStream do? XStream gives you some new streambuf objects (they inherit from streambuf) that perform some kind of filtering operation or redirect data to another streambuf. In essence this allows to stack several filters and use iostreams to acess data after several transforms. For example, suppose you want to read data from a file whose content is several lines of numbers base64 encoded, you could simply proceed like this: #include //to open the file for reading #include //xstream base64 classes #include using namespace std; using namespace xstream; int main(int argc, char* argv[]){ ifstream file("base64_encoded_file"); //this creates a xstream base64 input streambuf b64sb //this reads data from the streambuf of file base64::istreambuf b64sb(file.rdbuf()); //now create a usual istream that reads data from the base64 streambuf istream decoded(&b64sb); //read decoded data while(decoded.good()){ int i; decoded>>i; cout<