@@ -96,6 +96,7 @@ class DeflaterStream : public std::ostream,
9696 std::unique_ptr<Pimpl> pimpl;
9797
9898 int overflow (int ) override ;
99+ std::streamsize xsputn (const char_type* s, std::streamsize n) override ;
99100};
100101
101102
@@ -120,7 +121,7 @@ struct zlib
120121// I even started trying to improve some of the appalling variable names,
121122// but honestly, life's too short..
122123
123- CHOC_REGISTER_OPEN_SOURCE_LICENCE (QuickJS , R"(
124+ CHOC_REGISTER_OPEN_SOURCE_LICENCE (ZLIB , R"(
124125==============================================================================
125126ZLIB License:
126127
@@ -910,13 +911,15 @@ struct DeflateStream
910911 /* strstart == 0 is possible when wraparound on 16-bit machine */
911912 s->lookahead = (uint32_t ) (s->strstart - max_start);
912913 s->strstart = (uint32_t ) max_start;
913- s->flushBlock (0 );
914+ if (! s->flushBlock (false ))
915+ return BlockStatus::need_more; // Output buffer full, need to flush
914916 }
915917 /* Flush if we may have to slide, otherwise block_start may become
916918 * negative and the data will be gone:
917919 */
918920 if (s->strstart - (uint32_t ) s->block_start >= s->MAX_DIST ())
919- s->flushBlock (0 );
921+ if (! s->flushBlock (false ))
922+ return BlockStatus::need_more; // Output buffer full, need to flush
920923 }
921924 s->flushBlock (flush == FlushState::Z_FINISH);
922925 return flush == FlushState::Z_FINISH ? BlockStatus::finish_done
@@ -1498,14 +1501,15 @@ struct DeflateStream
14981501 last_lit = 0 ;
14991502 }
15001503
1501- void flushBlock (bool eof)
1504+ bool flushBlock (bool eof)
15021505 {
15031506 flushCurrentBlock (block_start >= 0 ? (uint8_t *) &window[(uint32_t ) block_start]
15041507 : (uint8_t *) nullptr ,
15051508 (unsigned long ) ((long ) strstart - block_start),
15061509 eof);
15071510 block_start = (long ) strstart;
15081511 flushPending ();
1512+ return pending == 0 ; // Return true if all data was flushed
15091513 }
15101514
15111515 void initialiseTrees ()
@@ -3808,9 +3812,10 @@ struct InflaterStream::Pimpl
38083812};
38093813
38103814inline InflaterStream::InflaterStream (std::shared_ptr<std::istream> source, FormatType format)
3811- : std::istream (this ),
3815+ : std::istream (nullptr ),
38123816 pimpl (std::make_unique<Pimpl> (std::move (source), format))
38133817{
3818+ rdbuf (this );
38143819}
38153820
38163821inline InflaterStream::~InflaterStream () = default ;
@@ -3981,14 +3986,21 @@ struct DeflaterStream::Pimpl
39813986};
39823987
39833988inline DeflaterStream::DeflaterStream (std::shared_ptr<std::ostream> d, CompressionLevel c, int w)
3984- : std::ostream (this ),
3989+ : std::ostream (nullptr ),
39853990 pimpl (std::make_unique<Pimpl> (std::move (d), c, w))
3986- {}
3991+ {
3992+ rdbuf (this );
3993+ }
39873994
39883995inline DeflaterStream::~DeflaterStream () = default ;
39893996
39903997inline int DeflaterStream::overflow (int c) { return pimpl->overflow (c); }
39913998
3999+ inline std::streamsize DeflaterStream::xsputn (const char_type* s, std::streamsize n)
4000+ {
4001+ return pimpl->write (reinterpret_cast <const uint8_t *> (s),
4002+ static_cast <size_t > (n)) ? n : 0 ;
4003+ }
39924004
39934005} // namespace choc::gzip
39944006
0 commit comments