Monday, 15 June 2015

c++ - zlib inflate stream and avail_in -


The application I'm working on includes part of a compressed data stream in the Zlib format. Piece piece by piece, basically to get the compressed data in regular section, pass it to Flow when more data is available when increases returns Z_STREAM_END We know the complete thing has come

Basic A very simplified version of C ++ inflater function is as follows:

  zero inflater :: inflate_next_chunk (zero * part, std :: size_t size) {m_strm.avail_in = size; M_strm.next_in = Chuck; M_strm.next_out = m_buffer; Int rate = Flow (& m_strm, Z_NO_FLUSH); / * ... check errors, etc ... * /}  

Strangely, in every way ... 40 or many times, fluff fail According to a Z_DATA_ERROR with

Any number of data that can be corrupted in your application can be out of the scope of - but after some rounds around, I realized that the to increase If I m_strm.avail_in was not 0 before I get this size Set to code>. In other words, it seems that inflow is failing because before setting my avail_in already has data in the stream

But my understanding is that inflow should completely empty the input stream of every call, which means that when I call again inflow I do not want to worry if it does not end with the last call. Is my understanding correct? Or let me always see if there is a pending input

Also, why never input Will it remain pending? Why not inflow just consumes all available inputs with each call?

inflow () can come back because he has filled the output buffer , But all input data is not consumed, this will give you a new output buffer and the increases () then m_strm.avail.in == 0 until the need to call If that happens.

This is to say in the zlib manual ...

The detailed semantics are as follows: Flowers perform one or both actions:

Next Decompress more input starting with input and update next_in and avail_in accordingly. Not all input can be processed (because there is not enough space in the production buffer), next_in is updated and processing will start again at this point for the next call () of fluff.

It seems that your compressed input will always fit in your output buffer space, this is not always the case ...

My wrapper code looks like this .. .

  bool CDataInflator :: moving (constant byte * constant pDataIn, DWORD & dataInSize, byte * pDataOut, DWORD & amp; dataOutSize) {if (pDataIn) {if (m_stream.avail_in == 0) {m_stream.avail_in = dataInSize; M_stream.next_in = const_cast & lt; BYTE * const & gt; (Pediatrics); } Other {Sextstation (_T ("CDTinfletter :: Inflight ()"), _T ("No Place for Input Data"); }} M_stream.avail_out = dataOutSize; M_stream.next_out = pDataOut; Bool done = false; Do {Fine Results = Flow (& amp; m_stream, Z_BLOCK); If (result & lt; 0) {ThrowOnFailure (_T ("CDataInflator :: Inflate ()"), results); } Did = (m_stream.avail_in == 0 || (dataautusitis !! = M_stream.will_out & amp; m_stream.val_out! = 0)); } While (! & Amp; m_stream.avail_out == DataAut Size); Data INSize = m_stream.avail_in; DataOutSize = dataOutSize - m_stream.avail_out; Returned; }  

Note that the loop and the fact that the caller depends on dataInSize , to know when the current input data has been used. If the output location is full, then Inflate (0, 0, pNewBuffer, newBufferSize) to provide caller call again buffer; Calls using ...


No comments:

Post a Comment