Problem reading from compression stram

Aug 19, 2009 at 2:32 PM

I'm trying to read from a compression stream, but I'm getting an exception:

Ionic.Zlib.ZlibException : AvailableBytesOut == 0 && flush<=old_flush && flush != FlushType.Finish

This is the example (sorry for the strange language, but  I think its readable):

LOCAL s := "This is a test file" AS STRING
MemoWrit("test2.txt",s) //write test file
LOCAL oInStream := System.IO.FileStream{"test2.txt", System.IO.FileMode.Open} AS System.IO.FileStream
LOCAL oFileStream := System.IO.FileStream{"test2.zlib",System.IO.FileMode.Create} AS System.IO.FileStream
LOCAL oZStream := Ionic.Zlib.ZlibStream{oInStream, Ionic.Zlib.CompressionMode.Compress} AS Ionic.Zlib.ZlibStream
LOCAL len as INT
LOCAL buffer := byte[]{2000} AS byte[]
 
WHILE (len := oZStream:Read(buffer,0,2000)) > 0 //
    oFileStream:Write(buffer,0,len)
END
oZStream:Close()

It fails in the second iteration of the loop when there is no more data to read. I thought that Read sould return 0 when there was no more data to read. Is there any way to find out that there is no more data to read? Using FlushMode Finish makes it work but that would certainly have penalties for large files? I can't find any example of reading from an compression stream. Since my task is not to write it back to a file (this was just for testing), writing to a compression stream is not an option.

Regards,

Haakon

Coordinator
Aug 19, 2009 at 5:30 PM

Haakon,

yes I get the same problem here. Something is wrong when using ZlibStream in compression, while reading.  This is supposed to work.

If you want to compress, you could do it through writing.  In other words, something like this?

  LOCAL oInStream := System.IO.FileStream{"test2.txt", System.IO.FileMode.Open} AS System.IO.FileStream
  LOCAL oFileStream := System.IO.FileStream{"test2.zlib",System.IO.FileMode.Create} AS System.IO.FileStream
  LOCAL oZStream := Ionic.Zlib.ZlibStream{oFileStream, Ionic.Zlib.CompressionMode.Compress} AS Ionic.Zlib.ZlibStream

  WHILE (len := oInStream:Read(buffer,0,2000)) > 0 //
    oZStream:Write(buffer,0,len)             
  END 
  oZStream:Close()
        

In the meantime I will set about fixing the problem in the library.

Coordinator
Aug 19, 2009 at 5:36 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Aug 20, 2009 at 1:54 AM

ok, it's fixed in v1.8.4.20.