ZipOutputStream does not work as expected

Jul 25, 2012 at 4:48 AM

I am working on windows azure project where i am reading a blob from Windows Azure Storage as a blob stream and wanted to pass it through ZipOutputStream and return the underlying stream to the WCF client (using streaming mode).

I have setup the compression level and compression mode to None as the source files are already compressed and the objective is to just wrap these files with another password protected zip file.

For this I created my own stream class and in the read method of this class, I am reading it from the blob stream and whatever bytes are read, I am writing it back to underlying memory stream using ZipOutputStream.Write method.

For some reasons, internall classes of zip libarary does not honour my zipoutput stream settings (of compression level and compression mode) and tries to use deflate zip algorith (e.g. in ZlibBaseStream.cs _wantCompress appears to be true despite of me setting compression level to none !)

Moreover, ZipOutpuStream.Write does not write any bytes to any underlying stream for the second iteration.

Here is my custom stream implementation of Read method

 

public override int Read(byte[] buffer, int offset, int

count)

{

 

//First read bytes from blob stream

 

byte[] mBuffer = new byte

[count];

 

int

byteCount = _blobStream.Read(mBuffer, offset, count);

 

//if any bytes are read, write it to this stream to get .

 

if

 

 

(byteCount > 0)

{

 

 

//Second time below operation does not write any bytes to the underlying steram !!.

_zos.Write(mBuffer, offset, byteCount);

}

 

 

 

 

 

 

 

_zippedStream.Position = _position;

 

byteCount = _zippedStream.Read(buffer, offset,

Convert

.ToInt32(_zippedStream.Length - _position));

 

Position += byteCount;

 

return

byteCount;

 

}

What is the issue here?

Regards

Badal