Exemple #1
0
      private void ReadCentralDirectoryData(Stream stream)
      {
          if (stream == null)
              throw new ArgumentNullException("stream");

          while (ReadInt32(stream) == Constants.CentralHeaderSignature)
          {
              ZipArchiveItem item = new ZipArchiveItem();
              item.ReadCentralDirectoryData(stream);
              m_arrItems.Add(item);
          }
      }
Exemple #2
0
      public ZipArchiveItem AddItem(string itemName, Stream data, bool bControlStream, FileAttributes attributes)
      {
          itemName = itemName.Replace('\\', '/');

          if (itemName.IndexOf(':') >= 0)
              throw new ArgumentOutOfRangeException("ZipItem name contains illegal characters.", "itemName");

          if (m_dicItems.Contains(itemName))
              throw new ArgumentOutOfRangeException("Item " + itemName + " already exists in the archive");

          ZipArchiveItem item = new ZipArchiveItem(itemName, data, bControlStream, attributes);
          item.CompressionLevel = m_defaultLevel;
          return AddItem(item);
      }
Exemple #3
0
      public ZipArchiveItem AddItem(ZipArchiveItem item)
      {
          if (item == null)
              throw new ArgumentNullException("item");

          m_arrItems.Add(item);
          m_dicItems.Add(item.ItemName, item);
          return item;
      }
Exemple #4
0
        private void CreateZipFileByTextFile(
            string zipFileName
            )
        {
            _fileStream.Position = 0;

            //doing zip
            using (var zip = new ZipArchive())
            {
                using (var mstream = new MemoryStream())
                {
                    var buffer = new byte[32768];

                    int read;
                    while ((read = _fileStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        mstream.Write(buffer, 0, read);
                    }

                    var zipItem = new ZipArchiveItem(
                        this._fileInformation.Name,
                        mstream,
                        true,
                        FileAttributes.Normal);

                    zip.AddItem(zipItem);

                    zip.Save(zipFileName);
                }
            }
        }