Пример #1
0
        public ZipFile(Stream strm, bool read)
        {
            _strm = strm;
            if (!read)
                _bw = new BinaryWriter(new GZipStream(_strm, CompressionMode.Compress, true));
            else
            {
                _br = new BinaryReader(new GZipStream(_strm, CompressionMode.Decompress, true));
                _base = new sZippedFolder("");
                while (true)
                {
                    byte[] bhead = new byte[512];
                    int bread = _br.Read(bhead, 0, 512);
                    if (bread == 0)
                        break;
                    TarHeader head = new TarHeader(bhead);
                    switch (head.TypeFlag)
                    {
                        case TarHeader.EntryTypes.DIRECTORY:
                            _base.AddFolder(head.Name, head.Prefix);
                            break;
                        case TarHeader.EntryTypes.NORMAL:
                            byte[] data = _br.ReadBytes((int)head.Size);
                            int size = 0;
                            while ((data.Length + size) % 512 != 0)
                            {
                                _br.ReadByte();
                                size++;
                            }
                            _base.AddFile(head, data);
                            break;

                    }
                }
            }
        }
Пример #2
0
 internal void AddFolder(string name, string prefix)
 {
     if ((prefix == _name) || (prefix == ""))
         _folders.Add(new sZippedFolder(name));
     else
     {
         string[] split = prefix.Split('/');
         prefix = prefix.Substring(prefix.IndexOf(split[0]));
         prefix = prefix.TrimStart('/');
         bool add = true;
         for (int x = 0; x < _folders.Count; x++)
         {
             if (_folders[x].Name == split[0])
             {
                 add = false;
                 _folders[x].AddFolder(name, prefix);
                 x = _folders.Count;
             }
         }
         if (add)
         {
             sZippedFolder fold = new sZippedFolder(split[0]);
             fold.AddFolder(name, prefix);
             _folders.Add(fold);
         }
     }
 }