none
Zlib Flush Modes RRS feed

  • Question

  • I am currently trying to replace a slow managed implementation of a ZLib stream with the build in Deflate stream. The protocol I'm implementing forces me to use the Z_SYNC_FLUSH flush mode, but by using dotPeek I noticed that in the internal DeflaterZLib class Microsoft seems to have hardcoded the flush mode to Z_NO_FLUSH:

        int IDeflater.GetDeflateOutput(byte[] outputBuffer)
        {
          try
          {
            int bytesRead;
            int num = (int) this.ReadDeflateOutput(outputBuffer, ZLibNative.FlushCode.NoFlush, out bytesRead);
            return bytesRead;
          }
          finally
          {
            if (this._zlibStream.AvailIn == 0U && this._inputBufferHandle.IsAllocated)
              this.DeallocateInputBufferHandle();
          }
        }

    Is there anyway to change that or to fake a sync flush without having to reimplement  the entire Deflate stream?

    I'm using .Net 4.5.1 btw


    • Edited by Betabot Sunday, October 14, 2018 11:56 AM formatting
    Sunday, October 14, 2018 11:54 AM

Answers

  • It's an internal class and you are referencing private members within that. The stream itself is also creating privately with no options to override. You aren't going to be able to change the implementation.

    Your only real option would be to copy the code and then make the changes you need in your own class. Just be aware that MS may have had a good reason for using that code so test yours very carefully.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Betabot Wednesday, October 17, 2018 9:21 AM
    Monday, October 15, 2018 2:28 PM
    Moderator

All replies

  • It's an internal class and you are referencing private members within that. The stream itself is also creating privately with no options to override. You aren't going to be able to change the implementation.

    Your only real option would be to copy the code and then make the changes you need in your own class. Just be aware that MS may have had a good reason for using that code so test yours very carefully.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Betabot Wednesday, October 17, 2018 9:21 AM
    Monday, October 15, 2018 2:28 PM
    Moderator
  • I ended up just writing a slim wrapper arround clrcompression.dll
    Wednesday, October 17, 2018 9:23 AM