[boost::iostreams] How to get number of bytes written?
Hi All, I'm using boost::iostreams and its filters to compress and decompress data. However I'm not able to retrieve number of bytes really written (number of bytes after a compression). Does anybody know how to do that? I'm currently using following code: coffset if offset to where start with writing of compressed data and after call it shall contain the length of the file. This works good to get length of the compressed block unless block of data is written somewhere in the middle of the file thus end of file is not the same as the last offset where compressed data has been written to. io::file_descriptor file(fd); file.seek(coffset, ios_base::beg); { io::filtering_ostream out; // Push the compression filter (bl->type.push(out);) out.push(file); io::write(out, buf, length); // Destroying the object 'out' causes all filters to // flush. } // Update raw length of the file. // coffset = file.seek(0, ios_base::end); Thank you for any help, Milan Svoboda
Milan Svoboda wrote:
Hi All,
I'm using boost::iostreams and its filters to compress and decompress data. However I'm not able to retrieve number of bytes really written (number of bytes after a compression).
Does anybody know how to do that?
I'm currently using following code:
coffset if offset to where start with writing of compressed data and after call it shall contain the length of the file. This works good to get length of the compressed block unless block of data is written somewhere in the middle of the file thus end of file is not the same as the last offset where compressed data has been written to.
io::file_descriptor file(fd); file.seek(coffset, ios_base::beg); { io::filtering_ostream out; // Push the compression filter (bl->type.push(out);) out.push(file);
io::write(out, buf, length);
// Destroying the object 'out' causes all filters to // flush. } // Update raw length of the file. // coffset = file.seek(0, ios_base::end);
Maybe I dont quite understand the problem... Could you just write a simple pass-through filter which counts the bytes only? Something like: io::filtering_ostream out; out.push(compressor()); out.push(passthru()); // <- this just counts bytes out.push(file_sink("my_file.txt"));
eg, le 27 novembre 2008 14:49:
Milan Svoboda wrote:
I'm using boost::iostreams and its filters to compress and decompress data. However I'm not able to retrieve number of bytes really written (number of bytes after a compression).
Does anybody know how to do that? [snip]
Maybe I dont quite understand the problem... Could you just write a simple pass-through filter which counts the bytes only? Something like:
io::filtering_ostream out; out.push(compressor()); out.push(passthru()); // <- this just counts bytes out.push(file_sink("my_file.txt"));
...and if it is the case, good news: It already exists: http://www.boost.org/doc/libs/1_37_0/libs/iostreams/doc/classes/counter.html Éric Malenfant --------------------------------------------- A conclusion is the place where you got tired of thinking
participants (3)
-
eg
-
Eric MALENFANT
-
Milan Svoboda