Пример #1
0
        internal static ZipIOLocalFileHeader CreateNew(string fileName, Encoding encoding, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption, bool streaming)
        {
            byte[] bytes = encoding.GetBytes(fileName);
            if (bytes.Length > ZipIOBlockManager.MaxFileNameSize)
            {
                throw new ArgumentOutOfRangeException("fileName");
            }
            ZipIOLocalFileHeader header = new ZipIOLocalFileHeader();

            header._signature         = 0x4034b50;
            header._compressionMethod = (ushort)compressionMethod;
            if (streaming)
            {
                header._versionNeededToExtract = 0x2d;
            }
            else
            {
                header._versionNeededToExtract = (ushort)ZipIOBlockManager.CalcVersionNeededToExtractFromCompression(compressionMethod);
            }
            if (compressionMethod != CompressionMethodEnum.Stored)
            {
                header.DeflateOption = deflateOption;
            }
            if (streaming)
            {
                header.StreamingCreationFlag = true;
            }
            header._lastModFileDateTime = ZipIOBlockManager.ToMsDosDateTime(DateTime.Now);
            header._fileNameLength      = (ushort)bytes.Length;
            header._fileName            = bytes;
            header._extraField          = ZipIOExtraField.CreateNew(!streaming);
            header._extraFieldLength    = header._extraField.Size;
            header._stringFileName      = fileName;
            return(header);
        }
Пример #2
0
        internal static ZipIOLocalFileHeader ParseRecord(BinaryReader reader, Encoding encoding)
        {
            ZipIOLocalFileHeader header = new ZipIOLocalFileHeader();

            header._signature = reader.ReadUInt32();
            header._versionNeededToExtract = reader.ReadUInt16();
            header._generalPurposeBitFlag  = reader.ReadUInt16();
            header._compressionMethod      = reader.ReadUInt16();
            header._lastModFileDateTime    = reader.ReadUInt32();
            header._crc32            = reader.ReadUInt32();
            header._compressedSize   = reader.ReadUInt32();
            header._uncompressedSize = reader.ReadUInt32();
            header._fileNameLength   = reader.ReadUInt16();
            header._extraFieldLength = reader.ReadUInt16();
            header._fileName         = reader.ReadBytes(header._fileNameLength);
            ZipIOZip64ExtraFieldUsage none = ZipIOZip64ExtraFieldUsage.None;

            if (header._versionNeededToExtract >= 0x2d)
            {
                if (header._compressedSize == uint.MaxValue)
                {
                    none |= ZipIOZip64ExtraFieldUsage.CompressedSize;
                }
                if (header._uncompressedSize == uint.MaxValue)
                {
                    none |= ZipIOZip64ExtraFieldUsage.UncompressedSize;
                }
            }
            header._extraField     = ZipIOExtraField.ParseRecord(reader, none, header._extraFieldLength);
            header._stringFileName = ZipIOBlockManager.ValidateNormalizeFileName(encoding.GetString(header._fileName));
            header.Validate();
            return(header);
        }
Пример #3
0
 private void ParseRecord(BinaryReader reader, string fileName, long position, ZipIOCentralDirectoryBlock centralDir, ZipIOCentralDirectoryFileHeader centralDirFileHeader)
 {
     this.CheckDisposed();
     this._localFileHeader = ZipIOLocalFileHeader.ParseRecord(reader, this._blockManager.Encoding);
     if (this._localFileHeader.StreamingCreationFlag)
     {
         this._blockManager.Stream.Seek(centralDirFileHeader.CompressedSize, SeekOrigin.Current);
         this._localFileDataDescriptor = ZipIOLocalFileDataDescriptor.ParseRecord(reader, centralDirFileHeader.CompressedSize, centralDirFileHeader.UncompressedSize, centralDirFileHeader.Crc32, this._localFileHeader.VersionNeededToExtract);
     }
     else
     {
         this._localFileDataDescriptor = null;
     }
     this._offset         = position;
     this._dirtyFlag      = false;
     this._fileItemStream = new ZipIOFileItemStream(this._blockManager, this, position + this._localFileHeader.Size, centralDirFileHeader.CompressedSize);
     if (this._localFileHeader.CompressionMethod == CompressionMethodEnum.Deflated)
     {
         this._deflateStream        = new CompressStream(this._fileItemStream, centralDirFileHeader.UncompressedSize);
         this._crcCalculatingStream = new ProgressiveCrcCalculatingStream(this._blockManager, this._deflateStream, this.Crc32);
     }
     else
     {
         if (this._localFileHeader.CompressionMethod != CompressionMethodEnum.Stored)
         {
             throw new NotSupportedException(SR.Get("ZipNotSupportedCompressionMethod"));
         }
         this._crcCalculatingStream = new ProgressiveCrcCalculatingStream(this._blockManager, this._fileItemStream, this.Crc32);
     }
     this.Validate(fileName, centralDir, centralDirFileHeader);
 }
Пример #4
0
        internal static ZipIOLocalFileBlock CreateNew(ZipIOBlockManager blockManager, string fileName, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption)
        {
            ZipIOLocalFileBlock block = new ZipIOLocalFileBlock(blockManager, false, false);

            block._localFileHeader = ZipIOLocalFileHeader.CreateNew(fileName, blockManager.Encoding, compressionMethod, deflateOption, blockManager.Streaming);
            if (blockManager.Streaming)
            {
                block._localFileDataDescriptor = ZipIOLocalFileDataDescriptor.CreateNew();
            }
            block._offset         = 0L;
            block._dirtyFlag      = true;
            block._fileItemStream = new ZipIOFileItemStream(blockManager, block, block._offset + block._localFileHeader.Size, 0L);
            if (compressionMethod == CompressionMethodEnum.Deflated)
            {
                block._deflateStream        = new CompressStream(block._fileItemStream, 0L, true);
                block._crcCalculatingStream = new ProgressiveCrcCalculatingStream(blockManager, block._deflateStream);
                return(block);
            }
            block._crcCalculatingStream = new ProgressiveCrcCalculatingStream(blockManager, block._fileItemStream);
            return(block);
        }