This is a migrated thread and some comments may be shown as answers.

Unzipping From ZipPackage

6 Answers 207 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 05 Aug 2011, 06:38 PM
Is there a way to unzip from the ZipPackage? My current routine is incorrect.

Here are my two routines (zip and unzip):
        public static void ZipStream(Stream oInStreamstring sFileNameStream oZipStream)
        {
            ZipPackage oZipPackage = ZipPackage.Create(oZipStream);
            oZipPackage.AddStream(sFileNameoInStream);
        }
 
        public static Stream UnzipStream(Stream oZipStreamint iIndex = 0//this is incorrect; returns zipped stream
        {
            ZipPackage oZipPackage = ZipPackage.Open(oZipStreamFileAccess.Read);
            return oZipPackage.ZipPackageEntries[iIndex].OpenInputStream();
        }

6 Answers, 1 is accepted

Sort by
0
Viktor Tsvetkov
Telerik team
answered on 08 Aug 2011, 12:41 PM
Hi Andrey,

I tried to reproduce your issue but was not able to, so could you please examine the attached sample project and tell me if I am missing something?

Greetings,
Viktor Tsvetkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Andrey
Top achievements
Rank 1
answered on 08 Aug 2011, 02:15 PM
I forgot to mention that my solution worked when I tested it locally, on some text. It failed when I used it on a large xaml file. The file was about 5kb originally. When telerik zipped it, it became ~1.4kb. When I tried unzipping it, using this method, it came out to 1.33kb. The program tried to read the xaml and crashed.

Edit:
[During Zip Process]
Stream to zip: {System.IO.MemoryStream}<br>
    [System.IO.MemoryStream]: {System.IO.MemoryStream}<br>
    CanRead: true<br>
    CanSeek: true<br>
    CanTimeout: false<br>
    CanWrite: true<br>
    Length: 5735<br>
    Position: 0<br>
    ReadTimeout: 'oStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'<br>
    WriteTimeout: 'oStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'

Zip Stream after zip process: {System.IO.MemoryStream}<br>
    [System.IO.MemoryStream]: {System.IO.MemoryStream}<br>
    CanRead: true<br>
    CanSeek: true<br>
    CanTimeout: false<br>
    CanWrite: true<br>
    Length: 1425<br>
    Position: 1425<br>
    ReadTimeout: 'm_oStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'<br>
    WriteTimeout: 'm_oStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'


[During Unzip Process]
Zip stream (before unzipping): {System.IO.MemoryStream}<br>
    [System.IO.MemoryStream]: {System.IO.MemoryStream}<br>
    CanRead: true<br>
    CanSeek: true<br>
    CanTimeout: false<br>
    CanWrite: true<br>
    Length: 1425<br>
    Position: 0<br>
    ReadTimeout: 'm_oDownloadStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'<br>
    WriteTimeout: 'm_oDownloadStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'

Unzipped stream (after unzipping): {Telerik.Windows.Zip.ZipInputStream}<br>
    [Telerik.Windows.Zip.ZipInputStream]: {Telerik.Windows.Zip.ZipInputStream}<br>
    CanRead: true<br>
    CanSeek: false<br>
    CanTimeout: false<br>
    CanWrite: false<br>
    Length: 1313<br>
    Position: 0<br>
    ReadTimeout: 'oStream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'<br>
    WriteTimeout: 'oStream.WriteTimeout' threw an exception of type 'System.InvalidOperationException'
0
Andrey
Top achievements
Rank 1
answered on 08 Aug 2011, 03:36 PM
The file that I am trying to zip: http://pastebin.com/eky06ekG.
0
Viktor Tsvetkov
Telerik team
answered on 08 Aug 2011, 04:50 PM
Hi Andrey,

Could you please send me your sample project that crashes, so I will be able to better assist you?

Greetings,
Viktor Tsvetkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Andrey
Top achievements
Rank 1
answered on 08 Aug 2011, 06:27 PM
Solution: [removed]. The text file in the solution was generated using 

            XElement oRootNode = new XElement("Root");
            oRootNode.Add(m_oDiagramDesigner.GetXmlNode());
            //add a bunch of stuff to root node
            XDocument oDocument = new XDocument(oRootNode);
            oDocument.Save(oStream);

oStream was then saved as the txt file.
The attached solution takes the file generated from this, zips it, then unzips it, and tries to read the "Root" element. It crashes at this point.

Edit: The project I posted first had a bug in it. Here is the fixed one that crashes for the correct reason: http://www.mediafire.com/?l3xd60oevat18ve
0
Viktor Tsvetkov
Telerik team
answered on 09 Aug 2011, 10:06 AM
Hi Andrey,

The problem in your project is not coming from the Telerik zip library, but from the text file that you are trying to load. It needs to be a xml file, because when it is a text file and you read it, the string is filled with unnecessary "\" characters and thus it is no more valid xml format. You can try and simply create a XDocument right after you get the resource stream and you will see that it doesn't work too. What you should do is simply keep your file as a xml file and everything works fine.

Greetings,
Viktor Tsvetkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
ZipLibrary
Asked by
Andrey
Top achievements
Rank 1
Answers by
Viktor Tsvetkov
Telerik team
Andrey
Top achievements
Rank 1
Share this question
or