2012-03-04 51 views
2

我有一個包含zlib壓縮(放縮)數據的向量。我想用Boost的filtering_istream來解壓縮它。在他們的網站上只有一個例子,它運行在一個數據流上(而不是我擁有的一個矢量)。如何使用Boost解壓縮癟的數據向量?

vector<char> compressed_buffer; 
compressed_buffer.resize(cdh.length); 
file.read(&compressed_buffer[0], cdh.length); 

filtering_istream in; 
in.push(zlib_decompressor()); 
in.push(something(compressed_data)); // what should "something" be? 

我想獲得未壓縮的數據作爲矢量。我怎樣才能做到這一點?

回答

3

array_source怎麼樣?

in.push(array_source(&*compressed_data.begin(), &*compressed_data.end())); 

然後使用boost::iostreams::copystd::insert_iterator將結果字符推入一個新的載體。

+0

謝謝,它工作得很好。爲了將來的參考,我用std :: back_inserter構造了inster_iterator。 – 2012-03-04 19:57:42

+0

@TamásSzelei:聽起來正確:) – 2012-03-04 20:00:10