1 #ifndef _library__streamcompress__hpp__included__
2 #define _library__streamcompress__hpp__included__
5 #include <boost/iostreams/categories.hpp>
6 #include <boost/iostreams/operations.hpp>
14 namespace streamcompress
16 std::map
<std::string
, std::string
> parse_attributes(const std::string
& val
);
25 * Parameter in: Input stream pointer. Updated.
26 * Parameter insize: Input stream available. Updated.
27 * Parameter out: Output stream pointer. Updated.
28 * Parameter outsize: Output stream available. Updated.
29 * Parameter final: True if input stream ends after currently available data, false otherwise.
30 * Returns: True if EOS has been seen and all data is emitted, otherwise false.
32 virtual bool process(uint8_t*& in
, size_t& insize
, uint8_t*& out
, size_t& outsize
, bool final
) = 0;
34 static std::set
<std::string
> get_compressors();
35 static base
* create_compressor(const std::string
& name
, const std::string
& args
);
36 static void do_register(const std::string
& name
,
37 std::function
<base
*(const std::string
&)> ctor
);
38 static void do_unregister(const std::string
& name
);
44 typedef char char_type
;
45 struct category
: boost::iostreams::input_filter_tag
, boost::iostreams::multichar_tag
{};
47 * Createa a new compressing stream.
49 iostream(base
* _compressor
)
51 compressor
= _compressor
;
59 template<typename Source
>
60 std::streamsize
read(Source
& src
, char* s
, std::streamsize n
)
64 if(oeof_flag
&& outbuf_use
== 0) {
65 if(flushed
) return flushed
;
69 size_t tocopy
= min(outbuf_use
, (size_t)n
);
70 size_t left
= outbuf_use
- tocopy
;
71 memcpy(s
, outbuffer
, tocopy
);
76 memmove(outbuffer
, outbuffer
+ tocopy
, left
);
79 while(!ieof_flag
&& inbuf_use
< sizeof(inbuffer
)) {
80 std::streamsize r
= boost::iostreams::read(src
, (char*)inbuffer
+ inbuf_use
,
81 sizeof(inbuffer
) - inbuf_use
);
89 uint8_t* in
= inbuffer
;
90 size_t insize
= inbuf_use
;
91 uint8_t* out
= outbuffer
+ outbuf_use
;
92 size_t outsize
= sizeof(outbuffer
) - outbuf_use
;
93 oeof_flag
= compressor
->process(in
, insize
, out
, outsize
, ieof_flag
);
94 outbuf_use
= sizeof(outbuffer
) - outsize
;
95 size_t in_r
= inbuf_use
- insize
;
96 memmove(inbuffer
, inbuffer
+ in_r
, insize
);
102 template<typename Source
>
103 void close(Source
& src
)
108 uint8_t inbuffer
[4096];
109 uint8_t outbuffer
[4096];