Example #1
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);
        }
Example #2
0
        internal ZipFileInfo AddFile(string zipFileName, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption)
        {
            this.CheckDisposed();
            if (this._openAccess == FileAccess.Read)
            {
                throw new InvalidOperationException(SR.Get("CanNotWriteInReadOnlyMode"));
            }
            zipFileName = ZipIOBlockManager.ValidateNormalizeFileName(zipFileName);
            if ((compressionMethod != CompressionMethodEnum.Stored) && (compressionMethod != CompressionMethodEnum.Deflated))
            {
                throw new ArgumentOutOfRangeException("compressionMethod");
            }
            if ((deflateOption < DeflateOptionEnum.Normal) || ((deflateOption > DeflateOptionEnum.SuperFast) && (deflateOption != DeflateOptionEnum.None)))
            {
                throw new ArgumentOutOfRangeException("deflateOption");
            }
            if (this.FileExists(zipFileName))
            {
                throw new InvalidOperationException(SR.Get("AttemptedToCreateDuplicateFileName"));
            }
            ZipIOLocalFileBlock fileBlock = this._blockManager.CreateLocalFileBlock(zipFileName, compressionMethod, deflateOption);
            ZipFileInfo         info      = new ZipFileInfo(this, fileBlock);

            this.ZipFileInfoDictionary.Add(info.Name, info);
            return(info);
        }
Example #3
0
 internal void DeleteFile(string zipFileName)
 {
     this.CheckDisposed();
     if (this._openAccess == FileAccess.Read)
     {
         throw new InvalidOperationException(SR.Get("CanNotWriteInReadOnlyMode"));
     }
     zipFileName = ZipIOBlockManager.ValidateNormalizeFileName(zipFileName);
     if (this.FileExists(zipFileName))
     {
         ZipFileInfo file = this.GetFile(zipFileName);
         this.ZipFileInfoDictionary.Remove(zipFileName);
         this._blockManager.RemoveLocalFileBlock(file.LocalFileBlock);
     }
 }
        internal static ZipIOCentralDirectoryFileHeader ParseRecord(BinaryReader reader, Encoding encoding)
        {
            ZipIOCentralDirectoryFileHeader header = new ZipIOCentralDirectoryFileHeader(encoding);

            header._signature              = reader.ReadUInt32();
            header._versionMadeBy          = reader.ReadUInt16();
            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._fileCommentLength           = reader.ReadUInt16();
            header._diskNumberStart             = reader.ReadUInt16();
            header._internalFileAttributes      = reader.ReadUInt16();
            header._externalFileAttributes      = reader.ReadUInt32();
            header._relativeOffsetOfLocalHeader = reader.ReadUInt32();
            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;
                }
                if (header._relativeOffsetOfLocalHeader == uint.MaxValue)
                {
                    none |= ZipIOZip64ExtraFieldUsage.OffsetOfLocalHeader;
                }
                if (header._diskNumberStart == 0xffff)
                {
                    none |= ZipIOZip64ExtraFieldUsage.DiskNumber;
                }
            }
            header._extraField     = ZipIOExtraField.ParseRecord(reader, none, header._extraFieldLength);
            header._fileComment    = reader.ReadBytes(header._fileCommentLength);
            header._stringFileName = ZipIOBlockManager.ValidateNormalizeFileName(encoding.GetString(header._fileName));
            header.Validate();
            return(header);
        }
Example #5
0
        internal ZipFileInfo GetFile(string zipFileName)
        {
            this.CheckDisposed();
            if (this._openAccess == FileAccess.Write)
            {
                throw new InvalidOperationException(SR.Get("CanNotReadInWriteOnlyMode"));
            }
            zipFileName = ZipIOBlockManager.ValidateNormalizeFileName(zipFileName);
            if (this.ZipFileInfoDictionary.Contains(zipFileName))
            {
                return((ZipFileInfo)this.ZipFileInfoDictionary[zipFileName]);
            }
            if (!this.FileExists(zipFileName))
            {
                throw new InvalidOperationException(SR.Get("FileDoesNotExists"));
            }
            ZipIOLocalFileBlock fileBlock = this._blockManager.LoadLocalFileBlock(zipFileName);
            ZipFileInfo         info      = new ZipFileInfo(this, fileBlock);

            this.ZipFileInfoDictionary.Add(info.Name, info);
            return(info);
        }
Example #6
0
 internal bool FileExists(string zipFileName)
 {
     this.CheckDisposed();
     zipFileName = ZipIOBlockManager.ValidateNormalizeFileName(zipFileName);
     return(this._blockManager.CentralDirectoryBlock.FileExists(zipFileName));
 }