SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

I got Inflate to work but Deflate is giving me trouble

Last post 01-29-2010 3:59 PM by FordGT90Concept. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-29-2010 3:19 PM

    I got Inflate to work but Deflate is giving me trouble

    No matter what I set as input, Deflate always returns 2 with the bytes: 120, 1 in the output buffer.  I'm putting in over 20,000 bytes and there's no way that could be deflated into two bytes so something is clearly wrong.


    Before it runs, the values are set to:

    buffer = 25242 bytes of uncompressed data.
    output_buffer = 32768 byte long empty array.

    Deflater deflate = new Deflater(Deflater.BEST_SPEED, false);
    result = 0;
    try
    {
    deflate.SetInput(buffer, 0, buffer.Length);
    result = deflate.Deflate(output_buffer, 0, output_buffer.Length);
    }
    catch { };
    deflate.Finish();

    After it runs:

    result = 2
    output_buffer = length of 32768 containing:
      output_buffer[0] = 120;
      output_buffer[1] = 1;
     
    The rest are 0.

    I can't figure out what I am doin wrong. :(

    Filed under:
  • 01-29-2010 3:27 PM In reply to

    Re: I got Inflate to work but Deflate is giving me trouble

    Why are you ignoring exceptions? Remove that try-catch block so that you can see crashes.

    Also, I think you might have to call Deflate in a loop until it returns 0, similar to streams there isn't any guarantee a single call processes the full input.

  • 01-29-2010 3:46 PM In reply to

    Re: I got Inflate to work but Deflate is giving me trouble

     Thank you for the quick response.

    The second time I call deflate, it returns 0 with no extra data.  IsFinished = false, IsNeedingInput = true.

    No exception is thrown. :(

  • 01-29-2010 3:52 PM In reply to

    Re: I got Inflate to work but Deflate is giving me trouble

    I haven't used Deflater directly myself, that was just a guess based on how the Stream classes in SharpZipLib work. Did you try using the higher-level stream classes? (InflaterInputStream etc.)

    Here's another post about using inflate/deflate directly: http://community.sharpdevelop.net/forums/t/10682.aspx

  • 01-29-2010 3:59 PM In reply to

    Re: I got Inflate to work but Deflate is giving me trouble

     I think it might be working now.  I didn't have the Finish() in the right place before:

    Deflater deflate = new Deflater(Deflater.BEST_SPEED, false);
    result = 0;
    int deflated_length = 0;
    try
    {
    deflate.SetInput(buffer);
    deflate.Finish();// This is IMPORTANT =D
    result = deflate.Deflate(output_buffer);
    }
    catch { };

    Thanks for that link!

Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.