Example #1
0
 internal sZippedFile(TarHeader header, byte[] data)
 {
     _header = header;
     _data = data;
 }
Example #2
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;

                    }
                }
            }
        }
Example #3
0
 internal void AddFile(TarHeader header, byte[] data)
 {
     string prefix = header.Prefix;
     if (prefix != null)
     {
         if ((prefix == _name) || (prefix == ""))
             _files.Add(new ZipFile.sZippedFile(header, data));
         else
         {
             AddFolder(prefix.Substring(prefix.LastIndexOf('/')), prefix.Substring(0, prefix.LastIndexOf('/')));
             string[] split = prefix.Trim('/').Split('/');
             sZippedFolder fold = this;
             int x = 0;
             if (split[x] == _name)
                 x++;
             while (x < split.Length)
             {
                 List<sZippedFolder> folds = fold.Folders;
                 foreach (sZippedFolder szf in folds)
                 {
                     if (szf.Name == split[x])
                     {
                         fold = szf;
                         break;
                     }
                 }
                 x++;
             }
             fold._files.Add(new ZipFile.sZippedFile(header, data));
         }
     }
     else
         _files.Add(new ZipFile.sZippedFile(header, data));
 }