The files you are trying to create as simply putting a ".zip" suffix will never be a valid zip files despite the stream type(ZipOutput or Stream). If you want to create a zip file I would suggest you to use the ZipLibrary API for creating a zip files(I demonstrated the approach in my first reply in the topic).
As for your question how to access/uncompress a ZipOutputStream, you need to do the following steps:
1) Create a ZipOutputStream
var stream = new MemoryStream();
ZipCompression method = ZipCompression.Deflate64;
var zipOut = new ZipOutputStream(stream, method);
2) Write information to the stream
PdfFormatProvider provider = new PdfFormatProvider();
3) Reset the position of the BaseStream. When we start to read the stream its position will be at the end of the stream that is why we need to reset it.
zipOut.BaseStream.Position = 0;
4) Create a ZipInputStream in order to decompress the information
ZipInputStream inputStream = new ZipInputStream(zipOut.BaseStream);
5) Read the ZipInputStream that we have created.
byte bytes = new byte[zipOut.UncompressedSize];
int numBytesToRead = (int)zipOut.UncompressedSize;
int numBytesRead = 0;
while (numBytesToRead > 0)
int n = inputStream.Read(bytes, numBytesRead, numBytesToRead);
if (n == 0)
numBytesRead += n;
numBytesToRead -= n;
6) Write the information to a pdf file
string zipFilePath = @"C:\Test\Final.pdf";
using (FileStream fsNew = new FileStream(zipFilePath,FileMode.Create, FileAccess.Write))
fsNew.Write(bytes, 0, numBytesRead);
I hope this information helps.
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>