From 8d31e7d78cc7659da784899e82533b48e8a5ae9c Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 9 Feb 2018 08:44:26 +0000 Subject: [PATCH] Core: InFilterStream FilterEof git-svn-id: svn://ultimatepp.org/upp/trunk@11768 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/FilterStream.cpp | 4 +++- uppsrc/Core/FilterStream.h | 1 + uppsrc/Core/src.tpp/InFilterStream_en-us.tpp | 8 +++++++- uppsrc/plugin/bz2/bz2.h | 8 ++++---- uppsrc/plugin/bz2/bz2upp.cpp | 6 ++++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/uppsrc/Core/FilterStream.cpp b/uppsrc/Core/FilterStream.cpp index fbb57a090..df05f0a34 100644 --- a/uppsrc/Core/FilterStream.cpp +++ b/uppsrc/Core/FilterStream.cpp @@ -88,8 +88,10 @@ void InFilterStream::Fetch() End(); eof = true; } - else + else { Filter(~inbuffer, n); + eof = FilterEof(); + } } } Stream::buffer = ptr = buffer.begin(); diff --git a/uppsrc/Core/FilterStream.h b/uppsrc/Core/FilterStream.h index 5dc51ae81..bb926debc 100644 --- a/uppsrc/Core/FilterStream.h +++ b/uppsrc/Core/FilterStream.h @@ -24,6 +24,7 @@ private: public: Stream *in; Event Filter; + Gate<> FilterEof; Event<> End; Gate<> More; void Out(const void *ptr, int size); diff --git a/uppsrc/Core/src.tpp/InFilterStream_en-us.tpp b/uppsrc/Core/src.tpp/InFilterStream_en-us.tpp index 4f993ca45..b588b6fb0 100644 --- a/uppsrc/Core/src.tpp/InFilterStream_en-us.tpp +++ b/uppsrc/Core/src.tpp/InFilterStream_en-us.tpp @@ -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 diff --git a/uppsrc/plugin/bz2/bz2.h b/uppsrc/plugin/bz2/bz2.h index 71ded98e1..dfefc1a75 100644 --- a/uppsrc/plugin/bz2/bz2.h +++ b/uppsrc/plugin/bz2/bz2.h @@ -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(); } }; } diff --git a/uppsrc/plugin/bz2/bz2upp.cpp b/uppsrc/plugin/bz2/bz2upp.cpp index ee7ece67d..72c79cb71 100644 --- a/uppsrc/plugin/bz2/bz2upp.cpp +++ b/uppsrc/plugin/bz2/bz2upp.cpp @@ -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(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)