Connect with Expertise | Find Experts, Get Answers, Share Insights

Why does this hang? (zlib.net)

 
Join Date: Jul 2008
Posts: 37
#1: Mar 21 '10
I am using the ZLIB.NET library and trying to decompress a file. I am using the sample code that they provided.
Expand|Select|Wrap|Line Numbers
  1. public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
  2. {
  3.    byte[] buffer = new byte[2000];
  4.    int len;
  5.    while ((len = input.Read(buffer, 0, 2000)) > 0)
  6.    {
  7.         output.Write(buffer, 0, len);    //it hangs here on the last write
  8.     }
  9.     output.Flush();
  10. }
  11.  
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.

✓ answered by dschu012

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.

jkmyoung's Avatar
E
M
C
 
Join Date: Mar 2006
Posts: 1,957
#2: Mar 22 '10

re: Why does this hang? (zlib.net)


Does the input stream have an end of file (EOF) character, or is it still left open?
 
Join Date: Jul 2008
Posts: 37
#3: Mar 22 '10

re: Why does this hang? (zlib.net)


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.
 
Join Date: Jul 2008
Posts: 37
#4: Mar 22 '10

re: Why does this hang? (zlib.net)


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
Expand|Select|Wrap|Line Numbers
  1. System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
  2. zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream);
  3. System.IO.FileStream inFileStream = new System.IO.FileStream(inFile, System.IO.FileMode.Open);
  4.  
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.
jkmyoung's Avatar
E
M
C
 
Join Date: Mar 2006
Posts: 1,957
#5: Mar 22 '10

re: Why does this hang? (zlib.net)


http://msdn.microsoft.com/en-us/libr...ream.read.aspx
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?
 
Join Date: Jul 2008
Posts: 37
#6: Mar 22 '10

re: Why does this hang? (zlib.net)


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.
Reply

Tags
zlib csharp