int check_end(const char* src_begin, const char* dest_begin);
int compress(int action);
int decompress();
+ int end(bool compress, std::nothrow_t);
void end(bool compress);
private:
void do_init( bool compress,
{
public:
bzip2_compressor_impl(const bzip2_params&);
+ ~bzip2_compressor_impl();
bool filter( const char*& src_begin, const char* src_end,
char*& dest_begin, char* dest_end, bool flush );
void close();
{
public:
bzip2_decompressor_impl(bool small = bzip2::default_small);
+ ~bzip2_decompressor_impl();
bool filter( const char*& begin_in, const char* end_in,
char*& begin_out, char* end_out, bool flush );
void close();
bzip2_compressor_impl<Alloc>::bzip2_compressor_impl(const bzip2_params& p)
: bzip2_base(p), eof_(false) { }
+template<typename Alloc>
+bzip2_compressor_impl<Alloc>::~bzip2_compressor_impl()
+{ (void) bzip2_base::end(true, std::nothrow); }
+
template<typename Alloc>
bool bzip2_compressor_impl<Alloc>::filter
( const char*& src_begin, const char* src_end,
bzip2_decompressor_impl<Alloc>::bzip2_decompressor_impl(bool small)
: bzip2_base(bzip2_params(small)), eof_(false) { }
+template<typename Alloc>
+bzip2_decompressor_impl<Alloc>::~bzip2_decompressor_impl()
+{ (void) bzip2_base::end(false, std::nothrow); }
+
template<typename Alloc>
bool bzip2_decompressor_impl<Alloc>::filter
( const char*& src_begin, const char* src_end,
char*& dest_begin, char* dest_end, bool flush )
{
- if (eof_) {
- // reset the stream if there are more characters
- if(src_begin == src_end)
- return false;
- else
- close();
- }
- if (!ready())
- init();
- before(src_begin, src_end, dest_begin, dest_end);
- int result = decompress();
- if(result == bzip2::ok && flush)
- result = check_end(src_begin, dest_begin);
- after(src_begin, dest_begin);
- bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(result);
- eof_ = result == bzip2::stream_end;
+ do {
+ if (eof_) {
+ // reset the stream if there are more characters
+ if(src_begin == src_end)
+ return false;
+ else
+ close();
+ }
+ if (!ready())
+ init();
+ before(src_begin, src_end, dest_begin, dest_end);
+ int result = decompress();
+ if(result == bzip2::ok && flush)
+ result = check_end(src_begin, dest_begin);
+ after(src_begin, dest_begin);
+ bzip2_error::check BOOST_PREVENT_MACRO_SUBSTITUTION(result);
+ eof_ = result == bzip2::stream_end;
+ } while (eof_ && src_begin != src_end && dest_begin != dest_end);
return true;
}