Example #1
0
        private bool IsOpenable(bool needToUncompress, bool needToLoadIntoMemory, out string message)
        {
            message = null;

            if (this._originallyInArchive)
            {
                if (needToUncompress && this.CompressionMethod != ZipArchiveEntry.CompressionMethodValues.Stored && this.CompressionMethod != ZipArchiveEntry.CompressionMethodValues.Deflate)
                {
                    message = CompressionConstants.UnsupportedCompression;
                    return(false);
                }

                if ((long)this._diskNumberStart != (long)this._archive.NumberOfThisDisk)
                {
                    message = CompressionConstants.SplitSpanned;
                    return(false);
                }

                if (this._offsetOfLocalHeader > this._archive.ArchiveStream.Length)
                {
                    message = CompressionConstants.LocalFileHeaderCorrupt;
                    return(false);
                }

                this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader, SeekOrigin.Begin);

                if (!ZipLocalFileHeader.TrySkipBlock(this._archive.ArchiveReader))
                {
                    message = CompressionConstants.LocalFileHeaderCorrupt;
                    return(false);
                }

                if (this.OffsetOfCompressedData + this._compressedSize > this._archive.ArchiveStream.Length)
                {
                    message = CompressionConstants.LocalFileHeaderCorrupt;
                    return(false);
                }

                if (needToLoadIntoMemory && this._compressedSize > (long)int.MaxValue)
                {
                    message = CompressionConstants.EntryTooLarge;
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        internal bool LoadLocalHeaderExtraFieldAndCompressedBytesIfNeeded()
        {
            if (this._originallyInArchive)
            {
                this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader, SeekOrigin.Begin);
                this._lhUnknownExtraFields = ZipLocalFileHeader.GetExtraFields(this._archive.ArchiveReader);
            }

            if (!this._everOpenedForWrite && this._originallyInArchive)
            {
                this._compressedBytes = new byte[this._compressedSize];
                this._archive.ArchiveStream.Seek(this.OffsetOfCompressedData, SeekOrigin.Begin);
                ZipHelper.ReadBytes(this._archive.ArchiveStream, this._compressedBytes, (int)this._compressedSize);
            }

            return(true);
        }