|
Boost Users : |
Subject: [Boost-users] [Iostreams] Problem to chain gzip filter with home-made one
From: Christophe hugon (chugon_at_[hidden])
Date: 2013-10-31 05:48:04
Hello everybody,
I meeting a execution issue while using the gzip filter of the
Boost.Iostreams, combined with a buffered home-made one. I would like to
know what is wrong in my way to do it.
Firstly, my filter is a general DualFilter. It uses an buffer (of 16
bytes) before the transformation and the put/return. The categories of
my filter is closable and dual_use.
You can find code details in the end of this mail.
My problem is ([a/b] means for the separates case with the letter a and b):
If I take the 6 possibilities for write and read:
1) io::filtering_[i/o]stream stm;
2) stm.push(io::gzip_[de/]compressor());
3) stm.push(my_[Unt/T]ransFilter);
at the moment to use the stm.[get/put] to read/write
1)-2) works perfectly
1)-3) works perfectly
1)-3)-2) works perfectly
1)-2)-3) Stay stuck (obviously it is the one I really need)
In fact in the last case, the gzip filter give this infinite loop to the
put of the TransFilter :
31 -117 8 0 0 0 0 0 0 31 -117 8 0 0...
A similar case occur with the bzip filter (even if it is a bit longer loop).
What do I do wrong ? Somebody can help me ?
Thanks in advance
Christophe
PS: here a simplified implementation of my filter
template<typename Source>
int get(Source& src)
{
//at the very beginning or if the buffer are fully returned
if (fcurrent_pos == fblkLength)
{
fcurrent_pos =0;
FillThem (src); //fill&transform the buffers with the right
number of src.get()
fc=CheckNSolveBufferIsEnd (src); //eventually prepare read
the suffix of the file
}
//The effective return
if (fcurrent_pos < fUntrans.size ())
return (int)fUntrans[fcurrent_pos++];
else
return fc;
}
template<typename Sink>
bool put(Sink& dest, int c)
{
if (c==EOF || c ==boost::iostreams::WOULD_BLOCK)
return false;
if (fUntrans.size () < fblkLength - 1)
{
fUntrans.AddData((char*)(&c),1);
return true;
}
fUntrans.AddData((char*)(&c),1);
fenc->TransformThis (fUntrans, fTrans, fKey);
for (int i=0; i<fblkLength; i++)
{
if (!boost::iostreams::put(dest, (int)fTrans[i]))
return false;
}
return true;
}
template<typename Sink>
bool close (Sink &dest, BOOST_IOS::openmode m)
{
if (fFlushed)
return true;
PrepareSuffix ();
for (int i=0; i< fblkLength*2; //suffix length
i++)
{
if (!boost::iostreams::put(dest, (int)fTrans[i]))
return false;
}
return true;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net