Example #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);
        }
Example #2
0
 public void UpdateReferences(bool closingFlag)
 {
     Invariant.Assert(!this._blockManager.Streaming);
     this.CheckDisposed();
     if (closingFlag)
     {
         this.CloseExposedStreams();
     }
     else
     {
         this.FlushExposedStreams();
     }
     if (this.GetDirtyFlag(closingFlag))
     {
         long size   = this._localFileHeader.Size;
         long length = this._crcCalculatingStream.Length;
         this._localFileHeader.Crc32 = this._crcCalculatingStream.CalculateCrc();
         if (closingFlag)
         {
             this._crcCalculatingStream.Close();
             if (this._deflateStream != null)
             {
                 this._deflateStream.Close();
             }
         }
         if (this._fileItemStream.DataChanged)
         {
             this._localFileHeader.LastModFileDateTime = ZipIOBlockManager.ToMsDosDateTime(DateTime.Now);
         }
         long compressedSize = this._fileItemStream.Length;
         this._localFileHeader.UpdateZip64Structures(compressedSize, length, this.Offset);
         this._localFileHeader.UpdatePadding(this._localFileHeader.Size - size);
         this._localFileHeader.StreamingCreationFlag = false;
         this._localFileDataDescriptor = null;
         this._fileItemStream.Move((this.Offset + this._localFileHeader.Size) - this._fileItemStream.Offset);
         this._dirtyFlag = true;
     }
 }