Unzipping From ZipPackage

7 posts, 0 answers
  1. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 05 Aug 2011 Link to this post

    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();
            }
  2. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 08 Aug 2011 Link to this post

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

  3. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 08 Aug 2011 Link to this post

    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'
  4. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 08 Aug 2011 Link to this post

    The file that I am trying to zip: http://pastebin.com/eky06ekG.
  5. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 08 Aug 2011 Link to this post

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

  6. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 08 Aug 2011 Link to this post

    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
  7. Viktor Tsvetkov
    Admin
    Viktor Tsvetkov avatar
    382 posts

    Posted 09 Aug 2011 Link to this post

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

Back to Top