Why does this hang? (zlib.net)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dschu012
    New Member
    • Jul 2008
    • 39

    Why does this hang? (zlib.net)

    I am using the ZLIB.NET library and trying to decompress a file. I am using the sample code that they provided.
    Code:
    public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
    {
       byte[] buffer = new byte[2000];
       int len;
       while ((len = input.Read(buffer, 0, 2000)) > 0)
       {
            output.Write(buffer, 0, len);    //it hangs here on the last write
        }
        output.Flush();
    }
    The input steam is my compressed zlib file and the output steam is the decompressed file. I am getting the file and it is decompressed fine, however my program just hangs on the last write. It looks like the write gets complete from viewing the file but I am not 100% sure about that. I've have set a breakpoint on output.Flush() and it never gets there.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Does the input stream have an end of file (EOF) character, or is it still left open?

    Comment

    • dschu012
      New Member
      • Jul 2008
      • 39

      #3
      How can I tell? I looked at the file with a hex editor and there were a bunch of null bytes (about 20 0x00 bytes) at the end.

      When compressing the files it doesn't hang at all and calls the same function.

      Comment

      • dschu012
        New Member
        • Jul 2008
        • 39

        #4
        Can't edit the last post. But more investigation made me notice something. The output streams read only methods CanWrite, CanRead, and CanSeek are all false. When on the input stream they are all true. The streams are created like so
        Code:
        System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
        zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream);
        System.IO.FileStream inFileStream = new System.IO.FileStream(inFile, System.IO.FileMode.Open);
        outFileStream can read, write, and seek. But outZStream which is passed to the function can't read, write, seek. But then again I get the decompressed file in the end, but my program hangs.

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

          Under notes:
          The implementation will block until at least one byte of data can be read, in the event that no data is available

          Do you know if you're reading from a file, or standard input? Eg, how is CopyStream called?

          Comment

          • dschu012
            New Member
            • Jul 2008
            • 39

            #6
            Well I just decided to use DotNetZip's Zlib library and everything worked perfectly. Used all of the same code just changing the ZOutput stream to the DotNetZip's implementation. Thanks for trying to help.

            Comment

            Working...