Core: InFilterStream FilterEof

git-svn-id: svn://ultimatepp.org/upp/trunk@11768 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-02-09 08:44:26 +00:00
parent ae0c3e65f5
commit 8d31e7d78c
5 changed files with 19 additions and 8 deletions

View file

@ -88,8 +88,10 @@ void InFilterStream::Fetch()
End();
eof = true;
}
else
else {
Filter(~inbuffer, n);
eof = FilterEof();
}
}
}
Stream::buffer = ptr = buffer.begin();

View file

@ -24,6 +24,7 @@ private:
public:
Stream *in;
Event<const void *, int> Filter;
Gate<> FilterEof;
Event<> End;
Gate<> More;
void Out(const void *ptr, int size);

View file

@ -1,5 +1,4 @@
topic "InFilterStream";
[2 $$0,0#00000000000000000000000000000000:Default]
[i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class]
[l288;2 $$2,2#27521748481378242620020725143825:desc]
[0 $$3,0#96390100711032703541132217272105:end]
@ -9,6 +8,7 @@ topic "InFilterStream";
[l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param]
[i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam]
[b42;2 $$9,9#13035079074754324216151401829390:normal]
[2 $$0,0#00000000000000000000000000000000:Default]
[{_}
[ {{10000@(113.42.0) [s0;%% [*@7;4 InFilterStream]]}}&]
[s0;i448;a25;kKO9;@(0.0.255) &]
@ -29,6 +29,12 @@ to be filtered.&]
[s2;%% Callback to filter input function.&]
[s3; &]
[s4; &]
[s5;:Upp`:`:InFilterStream`:`:FilterEof: [_^Upp`:`:Gate^ Gate]<>_[* FilterEof]&]
[s2;%% In some cases, there is a logical end of filtered stream before
the end of `'real`' stream. This Gate serves as signal of such
situation.&]
[s3; &]
[s4; &]
[s5;:InFilterStream`:`:End: [_^Callback^ Callback]_[* End]&]
[s2;%% Callback to filter finalization. This is invoked by InFilterStream
when it reaches the end of input stream. It gives chance to the

View file

@ -75,12 +75,12 @@ namespace bz2 {
Lib z;
public:
void Open(Stream& in) { z.Decompress(); Set(in, z); }
void Open(Stream& in, bool all = true) { z.Decompress(all); Set(in, z); FilterEof = [=]() -> bool { return z.IsEOS(); }; }
Lib& ChunkSize(int n) { return z.ChunkSize(n); }
DecompressStream() {}
DecompressStream(Stream& out) { Open(out); }
~DecompressStream() { Close(); }
DecompressStream() {}
DecompressStream(Stream& out, bool all = true) { Open(out, all); }
~DecompressStream() { Close(); }
};
}

View file

@ -52,7 +52,7 @@ namespace bz2 {
if (mode == INFLATE) {
z.avail_out = chunk;
z.next_out = output;
while (z.avail_in) {
while (z.avail_in && !IsEOS()) {
const int code = BZ2_bzDecompress(&z);
const int count = chunk - z.avail_out;
if(count) {
@ -111,9 +111,10 @@ namespace bz2 {
{
if(error)
return;
// return false;
LLOG("BZLIB Put " << size);
const char *p = reinterpret_cast<const char *>(ptr);
while(size) {
while(size && !IsEOS()) {
int psz = (int) min(size, INT_MAX / 4);
if(mode == DEFLATE)
total += size;
@ -123,6 +124,7 @@ namespace bz2 {
size -= psz;
p += psz;
}
// return !IsEOS();
}
void Lib::PutOut(const void *ptr, int size)