コード例 #1
0
 public static MmsFile FromZip(string filename)
 {
     try
     {
         using (FileStream fileStream = File.Open(filename, FileMode.Open, FileAccess.Read))
             return(MmsFile.FromZip(fileStream));
     }
     catch (Exception e)
     {
         throw new MmsException("Failed to load content from file", e);
     }
 }
コード例 #2
0
        public static MmsFile FromZip(Stream stream)
        {
            var file = new MmsFile();

            ZipInputStream zip = new ZipInputStream(stream); // Do NOT dispose, as it will close stream aswell, wich might not be what user wants
            ZipEntry       entry;

            while ((entry = zip.GetNextEntry()) != null)
            {
                string fileName = entry.Name;
                if (fileName != String.Empty)
                {
                    int size = 2048;
                    int len  = 0;
                    using (var mspart = new MemoryStream(size))
                    {
                        byte[] partData = new byte[size];
                        while (true)
                        {
                            size = zip.Read(partData, 0, partData.Length);
                            len += size;
                            if (size > 0)
                            {
                                mspart.Write(partData, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        file.Parts.Add(new MmsPart(mspart.ToArray(), fileName));
                    }
                }
            }
            zip.Close();

            return(file);
        }