in Education by
After spending quite some time debugging the issue today, I noticed the boost::iostream::filtering_ostream needs to be destroy for the sink to be written. Test code: #include #include #include struct ZlibOstream : boost::iostreams::filtering_ostream { ZlibOstream(std::ostream& os) { boost::iostreams::filtering_ostream::push(boost::iostreams::zlib_compressor{}); boost::iostreams::filtering_ostream::push(os); } }; int main() { std::ostringstream oss; #ifdef HAS_SCOPE { #endif ZlibOstream zlibOstream{oss}; zlibOstream << "This is a test string.\n"; #ifdef HAS_SCOPE } #endif return (oss.tellp() == 0); } Calling flush() doesn't do the trick and I don't need to do this when I remove the zlib_compressor. Result with coliru: https://coliru.stacked-crooked.com/a/7cd166d2d820e838 What would be the reason behind this behavior ? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This is in fact related to this question: Flushing a boost::iostreams::zlib_compressor. How to obtain a "sync flush"? You need a call to boost::iostreams::zlib_compressor::close for the flush to happen. You can achieve this by calling either pop() or reset() on the boost::iostream::filtering_ostream. Note, pop() as its name suggest pop the last filter in the chain and reset() clear the chain completely such that the filtering_ostream won't be usable afterward. Example: #include #include #include struct ZlibOstream : boost::iostreams::filtering_ostream { ZlibOstream(std::ostream& os) { boost::iostreams::filtering_ostream::push(boost::iostreams::zlib_compressor{}); boost::iostreams::filtering_ostream::push(os); } }; int main() { std::ostringstream oss; ZlibOstream zlibOstream{oss}; zlibOstream << "This is a test string.\n"; zlibOstream.reset(); // needed if you want to write to oss return oss.tellp(); }

Related questions

0 votes
    I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 22, 2022 in Education by JackTerrance
0 votes
    I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    This is a long shot but, having come across a constrain in a form of a qt's signals, slots being ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    This is a long shot but, having come across a constrain in a form of a qt's signals, slots being ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    When compiling boost filesystem (1_46_1) with Intel 12 Release 4, and Visual Studio 10, I get this error ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I can not seem to be able to read from config file multitoken options like I can from command line ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Which of the following is used to determine, if a piece of data in cache needs to be written back to cache? (a)Valid Bit = 0 (b)Dirty Bit = 1 (c)Valid Bit = 1 (d)Dirty Bit = 0...
asked Oct 6, 2020 in Technology by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 27, 2021 in Education by JackTerrance
0 votes
    What is the output of the following program? 3 . #include using namespace std; struct Time { int hours; int ... 20000 D. O 15000 Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    Which function is used to perform some action when the object is to be destroyed? (a) finalize() ( ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    A matrix of scatterplots can be produced using _________ function. (a) Pears (b) Pairs (c) Tears (d) ... Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    The cumulative frequency distribution of a categorical variable can be checked using the ________ function in R ... R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    R code can be tested using _________________ package. (a) Dplyr (b) Hadley's testthat (c) SKLearn (d) ... Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
...