none
SharpZipLib - Unexpected end of archive RRS feed

  • Question

  • Hey, 

    Does anyone know why this code produces errors in the archive file?

    using(FileStream f = File.Create(@"c:\tmp.zip"))
                {
                    using(MemoryStream ms = new MemoryStream())
                    {
                        byte[] b = File.ReadAllBytes("c:\\001.jpg");

                        ZipOutputStream outStream = new ZipOutputStream(ms);
                        outStream.SetLevel(5);
                       
                        ZipEntry entry = new ZipEntry("001.jpg");
                        entry.Size = b.Length;
                        entry.CompressionMethod = CompressionMethod.Deflated;
                        
                        outStream.PutNextEntry(entry);
                        outStream.Write(b, 0, b.Length);
                                                          
                        f.Write(ms.ToArray(), 0, (int)ms.Length);
                        outStream.Finish();                        
                        outStream.Close();

                        ms.Flush();
                    }

                    f.Flush();
               }

    Thanks
    M
    • Moved by Ji.Zhou Thursday, March 18, 2010 6:17 AM (From:Visual C# General)
    Wednesday, March 10, 2010 12:29 AM

Answers

  • And for this issue is at the side of SharpZipLib usage. It is not realted to the C# lanaguage itself. I suggest you post the question in SharpDevelop community for further help,
    http://community.sharpdevelop.net/forums/12.aspx


    Best regards,
    Ji Zhou

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by MJOw Thursday, April 19, 2012 10:04 AM
    Thursday, March 18, 2010 5:43 AM

All replies

  • Looks like a number of things starting with the fact that File.Create creates a zero-length file.

    The SharpZipLib comes with samples. I suggest you check them out.
    Wednesday, March 10, 2010 2:36 AM
  • And for this issue is at the side of SharpZipLib usage. It is not realted to the C# lanaguage itself. I suggest you post the question in SharpDevelop community for further help,
    http://community.sharpdevelop.net/forums/12.aspx


    Best regards,
    Ji Zhou

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by MJOw Thursday, April 19, 2012 10:04 AM
    Thursday, March 18, 2010 5:43 AM
  • Hope this snippet will assist you..

    //Files that exist in isolated storage
                string[] files = new string[6];
                files[0] = "Instrument.txt";
                files[1] = "users.txt";
                files[2] = "Skips.txt";
                files[3] = "Section.txt";
                files[4] = "MetricSystems.txt";

                using (IsolatedStorageFile ZipStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream zippedMemoryStream = new IsolatedStorageFileStream("BackupData.zip", FileMode.Create, ZipStore))
                    {
                        // A memory stream to write to  
                        //using (MemoryStream zippedMemoryStream = new MemoryStream())
                        //{
                            // A ZIP stream  
                            using (ZipOutputStream zipOutputStream = new ZipOutputStream(zippedMemoryStream))
                            {
                                // Highest compression rating  
                                zipOutputStream.SetLevel(9);

                                byte[] buffer;


                                //Files to that exists in isolated storage to be zipped
                                foreach (string file in files)
                                {
                                    using (IsolatedStorageFileStream IsofileStream = new IsolatedStorageFileStream(file, FileMode.Open, ZipStore))
                                    {
                                        buffer = new byte[IsofileStream.Length];
                                        IsofileStream.Read(buffer, 0, buffer.Length);
                                    }

                                    // Write the data to the ZIP file              
                                    ZipEntry entry = new ZipEntry(file);
                                    zipOutputStream.PutNextEntry(entry);
                                    zipOutputStream.Write(buffer, 0, buffer.Length);
                                }

                                // Finish the ZIP file  
                                zipOutputStream.Finish();
                            }
                        //}
                    }
                }

    • Edited by KenSenagi Wednesday, March 21, 2012 8:16 AM
    Wednesday, March 21, 2012 8:14 AM