From 8dfc4a2ffba08d14cb512c82d7123140880fbf93 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sun, 6 May 2018 08:59:00 +0100 Subject: [PATCH] more variable naming --- .../Archives/SevenZip/SevenZipArchive.cs | 6 +- src/SharpCompress/Common/ArchiveEncoding.cs | 4 +- src/SharpCompress/Common/GZip/GZipEntry.cs | 10 +- src/SharpCompress/Common/GZip/GZipFilePart.cs | 2 +- src/SharpCompress/Common/IEntry.Extensions.cs | 2 +- .../Common/Rar/Headers/AVHeader.cs | 4 +- .../Common/SevenZip/ArchiveDatabase.cs | 102 +++---- .../Common/SevenZip/ArchiveReader.cs | 250 +++++++++--------- .../Common/SevenZip/CBindPair.cs | 4 +- .../Common/SevenZip/CCoderInfo.cs | 8 +- src/SharpCompress/Common/SevenZip/CFolder.cs | 72 ++--- .../Common/SevenZip/CMethodId.cs | 30 +-- .../Common/SevenZip/SevenZipFilePart.cs | 36 +-- .../Common/Tar/Headers/TarHeader.cs | 32 +-- src/SharpCompress/Common/Tar/TarEntry.cs | 16 +- .../Common/Tar/TarReadOnlySubStream.cs | 12 +- src/SharpCompress/Common/Volume.cs | 14 +- .../Zip/Headers/DirectoryEntryHeader.cs | 2 +- .../Common/Zip/Headers/HeaderFlags.cs | 2 +- .../Common/Zip/Headers/LocalEntryHeader.cs | 2 +- .../Headers/LocalEntryHeaderExtraFactory.cs | 2 +- .../Zip/Headers/Zip64DirectoryEndHeader.cs | 4 +- .../Zip/PkwareTraditionalCryptoStream.cs | 36 +-- .../Zip/PkwareTraditionalEncryptionData.cs | 24 +- .../Common/Zip/StreamingZipFilePart.cs | 18 +- .../Common/Zip/StreamingZipHeaderFactory.cs | 16 +- .../Common/Zip/WinzipAesCryptoStream.cs | 60 ++--- .../Common/Zip/WinzipAesEncryptionData.cs | 30 +-- src/SharpCompress/Common/Zip/ZipEntry.cs | 20 +- .../Common/Zip/ZipHeaderFactory.cs | 36 +-- .../Compressors/Deflate/ZlibBaseStream.cs | 2 +- .../Compressors/Deflate64/Deflate64Stream.cs | 6 +- .../Deflate64/FastEncoderStatus.cs | 52 ++-- .../Compressors/Deflate64/HuffmanTree.cs | 24 +- .../Compressors/Deflate64/InflaterManaged.cs | 50 ++-- .../Compressors/Deflate64/OutputWindow.cs | 42 +-- .../Compressors/LZMA/DecoderStream.cs | 32 +-- .../Compressors/LZMA/Registry.cs | 4 +- src/SharpCompress/Writers/Tar/TarWriter.cs | 2 +- .../Writers/Zip/ZipCentralDirectoryEntry.cs | 2 +- src/SharpCompress/Writers/Zip/ZipWriter.cs | 2 +- 41 files changed, 537 insertions(+), 537 deletions(-) diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index dbc3df8b..9cf64142 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -104,9 +104,9 @@ namespace SharpCompress.Archives.SevenZip { var stream = volumes.Single().Stream; LoadFactory(stream); - for (int i = 0; i < database.Files.Count; i++) + for (int i = 0; i < database._files.Count; i++) { - var file = database.Files[i]; + var file = database._files[i]; yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file, ReaderOptions.ArchiveEncoding)); } } @@ -155,7 +155,7 @@ namespace SharpCompress.Archives.SevenZip get { int i = Entries.Count; - return database.PackSizes.Aggregate(0L, (total, packSize) => total + packSize); + return database._packSizes.Aggregate(0L, (total, packSize) => total + packSize); } } diff --git a/src/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs index a8712115..0b4328e7 100644 --- a/src/SharpCompress/Common/ArchiveEncoding.cs +++ b/src/SharpCompress/Common/ArchiveEncoding.cs @@ -49,8 +49,8 @@ namespace SharpCompress.Common #if NETSTANDARD1_0 return Decode(bytes, 0, bytes.Length); #else - var extendedASCIIEncoding = Encoding.GetEncoding(437); - return extendedASCIIEncoding.GetString(bytes, 0, bytes.Length); + var extendedAsciiEncoding = Encoding.GetEncoding(437); + return extendedAsciiEncoding.GetString(bytes, 0, bytes.Length); #endif } diff --git a/src/SharpCompress/Common/GZip/GZipEntry.cs b/src/SharpCompress/Common/GZip/GZipEntry.cs index 849d4741..0b43cd45 100644 --- a/src/SharpCompress/Common/GZip/GZipEntry.cs +++ b/src/SharpCompress/Common/GZip/GZipEntry.cs @@ -7,24 +7,24 @@ namespace SharpCompress.Common.GZip { public class GZipEntry : Entry { - private readonly GZipFilePart filePart; + private readonly GZipFilePart _filePart; internal GZipEntry(GZipFilePart filePart) { - this.filePart = filePart; + _filePart = filePart; } public override CompressionType CompressionType => CompressionType.GZip; public override long Crc => 0; - public override string Key => filePart.FilePartName; + public override string Key => _filePart.FilePartName; public override long CompressedSize => 0; public override long Size => 0; - public override DateTime? LastModifiedTime => filePart.DateModified; + public override DateTime? LastModifiedTime => _filePart.DateModified; public override DateTime? CreatedTime => null; @@ -38,7 +38,7 @@ namespace SharpCompress.Common.GZip public override bool IsSplitAfter => false; - internal override IEnumerable Parts => filePart.AsEnumerable(); + internal override IEnumerable Parts => _filePart.AsEnumerable(); internal static IEnumerable GetEntries(Stream stream, OptionsBase options) { diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs index 5859a242..1f942e74 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs @@ -61,7 +61,7 @@ namespace SharpCompress.Common.GZip } Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4); - DateModified = TarHeader.Epoch.AddSeconds(timet); + DateModified = TarHeader.EPOCH.AddSeconds(timet); if ((header[3] & 0x04) == 0x04) { // read and discard extra field diff --git a/src/SharpCompress/Common/IEntry.Extensions.cs b/src/SharpCompress/Common/IEntry.Extensions.cs index 70a634ac..76d75a8f 100644 --- a/src/SharpCompress/Common/IEntry.Extensions.cs +++ b/src/SharpCompress/Common/IEntry.Extensions.cs @@ -5,7 +5,7 @@ using SharpCompress.Readers; namespace SharpCompress.Common { - internal static class IEntryExtensions + internal static class EntryExtensions { internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName, ExtractionOptions options) diff --git a/src/SharpCompress/Common/Rar/Headers/AVHeader.cs b/src/SharpCompress/Common/Rar/Headers/AVHeader.cs index 4b521ca8..51dda2cf 100644 --- a/src/SharpCompress/Common/Rar/Headers/AVHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/AVHeader.cs @@ -2,9 +2,9 @@ namespace SharpCompress.Common.Rar.Headers { - internal class AVHeader : RarHeader + internal class AvHeader : RarHeader { - public AVHeader(RarHeader header, RarCrcBinaryReader reader) + public AvHeader(RarHeader header, RarCrcBinaryReader reader) : base(header, reader, HeaderType.Av) { if (IsRar5) diff --git a/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs b/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs index c6da3cda..e827eb20 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs @@ -8,20 +8,20 @@ namespace SharpCompress.Common.SevenZip { internal class ArchiveDatabase { - internal byte MajorVersion; - internal byte MinorVersion; - internal long StartPositionAfterHeader; - internal long DataStartPosition; + internal byte _majorVersion; + internal byte _minorVersion; + internal long _startPositionAfterHeader; + internal long _dataStartPosition; - internal List PackSizes = new List(); - internal List PackCRCs = new List(); - internal List Folders = new List(); - internal List NumUnpackStreamsVector; - internal List Files = new List(); + internal List _packSizes = new List(); + internal List _packCrCs = new List(); + internal List _folders = new List(); + internal List _numUnpackStreamsVector; + internal List _files = new List(); - internal List PackStreamStartPositions = new List(); - internal List FolderStartFileIndex = new List(); - internal List FileIndexToFolderIndexMap = new List(); + internal List _packStreamStartPositions = new List(); + internal List _folderStartFileIndex = new List(); + internal List _fileIndexToFolderIndexMap = new List(); internal IPasswordProvider PasswordProvider { get; } @@ -32,54 +32,54 @@ namespace SharpCompress.Common.SevenZip internal void Clear() { - PackSizes.Clear(); - PackCRCs.Clear(); - Folders.Clear(); - NumUnpackStreamsVector = null; - Files.Clear(); + _packSizes.Clear(); + _packCrCs.Clear(); + _folders.Clear(); + _numUnpackStreamsVector = null; + _files.Clear(); - PackStreamStartPositions.Clear(); - FolderStartFileIndex.Clear(); - FileIndexToFolderIndexMap.Clear(); + _packStreamStartPositions.Clear(); + _folderStartFileIndex.Clear(); + _fileIndexToFolderIndexMap.Clear(); } internal bool IsEmpty() { - return PackSizes.Count == 0 - && PackCRCs.Count == 0 - && Folders.Count == 0 - && NumUnpackStreamsVector.Count == 0 - && Files.Count == 0; + return _packSizes.Count == 0 + && _packCrCs.Count == 0 + && _folders.Count == 0 + && _numUnpackStreamsVector.Count == 0 + && _files.Count == 0; } private void FillStartPos() { - PackStreamStartPositions.Clear(); + _packStreamStartPositions.Clear(); long startPos = 0; - for (int i = 0; i < PackSizes.Count; i++) + for (int i = 0; i < _packSizes.Count; i++) { - PackStreamStartPositions.Add(startPos); - startPos += PackSizes[i]; + _packStreamStartPositions.Add(startPos); + startPos += _packSizes[i]; } } private void FillFolderStartFileIndex() { - FolderStartFileIndex.Clear(); - FileIndexToFolderIndexMap.Clear(); + _folderStartFileIndex.Clear(); + _fileIndexToFolderIndexMap.Clear(); int folderIndex = 0; int indexInFolder = 0; - for (int i = 0; i < Files.Count; i++) + for (int i = 0; i < _files.Count; i++) { - CFileItem file = Files[i]; + CFileItem file = _files[i]; bool emptyStream = !file.HasStream; if (emptyStream && indexInFolder == 0) { - FileIndexToFolderIndexMap.Add(-1); + _fileIndexToFolderIndexMap.Add(-1); continue; } @@ -89,14 +89,14 @@ namespace SharpCompress.Common.SevenZip // v4.07: Loop for skipping empty folders for (;;) { - if (folderIndex >= Folders.Count) + if (folderIndex >= _folders.Count) { throw new InvalidOperationException(); } - FolderStartFileIndex.Add(i); // check it + _folderStartFileIndex.Add(i); // check it - if (NumUnpackStreamsVector[folderIndex] != 0) + if (_numUnpackStreamsVector[folderIndex] != 0) { break; } @@ -105,7 +105,7 @@ namespace SharpCompress.Common.SevenZip } } - FileIndexToFolderIndexMap.Add(folderIndex); + _fileIndexToFolderIndexMap.Add(folderIndex); if (emptyStream) { @@ -114,7 +114,7 @@ namespace SharpCompress.Common.SevenZip indexInFolder++; - if (indexInFolder >= NumUnpackStreamsVector[folderIndex]) + if (indexInFolder >= _numUnpackStreamsVector[folderIndex]) { folderIndex++; indexInFolder = 0; @@ -130,19 +130,19 @@ namespace SharpCompress.Common.SevenZip internal long GetFolderStreamPos(CFolder folder, int indexInFolder) { - int index = folder.FirstPackStreamId + indexInFolder; - return DataStartPosition + PackStreamStartPositions[index]; + int index = folder._firstPackStreamId + indexInFolder; + return _dataStartPosition + _packStreamStartPositions[index]; } internal long GetFolderFullPackSize(int folderIndex) { - int packStreamIndex = Folders[folderIndex].FirstPackStreamId; - CFolder folder = Folders[folderIndex]; + int packStreamIndex = _folders[folderIndex]._firstPackStreamId; + CFolder folder = _folders[folderIndex]; long size = 0; - for (int i = 0; i < folder.PackStreams.Count; i++) + for (int i = 0; i < folder._packStreams.Count; i++) { - size += PackSizes[packStreamIndex + i]; + size += _packSizes[packStreamIndex + i]; } return size; @@ -150,12 +150,12 @@ namespace SharpCompress.Common.SevenZip internal Stream GetFolderStream(Stream stream, CFolder folder, IPasswordProvider pw) { - int packStreamIndex = folder.FirstPackStreamId; + int packStreamIndex = folder._firstPackStreamId; long folderStartPackPos = GetFolderStreamPos(folder, 0); List packSizes = new List(); - for (int j = 0; j < folder.PackStreams.Count; j++) + for (int j = 0; j < folder._packStreams.Count; j++) { - packSizes.Add(PackSizes[packStreamIndex + j]); + packSizes.Add(_packSizes[packStreamIndex + j]); } return DecoderStreamHelper.CreateDecoderStream(stream, folderStartPackPos, packSizes.ToArray(), folder, pw); @@ -163,15 +163,15 @@ namespace SharpCompress.Common.SevenZip private long GetFolderPackStreamSize(int folderIndex, int streamIndex) { - return PackSizes[Folders[folderIndex].FirstPackStreamId + streamIndex]; + return _packSizes[_folders[folderIndex]._firstPackStreamId + streamIndex]; } private long GetFilePackSize(int fileIndex) { - int folderIndex = FileIndexToFolderIndexMap[fileIndex]; + int folderIndex = _fileIndexToFolderIndexMap[fileIndex]; if (folderIndex != -1) { - if (FolderStartFileIndex[folderIndex] == fileIndex) + if (_folderStartFileIndex[folderIndex] == fileIndex) { return GetFolderFullPackSize(folderIndex); } diff --git a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs index 2041fd3f..2093a831 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs @@ -230,7 +230,7 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.WriteLine("NumCoders: " + numCoders); #endif - folder.Coders = new List(numCoders); + folder._coders = new List(numCoders); int numInStreams = 0; int numOutStreams = 0; for (int i = 0; i < numCoders; i++) @@ -242,14 +242,14 @@ namespace SharpCompress.Common.SevenZip try { CCoderInfo coder = new CCoderInfo(); - folder.Coders.Add(coder); + folder._coders.Add(coder); byte mainByte = ReadByte(); int idSize = (mainByte & 0xF); - byte[] longID = new byte[idSize]; - ReadBytes(longID, 0, idSize); + byte[] longId = new byte[idSize]; + ReadBytes(longId, 0, idSize); #if DEBUG - Log.WriteLine("MethodId: " + String.Join("", Enumerable.Range(0, idSize).Select(x => longID[x].ToString("x2")).ToArray())); + Log.WriteLine("MethodId: " + String.Join("", Enumerable.Range(0, idSize).Select(x => longId[x].ToString("x2")).ToArray())); #endif if (idSize > 8) { @@ -258,16 +258,16 @@ namespace SharpCompress.Common.SevenZip ulong id = 0; for (int j = 0; j < idSize; j++) { - id |= (ulong)longID[idSize - 1 - j] << (8 * j); + id |= (ulong)longId[idSize - 1 - j] << (8 * j); } - coder.MethodId = new CMethodId(id); + coder._methodId = new CMethodId(id); if ((mainByte & 0x10) != 0) { - coder.NumInStreams = ReadNum(); - coder.NumOutStreams = ReadNum(); + coder._numInStreams = ReadNum(); + coder._numOutStreams = ReadNum(); #if DEBUG - Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams + ")"); + Log.WriteLine("Complex Stream (In: " + coder._numInStreams + " - Out: " + coder._numOutStreams + ")"); #endif } else @@ -275,17 +275,17 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.WriteLine("Simple Stream (In: 1 - Out: 1)"); #endif - coder.NumInStreams = 1; - coder.NumOutStreams = 1; + coder._numInStreams = 1; + coder._numOutStreams = 1; } if ((mainByte & 0x20) != 0) { int propsSize = ReadNum(); - coder.Props = new byte[propsSize]; - ReadBytes(coder.Props, 0, propsSize); + coder._props = new byte[propsSize]; + ReadBytes(coder._props, 0, propsSize); #if DEBUG - Log.WriteLine("Settings: " + String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray())); + Log.WriteLine("Settings: " + String.Join("", coder._props.Select(bt => bt.ToString("x2")).ToArray())); #endif } @@ -294,8 +294,8 @@ namespace SharpCompress.Common.SevenZip throw new NotSupportedException(); } - numInStreams += coder.NumInStreams; - numOutStreams += coder.NumOutStreams; + numInStreams += coder._numInStreams; + numOutStreams += coder._numOutStreams; } finally { @@ -306,7 +306,7 @@ namespace SharpCompress.Common.SevenZip } int numBindPairs = numOutStreams - 1; - folder.BindPairs = new List(numBindPairs); + folder._bindPairs = new List(numBindPairs); #if DEBUG Log.WriteLine("BindPairs: " + numBindPairs); Log.PushIndent(); @@ -314,11 +314,11 @@ namespace SharpCompress.Common.SevenZip for (int i = 0; i < numBindPairs; i++) { CBindPair bp = new CBindPair(); - bp.InIndex = ReadNum(); - bp.OutIndex = ReadNum(); - folder.BindPairs.Add(bp); + bp._inIndex = ReadNum(); + bp._outIndex = ReadNum(); + folder._bindPairs.Add(bp); #if DEBUG - Log.WriteLine("#" + i + " - In: " + bp.InIndex + " - Out: " + bp.OutIndex); + Log.WriteLine("#" + i + " - In: " + bp._inIndex + " - Out: " + bp._outIndex); #endif } #if DEBUG @@ -342,12 +342,12 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.WriteLine("Single PackStream: #" + i); #endif - folder.PackStreams.Add(i); + folder._packStreams.Add(i); break; } } - if (folder.PackStreams.Count != 1) + if (folder._packStreams.Count != 1) { throw new NotSupportedException(); } @@ -364,7 +364,7 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.WriteLine("#" + i + " - " + num); #endif - folder.PackStreams.Add(num); + folder._packStreams.Add(num); } #if DEBUG Log.PopIndent(); @@ -412,7 +412,7 @@ namespace SharpCompress.Common.SevenZip return digests; } - private void ReadPackInfo(out long dataOffset, out List packSizes, out List packCRCs) + private void ReadPackInfo(out long dataOffset, out List packSizes, out List packCrCs) { #if DEBUG Log.WriteLine("-- ReadPackInfo --"); @@ -420,7 +420,7 @@ namespace SharpCompress.Common.SevenZip #endif try { - packCRCs = null; + packCrCs = null; dataOffset = checked((long)ReadNumber()); #if DEBUG @@ -459,18 +459,18 @@ namespace SharpCompress.Common.SevenZip } if (type == BlockType.Crc) { - packCRCs = ReadHashDigests(numPackStreams); + packCrCs = ReadHashDigests(numPackStreams); continue; } SkipData(); } - if (packCRCs == null) + if (packCrCs == null) { - packCRCs = new List(numPackStreams); + packCrCs = new List(numPackStreams); for (int i = 0; i < numPackStreams; i++) { - packCRCs.Add(null); + packCrCs.Add(null); } } } @@ -506,10 +506,10 @@ namespace SharpCompress.Common.SevenZip int index = 0; for (int i = 0; i < numFolders; i++) { - var f = new CFolder {FirstPackStreamId = index}; + var f = new CFolder {_firstPackStreamId = index}; folders.Add(f); GetNextFolderItem(f); - index += f.PackStreams.Count; + index += f._packStreams.Count; } } @@ -530,7 +530,7 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write(" " + size); #endif - folder.UnpackSizes.Add(size); + folder._unpackSizes.Add(size); } #if DEBUG Log.WriteLine(); @@ -550,7 +550,7 @@ namespace SharpCompress.Common.SevenZip List crcs = ReadHashDigests(numFolders); for (int i = 0; i < numFolders; i++) { - folders[i].UnpackCRC = crcs[i]; + folders[i]._unpackCrc = crcs[i]; } continue; } @@ -661,7 +661,7 @@ namespace SharpCompress.Common.SevenZip for (int i = 0; i < folders.Count; i++) { int numSubstreams = numUnpackStreamsInFolders[i]; - if (numSubstreams != 1 || !folders[i].UnpackCRCDefined) + if (numSubstreams != 1 || !folders[i].UnpackCrcDefined) { numDigests += numSubstreams; } @@ -683,9 +683,9 @@ namespace SharpCompress.Common.SevenZip { int numSubstreams = numUnpackStreamsInFolders[i]; CFolder folder = folders[i]; - if (numSubstreams == 1 && folder.UnpackCRCDefined) + if (numSubstreams == 1 && folder.UnpackCrcDefined) { - digests.Add(folder.UnpackCRC.Value); + digests.Add(folder._unpackCrc.Value); } else { @@ -733,7 +733,7 @@ namespace SharpCompress.Common.SevenZip List dataVector, out long dataOffset, out List packSizes, - out List packCRCs, + out List packCrCs, out List folders, out List numUnpackStreamsInFolders, out List unpackSizes, @@ -747,7 +747,7 @@ namespace SharpCompress.Common.SevenZip { dataOffset = long.MinValue; packSizes = null; - packCRCs = null; + packCrCs = null; folders = null; numUnpackStreamsInFolders = null; unpackSizes = null; @@ -760,7 +760,7 @@ namespace SharpCompress.Common.SevenZip case BlockType.End: return; case BlockType.PackInfo: - ReadPackInfo(out dataOffset, out packSizes, out packCRCs); + ReadPackInfo(out dataOffset, out packSizes, out packCrCs); break; case BlockType.UnpackInfo: ReadUnpackInfo(dataVector, out folders); @@ -791,7 +791,7 @@ namespace SharpCompress.Common.SevenZip { long dataStartPos; List packSizes; - List packCRCs; + List packCrCs; List folders; List numUnpackStreamsInFolders; List unpackSizes; @@ -800,7 +800,7 @@ namespace SharpCompress.Common.SevenZip ReadStreamsInfo(null, out dataStartPos, out packSizes, - out packCRCs, + out packCrCs, out folders, out numUnpackStreamsInFolders, out unpackSizes, @@ -813,7 +813,7 @@ namespace SharpCompress.Common.SevenZip foreach (var folder in folders) { long oldDataStartPos = dataStartPos; - long[] myPackSizes = new long[folder.PackStreams.Count]; + long[] myPackSizes = new long[folder._packStreams.Count]; for (int i = 0; i < myPackSizes.Length; i++) { long packSize = packSizes[packIndex + i]; @@ -833,9 +833,9 @@ namespace SharpCompress.Common.SevenZip } dataVector.Add(data); - if (folder.UnpackCRCDefined) + if (folder.UnpackCrcDefined) { - if (Crc.Finish(Crc.Update(Crc.INIT_CRC, data, 0, unpackSize)) != folder.UnpackCRC) + if (Crc.Finish(Crc.Update(Crc.INIT_CRC, data, 0, unpackSize)) != folder._unpackCrc) { throw new InvalidOperationException("Decoded stream does not match expected CRC."); } @@ -870,7 +870,7 @@ namespace SharpCompress.Common.SevenZip List dataVector = null; if (type == BlockType.AdditionalStreamsInfo) { - dataVector = ReadAndDecodePackedStreams(db.StartPositionAfterHeader, getTextPassword); + dataVector = ReadAndDecodePackedStreams(db._startPositionAfterHeader, getTextPassword); type = ReadId(); } @@ -880,32 +880,32 @@ namespace SharpCompress.Common.SevenZip if (type == BlockType.MainStreamsInfo) { ReadStreamsInfo(dataVector, - out db.DataStartPosition, - out db.PackSizes, - out db.PackCRCs, - out db.Folders, - out db.NumUnpackStreamsVector, + out db._dataStartPosition, + out db._packSizes, + out db._packCrCs, + out db._folders, + out db._numUnpackStreamsVector, out unpackSizes, out digests); - db.DataStartPosition += db.StartPositionAfterHeader; + db._dataStartPosition += db._startPositionAfterHeader; type = ReadId(); } else { - unpackSizes = new List(db.Folders.Count); - digests = new List(db.Folders.Count); - db.NumUnpackStreamsVector = new List(db.Folders.Count); - for (int i = 0; i < db.Folders.Count; i++) + unpackSizes = new List(db._folders.Count); + digests = new List(db._folders.Count); + db._numUnpackStreamsVector = new List(db._folders.Count); + for (int i = 0; i < db._folders.Count; i++) { - var folder = db.Folders[i]; + var folder = db._folders[i]; unpackSizes.Add(folder.GetUnpackSize()); - digests.Add(folder.UnpackCRC); - db.NumUnpackStreamsVector.Add(1); + digests.Add(folder._unpackCrc); + db._numUnpackStreamsVector.Add(1); } } - db.Files.Clear(); + db._files.Clear(); if (type == BlockType.End) { @@ -921,10 +921,10 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.WriteLine("NumFiles: " + numFiles); #endif - db.Files = new List(numFiles); + db._files = new List(numFiles); for (int i = 0; i < numFiles; i++) { - db.Files.Add(new CFileItem()); + db._files.Add(new CFileItem()); } BitVector emptyStreamVector = new BitVector(numFiles); @@ -951,11 +951,11 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write("FileNames:"); #endif - for (int i = 0; i < db.Files.Count; i++) + for (int i = 0; i < db._files.Count; i++) { - db.Files[i].Name = _currentReader.ReadString(); + db._files[i].Name = _currentReader.ReadString(); #if DEBUG - Log.Write(" " + db.Files[i].Name); + Log.Write(" " + db._files[i].Name); #endif } #if DEBUG @@ -991,7 +991,7 @@ namespace SharpCompress.Common.SevenZip attr = attr.Value & 0x7FFFu; } - db.Files[i].Attrib = attr; + db._files[i].Attrib = attr; #if DEBUG Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a")); #endif @@ -1057,7 +1057,7 @@ namespace SharpCompress.Common.SevenZip #endif ReadNumberVector(dataVector, numFiles, delegate(int i, long? startPos) { - db.Files[i].StartPos = startPos; + db._files[i].StartPos = startPos; #if DEBUG Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a")); #endif @@ -1072,7 +1072,7 @@ namespace SharpCompress.Common.SevenZip #endif ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time) { - db.Files[i].CTime = time; + db._files[i].CTime = time; #if DEBUG Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); #endif @@ -1087,7 +1087,7 @@ namespace SharpCompress.Common.SevenZip #endif ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time) { - db.Files[i].ATime = time; + db._files[i].ATime = time; #if DEBUG Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); #endif @@ -1102,7 +1102,7 @@ namespace SharpCompress.Common.SevenZip #endif ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time) { - db.Files[i].MTime = time; + db._files[i].MTime = time; #if DEBUG Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); #endif @@ -1129,7 +1129,7 @@ namespace SharpCompress.Common.SevenZip } // since 0.3 record sizes must be correct - bool checkRecordsSize = (db.MajorVersion > 0 || db.MinorVersion > 2); + bool checkRecordsSize = (db._majorVersion > 0 || db._minorVersion > 2); if (checkRecordsSize && _currentReader.Offset - oldPos != size) { throw new InvalidOperationException(); @@ -1140,7 +1140,7 @@ namespace SharpCompress.Common.SevenZip int sizeIndex = 0; for (int i = 0; i < numFiles; i++) { - CFileItem file = db.Files[i]; + CFileItem file = db._files[i]; file.HasStream = !emptyStreamVector[i]; if (file.HasStream) { @@ -1214,10 +1214,10 @@ namespace SharpCompress.Common.SevenZip var db = new ArchiveDatabase(pass); db.Clear(); - db.MajorVersion = _header[6]; - db.MinorVersion = _header[7]; + db._majorVersion = _header[6]; + db._minorVersion = _header[7]; - if (db.MajorVersion != 0) + if (db._majorVersion != 0) { throw new InvalidOperationException(); } @@ -1238,7 +1238,7 @@ namespace SharpCompress.Common.SevenZip throw new InvalidOperationException(); } - db.StartPositionAfterHeader = _streamOrigin + 0x20; + db._startPositionAfterHeader = _streamOrigin + 0x20; // empty header is ok if (nextHeaderSize == 0) @@ -1252,7 +1252,7 @@ namespace SharpCompress.Common.SevenZip throw new InvalidOperationException(); } - if (nextHeaderOffset > _streamEnding - db.StartPositionAfterHeader) + if (nextHeaderOffset > _streamEnding - db._startPositionAfterHeader) { throw new IndexOutOfRangeException(); } @@ -1279,7 +1279,7 @@ namespace SharpCompress.Common.SevenZip throw new InvalidOperationException(); } - var dataVector = ReadAndDecodePackedStreams(db.StartPositionAfterHeader, db.PasswordProvider); + var dataVector = ReadAndDecodePackedStreams(db._startPositionAfterHeader, db.PasswordProvider); // compressed header without content is odd but ok if (dataVector.Count == 0) @@ -1309,17 +1309,17 @@ namespace SharpCompress.Common.SevenZip internal class CExtractFolderInfo { - internal int FileIndex; - internal int FolderIndex; - internal List ExtractStatuses = new List(); + internal int _fileIndex; + internal int _folderIndex; + internal List _extractStatuses = new List(); internal CExtractFolderInfo(int fileIndex, int folderIndex) { - FileIndex = fileIndex; - FolderIndex = folderIndex; + _fileIndex = fileIndex; + _folderIndex = folderIndex; if (fileIndex != -1) { - ExtractStatuses.Add(true); + _extractStatuses.Add(true); } } } @@ -1375,7 +1375,7 @@ namespace SharpCompress.Common.SevenZip private void ProcessEmptyFiles() { - while (_currentIndex < _extractStatuses.Count && _db.Files[_startIndex + _currentIndex].Size == 0) + while (_currentIndex < _extractStatuses.Count && _db._files[_startIndex + _currentIndex].Size == 0) { OpenFile(); _stream.Dispose(); @@ -1388,17 +1388,17 @@ namespace SharpCompress.Common.SevenZip { int index = _startIndex + _currentIndex; #if DEBUG - Log.WriteLine(_db.Files[index].Name); + Log.WriteLine(_db._files[index].Name); #endif - if (_db.Files[index].CrcDefined) + if (_db._files[index].CrcDefined) { - _stream = new CrcCheckStream(_db.Files[index].Crc.Value); + _stream = new CrcCheckStream(_db._files[index].Crc.Value); } else { _stream = new MemoryStream(); } - _rem = _db.Files[index].Size; + _rem = _db._files[index].Size; } public override void Write(byte[] buffer, int offset, int count) @@ -1441,32 +1441,32 @@ namespace SharpCompress.Common.SevenZip #endregion } - private Stream GetCachedDecoderStream(ArchiveDatabase _db, int folderIndex) + private Stream GetCachedDecoderStream(ArchiveDatabase db, int folderIndex) { Stream s; if (!_cachedStreams.TryGetValue(folderIndex, out s)) { - CFolder folderInfo = _db.Folders[folderIndex]; - int packStreamIndex = _db.Folders[folderIndex].FirstPackStreamId; - long folderStartPackPos = _db.GetFolderStreamPos(folderInfo, 0); + CFolder folderInfo = db._folders[folderIndex]; + int packStreamIndex = db._folders[folderIndex]._firstPackStreamId; + long folderStartPackPos = db.GetFolderStreamPos(folderInfo, 0); List packSizes = new List(); - for (int j = 0; j < folderInfo.PackStreams.Count; j++) + for (int j = 0; j < folderInfo._packStreams.Count; j++) { - packSizes.Add(_db.PackSizes[packStreamIndex + j]); + packSizes.Add(db._packSizes[packStreamIndex + j]); } s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), folderInfo, - _db.PasswordProvider); + db.PasswordProvider); _cachedStreams.Add(folderIndex, s); } return s; } - public Stream OpenStream(ArchiveDatabase _db, int fileIndex) + public Stream OpenStream(ArchiveDatabase db, int fileIndex) { - int folderIndex = _db.FileIndexToFolderIndexMap[fileIndex]; - int numFilesInFolder = _db.NumUnpackStreamsVector[folderIndex]; - int firstFileIndex = _db.FolderStartFileIndex[folderIndex]; + int folderIndex = db._fileIndexToFolderIndexMap[fileIndex]; + int numFilesInFolder = db._numUnpackStreamsVector[folderIndex]; + int firstFileIndex = db._folderStartFileIndex[folderIndex]; if (firstFileIndex > fileIndex || fileIndex - firstFileIndex >= numFilesInFolder) { throw new InvalidOperationException(); @@ -1476,21 +1476,21 @@ namespace SharpCompress.Common.SevenZip long skipSize = 0; for (int i = 0; i < skipCount; i++) { - skipSize += _db.Files[firstFileIndex + i].Size; + skipSize += db._files[firstFileIndex + i].Size; } - Stream s = GetCachedDecoderStream(_db, folderIndex); + Stream s = GetCachedDecoderStream(db, folderIndex); s.Position = skipSize; - return new ReadOnlySubStream(s, _db.Files[fileIndex].Size); + return new ReadOnlySubStream(s, db._files[fileIndex].Size); } - public void Extract(ArchiveDatabase _db, int[] indices) + public void Extract(ArchiveDatabase db, int[] indices) { int numItems; bool allFilesMode = (indices == null); if (allFilesMode) { - numItems = _db.Files.Count; + numItems = db._files.Count; } else { @@ -1507,62 +1507,62 @@ namespace SharpCompress.Common.SevenZip { int fileIndex = allFilesMode ? i : indices[i]; - int folderIndex = _db.FileIndexToFolderIndexMap[fileIndex]; + int folderIndex = db._fileIndexToFolderIndexMap[fileIndex]; if (folderIndex == -1) { extractFolderInfoVector.Add(new CExtractFolderInfo(fileIndex, -1)); continue; } - if (extractFolderInfoVector.Count == 0 || folderIndex != extractFolderInfoVector.Last().FolderIndex) + if (extractFolderInfoVector.Count == 0 || folderIndex != extractFolderInfoVector.Last()._folderIndex) { extractFolderInfoVector.Add(new CExtractFolderInfo(-1, folderIndex)); } CExtractFolderInfo efi = extractFolderInfoVector.Last(); - int startIndex = _db.FolderStartFileIndex[folderIndex]; - for (int index = efi.ExtractStatuses.Count; index <= fileIndex - startIndex; index++) + int startIndex = db._folderStartFileIndex[folderIndex]; + for (int index = efi._extractStatuses.Count; index <= fileIndex - startIndex; index++) { - efi.ExtractStatuses.Add(index == fileIndex - startIndex); + efi._extractStatuses.Add(index == fileIndex - startIndex); } } foreach (CExtractFolderInfo efi in extractFolderInfoVector) { int startIndex; - if (efi.FileIndex != -1) + if (efi._fileIndex != -1) { - startIndex = efi.FileIndex; + startIndex = efi._fileIndex; } else { - startIndex = _db.FolderStartFileIndex[efi.FolderIndex]; + startIndex = db._folderStartFileIndex[efi._folderIndex]; } - var outStream = new FolderUnpackStream(_db, 0, startIndex, efi.ExtractStatuses); + var outStream = new FolderUnpackStream(db, 0, startIndex, efi._extractStatuses); - if (efi.FileIndex != -1) + if (efi._fileIndex != -1) { continue; } - int folderIndex = efi.FolderIndex; - CFolder folderInfo = _db.Folders[folderIndex]; + int folderIndex = efi._folderIndex; + CFolder folderInfo = db._folders[folderIndex]; - int packStreamIndex = _db.Folders[folderIndex].FirstPackStreamId; - long folderStartPackPos = _db.GetFolderStreamPos(folderInfo, 0); + int packStreamIndex = db._folders[folderIndex]._firstPackStreamId; + long folderStartPackPos = db.GetFolderStreamPos(folderInfo, 0); List packSizes = new List(); - for (int j = 0; j < folderInfo.PackStreams.Count; j++) + for (int j = 0; j < folderInfo._packStreams.Count; j++) { - packSizes.Add(_db.PackSizes[packStreamIndex + j]); + packSizes.Add(db._packSizes[packStreamIndex + j]); } // TODO: If the decoding fails the last file may be extracted incompletely. Delete it? Stream s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), - folderInfo, _db.PasswordProvider); + folderInfo, db.PasswordProvider); byte[] buffer = new byte[4 << 10]; for (;;) { @@ -1578,12 +1578,12 @@ namespace SharpCompress.Common.SevenZip public IEnumerable GetFiles(ArchiveDatabase db) { - return db.Files; + return db._files; } public int GetFileIndex(ArchiveDatabase db, CFileItem item) { - return db.Files.IndexOf(item); + return db._files.IndexOf(item); } #endregion diff --git a/src/SharpCompress/Common/SevenZip/CBindPair.cs b/src/SharpCompress/Common/SevenZip/CBindPair.cs index ca52cdbe..ad947967 100644 --- a/src/SharpCompress/Common/SevenZip/CBindPair.cs +++ b/src/SharpCompress/Common/SevenZip/CBindPair.cs @@ -2,7 +2,7 @@ { internal class CBindPair { - internal int InIndex; - internal int OutIndex; + internal int _inIndex; + internal int _outIndex; } } \ No newline at end of file diff --git a/src/SharpCompress/Common/SevenZip/CCoderInfo.cs b/src/SharpCompress/Common/SevenZip/CCoderInfo.cs index 75ae4781..03572299 100644 --- a/src/SharpCompress/Common/SevenZip/CCoderInfo.cs +++ b/src/SharpCompress/Common/SevenZip/CCoderInfo.cs @@ -2,9 +2,9 @@ { internal class CCoderInfo { - internal CMethodId MethodId; - internal byte[] Props; - internal int NumInStreams; - internal int NumOutStreams; + internal CMethodId _methodId; + internal byte[] _props; + internal int _numInStreams; + internal int _numOutStreams; } } \ No newline at end of file diff --git a/src/SharpCompress/Common/SevenZip/CFolder.cs b/src/SharpCompress/Common/SevenZip/CFolder.cs index 4606d9dc..4a68cf50 100644 --- a/src/SharpCompress/Common/SevenZip/CFolder.cs +++ b/src/SharpCompress/Common/SevenZip/CFolder.cs @@ -6,27 +6,27 @@ namespace SharpCompress.Common.SevenZip { internal class CFolder { - internal List Coders = new List(); - internal List BindPairs = new List(); - internal List PackStreams = new List(); - internal int FirstPackStreamId; - internal List UnpackSizes = new List(); - internal uint? UnpackCRC; + internal List _coders = new List(); + internal List _bindPairs = new List(); + internal List _packStreams = new List(); + internal int _firstPackStreamId; + internal List _unpackSizes = new List(); + internal uint? _unpackCrc; - internal bool UnpackCRCDefined => UnpackCRC != null; + internal bool UnpackCrcDefined => _unpackCrc != null; public long GetUnpackSize() { - if (UnpackSizes.Count == 0) + if (_unpackSizes.Count == 0) { return 0; } - for (int i = UnpackSizes.Count - 1; i >= 0; i--) + for (int i = _unpackSizes.Count - 1; i >= 0; i--) { if (FindBindPairForOutStream(i) < 0) { - return UnpackSizes[i]; + return _unpackSizes[i]; } } @@ -36,9 +36,9 @@ namespace SharpCompress.Common.SevenZip public int GetNumOutStreams() { int count = 0; - for (int i = 0; i < Coders.Count; i++) + for (int i = 0; i < _coders.Count; i++) { - count += Coders[i].NumOutStreams; + count += _coders[i]._numOutStreams; } return count; @@ -46,9 +46,9 @@ namespace SharpCompress.Common.SevenZip public int FindBindPairForInStream(int inStreamIndex) { - for (int i = 0; i < BindPairs.Count; i++) + for (int i = 0; i < _bindPairs.Count; i++) { - if (BindPairs[i].InIndex == inStreamIndex) + if (_bindPairs[i]._inIndex == inStreamIndex) { return i; } @@ -59,9 +59,9 @@ namespace SharpCompress.Common.SevenZip public int FindBindPairForOutStream(int outStreamIndex) { - for (int i = 0; i < BindPairs.Count; i++) + for (int i = 0; i < _bindPairs.Count; i++) { - if (BindPairs[i].OutIndex == outStreamIndex) + if (_bindPairs[i]._outIndex == outStreamIndex) { return i; } @@ -72,9 +72,9 @@ namespace SharpCompress.Common.SevenZip public int FindPackStreamArrayIndex(int inStreamIndex) { - for (int i = 0; i < PackStreams.Count; i++) + for (int i = 0; i < _packStreams.Count; i++) { - if (PackStreams[i] == inStreamIndex) + if (_packStreams[i] == inStreamIndex) { return i; } @@ -85,9 +85,9 @@ namespace SharpCompress.Common.SevenZip public bool IsEncrypted() { - for (int i = Coders.Count - 1; i >= 0; i--) + for (int i = _coders.Count - 1; i >= 0; i--) { - if (Coders[i].MethodId == CMethodId.kAES) + if (_coders[i]._methodId == CMethodId.K_AES) { return true; } @@ -102,25 +102,25 @@ namespace SharpCompress.Common.SevenZip const int kMaskSize = 32; // it must be >= kNumCodersMax const int kNumBindsMax = 32; - if (Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax) + if (_coders.Count > kNumCodersMax || _bindPairs.Count > kNumBindsMax) { return false; } { - var v = new BitVector(BindPairs.Count + PackStreams.Count); + var v = new BitVector(_bindPairs.Count + _packStreams.Count); - for (int i = 0; i < BindPairs.Count; i++) + for (int i = 0; i < _bindPairs.Count; i++) { - if (v.GetAndSet(BindPairs[i].InIndex)) + if (v.GetAndSet(_bindPairs[i]._inIndex)) { return false; } } - for (int i = 0; i < PackStreams.Count; i++) + for (int i = 0; i < _packStreams.Count; i++) { - if (v.GetAndSet(PackStreams[i])) + if (v.GetAndSet(_packStreams[i])) { return false; } @@ -128,10 +128,10 @@ namespace SharpCompress.Common.SevenZip } { - var v = new BitVector(UnpackSizes.Count); - for (int i = 0; i < BindPairs.Count; i++) + var v = new BitVector(_unpackSizes.Count); + for (int i = 0; i < _bindPairs.Count; i++) { - if (v.GetAndSet(BindPairs[i].OutIndex)) + if (v.GetAndSet(_bindPairs[i]._outIndex)) { return false; } @@ -143,23 +143,23 @@ namespace SharpCompress.Common.SevenZip { List inStreamToCoder = new List(); List outStreamToCoder = new List(); - for (int i = 0; i < Coders.Count; i++) + for (int i = 0; i < _coders.Count; i++) { - CCoderInfo coder = Coders[i]; - for (int j = 0; j < coder.NumInStreams; j++) + CCoderInfo coder = _coders[i]; + for (int j = 0; j < coder._numInStreams; j++) { inStreamToCoder.Add(i); } - for (int j = 0; j < coder.NumOutStreams; j++) + for (int j = 0; j < coder._numOutStreams; j++) { outStreamToCoder.Add(i); } } - for (int i = 0; i < BindPairs.Count; i++) + for (int i = 0; i < _bindPairs.Count; i++) { - CBindPair bp = BindPairs[i]; - mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]); + CBindPair bp = _bindPairs[i]; + mask[inStreamToCoder[bp._inIndex]] |= (1u << outStreamToCoder[bp._outIndex]); } } diff --git a/src/SharpCompress/Common/SevenZip/CMethodId.cs b/src/SharpCompress/Common/SevenZip/CMethodId.cs index 685d28bb..ee9e3bb3 100644 --- a/src/SharpCompress/Common/SevenZip/CMethodId.cs +++ b/src/SharpCompress/Common/SevenZip/CMethodId.cs @@ -2,26 +2,26 @@ { internal struct CMethodId { - public const ulong kCopyId = 0; - public const ulong kLzmaId = 0x030101; - public const ulong kLzma2Id = 0x21; - public const ulong kAESId = 0x06F10701; + public const ulong K_COPY_ID = 0; + public const ulong K_LZMA_ID = 0x030101; + public const ulong K_LZMA2_ID = 0x21; + public const ulong K_AES_ID = 0x06F10701; - public static readonly CMethodId kCopy = new CMethodId(kCopyId); - public static readonly CMethodId kLzma = new CMethodId(kLzmaId); - public static readonly CMethodId kLzma2 = new CMethodId(kLzma2Id); - public static readonly CMethodId kAES = new CMethodId(kAESId); + public static readonly CMethodId K_COPY = new CMethodId(K_COPY_ID); + public static readonly CMethodId K_LZMA = new CMethodId(K_LZMA_ID); + public static readonly CMethodId K_LZMA2 = new CMethodId(K_LZMA2_ID); + public static readonly CMethodId K_AES = new CMethodId(K_AES_ID); - public readonly ulong Id; + public readonly ulong _id; public CMethodId(ulong id) { - Id = id; + _id = id; } public override int GetHashCode() { - return Id.GetHashCode(); + return _id.GetHashCode(); } public override bool Equals(object obj) @@ -31,23 +31,23 @@ public bool Equals(CMethodId other) { - return Id == other.Id; + return _id == other._id; } public static bool operator ==(CMethodId left, CMethodId right) { - return left.Id == right.Id; + return left._id == right._id; } public static bool operator !=(CMethodId left, CMethodId right) { - return left.Id != right.Id; + return left._id != right._id; } public int GetLength() { int bytes = 0; - for (ulong value = Id; value != 0; value >>= 8) + for (ulong value = _id; value != 0; value >>= 8) { bytes++; } diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs index f62d9e32..3c5232b2 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs @@ -20,7 +20,7 @@ namespace SharpCompress.Common.SevenZip Header = fileEntry; if (Header.HasStream) { - Folder = database.Folders[database.FileIndexToFolderIndexMap[index]]; + Folder = database._folders[database._fileIndexToFolderIndexMap[index]]; } } @@ -43,12 +43,12 @@ namespace SharpCompress.Common.SevenZip } var folderStream = _database.GetFolderStream(_stream, Folder, _database.PasswordProvider); - int firstFileIndex = _database.FolderStartFileIndex[_database.Folders.IndexOf(Folder)]; + int firstFileIndex = _database._folderStartFileIndex[_database._folders.IndexOf(Folder)]; int skipCount = Index - firstFileIndex; long skipSize = 0; for (int i = 0; i < skipCount; i++) { - skipSize += _database.Files[firstFileIndex + i].Size; + skipSize += _database._files[firstFileIndex + i].Size; } if (skipSize > 0) { @@ -70,31 +70,31 @@ namespace SharpCompress.Common.SevenZip } //copied from DecoderRegistry - private const uint k_Copy = 0x0; - private const uint k_Delta = 3; - private const uint k_LZMA2 = 0x21; - private const uint k_LZMA = 0x030101; - private const uint k_PPMD = 0x030401; - private const uint k_BCJ = 0x03030103; - private const uint k_BCJ2 = 0x0303011B; - private const uint k_Deflate = 0x040108; - private const uint k_BZip2 = 0x040202; + private const uint K_COPY = 0x0; + private const uint K_DELTA = 3; + private const uint K_LZMA2 = 0x21; + private const uint K_LZMA = 0x030101; + private const uint K_PPMD = 0x030401; + private const uint K_BCJ = 0x03030103; + private const uint K_BCJ2 = 0x0303011B; + private const uint K_DEFLATE = 0x040108; + private const uint K_B_ZIP2 = 0x040202; internal CompressionType GetCompression() { - var coder = Folder.Coders.First(); - switch (coder.MethodId.Id) + var coder = Folder._coders.First(); + switch (coder._methodId._id) { - case k_LZMA: - case k_LZMA2: + case K_LZMA: + case K_LZMA2: { return CompressionType.LZMA; } - case k_PPMD: + case K_PPMD: { return CompressionType.PPMd; } - case k_BZip2: + case K_B_ZIP2: { return CompressionType.BZip2; } diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs index a03495f0..9f7f1536 100644 --- a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs +++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs @@ -7,7 +7,7 @@ namespace SharpCompress.Common.Tar.Headers { internal class TarHeader { - internal static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + internal static readonly DateTime EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); public TarHeader(ArchiveEncoding archiveEncoding) { @@ -27,11 +27,11 @@ namespace SharpCompress.Common.Tar.Headers internal Stream PackedStream { get; set; } internal ArchiveEncoding ArchiveEncoding { get; } - internal const int BlockSize = 512; + internal const int BLOCK_SIZE = 512; internal void Write(Stream output) { - byte[] buffer = new byte[BlockSize]; + byte[] buffer = new byte[BLOCK_SIZE]; WriteOctalBytes(511, buffer, 100, 8); // file mode WriteOctalBytes(0, buffer, 108, 8); // owner ID @@ -49,7 +49,7 @@ namespace SharpCompress.Common.Tar.Headers { WriteStringBytes(Name, buffer, 0, 100); WriteOctalBytes(Size, buffer, 124, 12); - var time = (long)(LastModifiedTime.ToUniversalTime() - Epoch).TotalSeconds; + var time = (long)(LastModifiedTime.ToUniversalTime() - EPOCH).TotalSeconds; WriteOctalBytes(time, buffer, 136, 12); buffer[156] = (byte)EntryType; @@ -82,10 +82,10 @@ namespace SharpCompress.Common.Tar.Headers output.Write(nameBytes, 0, nameBytes.Length); // pad to multiple of BlockSize bytes, and make sure a terminating null is added - int numPaddingBytes = BlockSize - (nameBytes.Length % BlockSize); + int numPaddingBytes = BLOCK_SIZE - (nameBytes.Length % BLOCK_SIZE); if (numPaddingBytes == 0) { - numPaddingBytes = BlockSize; + numPaddingBytes = BLOCK_SIZE; } output.Write(new byte[numPaddingBytes], 0, numPaddingBytes); } @@ -114,8 +114,8 @@ namespace SharpCompress.Common.Tar.Headers //Mode = ReadASCIIInt32Base8(buffer, 100, 7); //UserId = ReadASCIIInt32Base8(buffer, 108, 7); //GroupId = ReadASCIIInt32Base8(buffer, 116, 7); - long unixTimeStamp = ReadASCIIInt64Base8(buffer, 136, 11); - LastModifiedTime = Epoch.AddSeconds(unixTimeStamp).ToLocalTime(); + long unixTimeStamp = ReadAsciiInt64Base8(buffer, 136, 11); + LastModifiedTime = EPOCH.AddSeconds(unixTimeStamp).ToLocalTime(); Magic = ArchiveEncoding.Decode(buffer, 257, 6).TrimNulls(); @@ -142,10 +142,10 @@ namespace SharpCompress.Common.Tar.Headers var size = ReadSize(buffer); var nameLength = (int)size; var nameBytes = reader.ReadBytes(nameLength); - var remainingBytesToRead = BlockSize - (nameLength % BlockSize); + var remainingBytesToRead = BLOCK_SIZE - (nameLength % BLOCK_SIZE); // Read the rest of the block and discard the data - if (remainingBytesToRead < BlockSize) + if (remainingBytesToRead < BLOCK_SIZE) { reader.ReadBytes(remainingBytesToRead); } @@ -163,14 +163,14 @@ namespace SharpCompress.Common.Tar.Headers { return DataConverter.BigEndian.GetInt64(buffer, 0x80); } - return ReadASCIIInt64Base8(buffer, 124, 11); + return ReadAsciiInt64Base8(buffer, 124, 11); } private static byte[] ReadBlock(BinaryReader reader) { - byte[] buffer = reader.ReadBytes(BlockSize); + byte[] buffer = reader.ReadBytes(BLOCK_SIZE); - if (buffer.Length != 0 && buffer.Length < BlockSize) + if (buffer.Length != 0 && buffer.Length < BLOCK_SIZE) { throw new InvalidOperationException("Buffer is invalid size"); } @@ -206,7 +206,7 @@ namespace SharpCompress.Common.Tar.Headers } } - private static int ReadASCIIInt32Base8(byte[] buffer, int offset, int count) + private static int ReadAsciiInt32Base8(byte[] buffer, int offset, int count) { string s = Encoding.UTF8.GetString(buffer, offset, count).TrimNulls(); if (string.IsNullOrEmpty(s)) @@ -216,7 +216,7 @@ namespace SharpCompress.Common.Tar.Headers return Convert.ToInt32(s, 8); } - private static long ReadASCIIInt64Base8(byte[] buffer, int offset, int count) + private static long ReadAsciiInt64Base8(byte[] buffer, int offset, int count) { string s = Encoding.UTF8.GetString(buffer, offset, count).TrimNulls(); if (string.IsNullOrEmpty(s)) @@ -226,7 +226,7 @@ namespace SharpCompress.Common.Tar.Headers return Convert.ToInt64(s, 8); } - private static long ReadASCIIInt64(byte[] buffer, int offset, int count) + private static long ReadAsciiInt64(byte[] buffer, int offset, int count) { string s = Encoding.UTF8.GetString(buffer, offset, count).TrimNulls(); if (string.IsNullOrEmpty(s)) diff --git a/src/SharpCompress/Common/Tar/TarEntry.cs b/src/SharpCompress/Common/Tar/TarEntry.cs index 6ff6e19f..82e707d0 100644 --- a/src/SharpCompress/Common/Tar/TarEntry.cs +++ b/src/SharpCompress/Common/Tar/TarEntry.cs @@ -9,11 +9,11 @@ namespace SharpCompress.Common.Tar { public class TarEntry : Entry { - private readonly TarFilePart filePart; + private readonly TarFilePart _filePart; internal TarEntry(TarFilePart filePart, CompressionType type) { - this.filePart = filePart; + this._filePart = filePart; CompressionType = type; } @@ -21,13 +21,13 @@ namespace SharpCompress.Common.Tar public override long Crc => 0; - public override string Key => filePart.Header.Name; + public override string Key => _filePart.Header.Name; - public override long CompressedSize => filePart.Header.Size; + public override long CompressedSize => _filePart.Header.Size; - public override long Size => filePart.Header.Size; + public override long Size => _filePart.Header.Size; - public override DateTime? LastModifiedTime => filePart.Header.LastModifiedTime; + public override DateTime? LastModifiedTime => _filePart.Header.LastModifiedTime; public override DateTime? CreatedTime => null; @@ -37,11 +37,11 @@ namespace SharpCompress.Common.Tar public override bool IsEncrypted => false; - public override bool IsDirectory => filePart.Header.EntryType == EntryType.Directory; + public override bool IsDirectory => _filePart.Header.EntryType == EntryType.Directory; public override bool IsSplitAfter => false; - internal override IEnumerable Parts => filePart.AsEnumerable(); + internal override IEnumerable Parts => _filePart.AsEnumerable(); internal static IEnumerable GetEntries(StreamingMode mode, Stream stream, CompressionType compressionType, ArchiveEncoding archiveEncoding) diff --git a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs index 337dad74..d7ea3040 100644 --- a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs +++ b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs @@ -5,8 +5,8 @@ namespace SharpCompress.Common.Tar { internal class TarReadOnlySubStream : Stream { - private bool isDisposed; - private long amountRead; + private bool _isDisposed; + private long _amountRead; public TarReadOnlySubStream(Stream stream, long bytesToRead) { @@ -16,14 +16,14 @@ namespace SharpCompress.Common.Tar protected override void Dispose(bool disposing) { - if (isDisposed) + if (_isDisposed) { return; } - isDisposed = true; + _isDisposed = true; if (disposing) { - long skipBytes = amountRead % 512; + long skipBytes = _amountRead % 512; if (skipBytes == 0) { return; @@ -67,7 +67,7 @@ namespace SharpCompress.Common.Tar if (read > 0) { BytesLeftToRead -= read; - amountRead += read; + _amountRead += read; } return read; } diff --git a/src/SharpCompress/Common/Volume.cs b/src/SharpCompress/Common/Volume.cs index eab39d4d..86d968c0 100644 --- a/src/SharpCompress/Common/Volume.cs +++ b/src/SharpCompress/Common/Volume.cs @@ -6,7 +6,7 @@ namespace SharpCompress.Common { public abstract class Volume : IVolume { - private readonly Stream actualStream; + private readonly Stream _actualStream; internal Volume(Stream stream, ReaderOptions readerOptions) { @@ -15,10 +15,10 @@ namespace SharpCompress.Common { stream = new NonDisposingStream(stream); } - actualStream = stream; + _actualStream = stream; } - internal Stream Stream => actualStream; + internal Stream Stream => _actualStream; protected ReaderOptions ReaderOptions { get; } @@ -33,14 +33,14 @@ namespace SharpCompress.Common /// public virtual bool IsMultiVolume => true; - private bool disposed; + private bool _disposed; public void Dispose() { - if (!disposed) + if (!_disposed) { - actualStream.Dispose(); - disposed = true; + _actualStream.Dispose(); + _disposed = true; } } } diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs index c4002e22..a71d311d 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs @@ -34,7 +34,7 @@ namespace SharpCompress.Common.Zip.Headers byte[] extra = reader.ReadBytes(extraLength); byte[] comment = reader.ReadBytes(commentLength); - if (Flags.HasFlag(HeaderFlags.EFS)) + if (Flags.HasFlag(HeaderFlags.Efs)) { Name = ArchiveEncoding.Decode(name); Comment = ArchiveEncoding.Decode(comment); diff --git a/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs b/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs index b5f363d7..92aaaca7 100644 --- a/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs +++ b/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs @@ -12,6 +12,6 @@ namespace SharpCompress.Common.Zip.Headers UsePostDataDescriptor = 8, EnhancedDeflate = 16, //Bit 11: Language encoding flag - EFS = 2048 + Efs = 2048 } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs index 4b9e8178..e56b6102 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs @@ -26,7 +26,7 @@ namespace SharpCompress.Common.Zip.Headers byte[] name = reader.ReadBytes(nameLength); byte[] extra = reader.ReadBytes(extraLength); - if (Flags.HasFlag(HeaderFlags.EFS)) + if (Flags.HasFlag(HeaderFlags.Efs)) { Name = ArchiveEncoding.Decode(name); } diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs index 23ae243a..b86d5052 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs @@ -27,7 +27,7 @@ namespace SharpCompress.Common.Zip.Headers { internal byte Version => DataBytes[0]; - internal byte[] NameCRC32 + internal byte[] NameCrc32 { get { diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs index 41a74ef2..443cbd8a 100644 --- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs @@ -21,10 +21,10 @@ namespace SharpCompress.Common.Zip.Headers TotalNumberOfEntries = (long)reader.ReadUInt64(); DirectorySize = (long)reader.ReadUInt64(); DirectoryStartOffsetRelativeToDisk = (long)reader.ReadUInt64(); - DataSector = reader.ReadBytes((int)(SizeOfDirectoryEndRecord - SizeOfFixedHeaderDataExceptSignatureAndSizeFields)); + DataSector = reader.ReadBytes((int)(SizeOfDirectoryEndRecord - SIZE_OF_FIXED_HEADER_DATA_EXCEPT_SIGNATURE_AND_SIZE_FIELDS)); } - private const int SizeOfFixedHeaderDataExceptSignatureAndSizeFields = 44; + private const int SIZE_OF_FIXED_HEADER_DATA_EXCEPT_SIGNATURE_AND_SIZE_FIELDS = 44; public long SizeOfDirectoryEndRecord { get; private set; } diff --git a/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs b/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs index 2d412242..2c3f1400 100644 --- a/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs @@ -11,23 +11,23 @@ namespace SharpCompress.Common.Zip internal class PkwareTraditionalCryptoStream : Stream { - private readonly PkwareTraditionalEncryptionData encryptor; - private readonly CryptoMode mode; - private readonly Stream stream; - private bool isDisposed; + private readonly PkwareTraditionalEncryptionData _encryptor; + private readonly CryptoMode _mode; + private readonly Stream _stream; + private bool _isDisposed; public PkwareTraditionalCryptoStream(Stream stream, PkwareTraditionalEncryptionData encryptor, CryptoMode mode) { - this.encryptor = encryptor; - this.stream = stream; - this.mode = mode; + this._encryptor = encryptor; + this._stream = stream; + this._mode = mode; } - public override bool CanRead => (mode == CryptoMode.Decrypt); + public override bool CanRead => (_mode == CryptoMode.Decrypt); public override bool CanSeek => false; - public override bool CanWrite => (mode == CryptoMode.Encrypt); + public override bool CanWrite => (_mode == CryptoMode.Encrypt); public override long Length => throw new NotSupportedException(); @@ -35,7 +35,7 @@ namespace SharpCompress.Common.Zip public override int Read(byte[] buffer, int offset, int count) { - if (mode == CryptoMode.Encrypt) + if (_mode == CryptoMode.Encrypt) { throw new NotSupportedException("This stream does not encrypt via Read()"); } @@ -46,15 +46,15 @@ namespace SharpCompress.Common.Zip } byte[] temp = new byte[count]; - int readBytes = stream.Read(temp, 0, count); - byte[] decrypted = encryptor.Decrypt(temp, readBytes); + int readBytes = _stream.Read(temp, 0, count); + byte[] decrypted = _encryptor.Decrypt(temp, readBytes); Buffer.BlockCopy(decrypted, 0, buffer, offset, readBytes); return readBytes; } public override void Write(byte[] buffer, int offset, int count) { - if (mode == CryptoMode.Decrypt) + if (_mode == CryptoMode.Decrypt) { throw new NotSupportedException("This stream does not Decrypt via Write()"); } @@ -75,8 +75,8 @@ namespace SharpCompress.Common.Zip plaintext = buffer; } - byte[] encrypted = encryptor.Encrypt(plaintext, count); - stream.Write(encrypted, 0, encrypted.Length); + byte[] encrypted = _encryptor.Encrypt(plaintext, count); + _stream.Write(encrypted, 0, encrypted.Length); } public override void Flush() @@ -96,13 +96,13 @@ namespace SharpCompress.Common.Zip protected override void Dispose(bool disposing) { - if (isDisposed) + if (_isDisposed) { return; } - isDisposed = true; + _isDisposed = true; base.Dispose(disposing); - stream.Dispose(); + _stream.Dispose(); } } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs b/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs index a423176b..2a328003 100644 --- a/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs @@ -7,8 +7,8 @@ namespace SharpCompress.Common.Zip { internal class PkwareTraditionalEncryptionData { - private static readonly CRC32 crc32 = new CRC32(); - private readonly UInt32[] _Keys = {0x12345678, 0x23456789, 0x34567890}; + private static readonly CRC32 CRC32 = new CRC32(); + private readonly UInt32[] _keys = {0x12345678, 0x23456789, 0x34567890}; private readonly ArchiveEncoding _archiveEncoding; private PkwareTraditionalEncryptionData(string password, ArchiveEncoding archiveEncoding) @@ -21,7 +21,7 @@ namespace SharpCompress.Common.Zip { get { - ushort t = (ushort)((ushort)(_Keys[2] & 0xFFFF) | 2); + ushort t = (ushort)((ushort)(_keys[2] & 0xFFFF) | 2); return (byte)((t * (t ^ 1)) >> 8); } } @@ -56,9 +56,9 @@ namespace SharpCompress.Common.Zip var plainText = new byte[length]; for (int i = 0; i < length; i++) { - var C = (byte)(cipherText[i] ^ MagicByte); - UpdateKeys(C); - plainText[i] = C; + var c = (byte)(cipherText[i] ^ MagicByte); + UpdateKeys(c); + plainText[i] = c; } return plainText; } @@ -79,9 +79,9 @@ namespace SharpCompress.Common.Zip var cipherText = new byte[length]; for (int i = 0; i < length; i++) { - byte C = plainText[i]; + byte c = plainText[i]; cipherText[i] = (byte)(plainText[i] ^ MagicByte); - UpdateKeys(C); + UpdateKeys(c); } return cipherText; } @@ -103,10 +103,10 @@ namespace SharpCompress.Common.Zip private void UpdateKeys(byte byteValue) { - _Keys[0] = (UInt32)crc32.ComputeCrc32((int)_Keys[0], byteValue); - _Keys[1] = _Keys[1] + (byte)_Keys[0]; - _Keys[1] = _Keys[1] * 0x08088405 + 1; - _Keys[2] = (UInt32)crc32.ComputeCrc32((int)_Keys[2], (byte)(_Keys[1] >> 24)); + _keys[0] = (UInt32)CRC32.ComputeCrc32((int)_keys[0], byteValue); + _keys[1] = _keys[1] + (byte)_keys[0]; + _keys[1] = _keys[1] * 0x08088405 + 1; + _keys[2] = (UInt32)CRC32.ComputeCrc32((int)_keys[2], (byte)(_keys[1] >> 24)); } } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs index a528c137..60715413 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs @@ -7,7 +7,7 @@ namespace SharpCompress.Common.Zip { internal class StreamingZipFilePart : ZipFilePart { - private Stream decompressionStream; + private Stream _decompressionStream; internal StreamingZipFilePart(ZipFileEntry header, Stream stream) : base(header, stream) @@ -25,12 +25,12 @@ namespace SharpCompress.Common.Zip { return Stream.Null; } - decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod); + _decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod); if (LeaveStreamOpen) { - return new NonDisposingStream(decompressionStream); + return new NonDisposingStream(_decompressionStream); } - return decompressionStream; + return _decompressionStream; } internal BinaryReader FixStreamedFileLocation(ref RewindableStream rewindableStream) @@ -41,13 +41,13 @@ namespace SharpCompress.Common.Zip } if (Header.HasData && !Skipped) { - if (decompressionStream == null) + if (_decompressionStream == null) { - decompressionStream = GetCompressedStream(); + _decompressionStream = GetCompressedStream(); } - decompressionStream.Skip(); + _decompressionStream.Skip(); - DeflateStream deflateStream = decompressionStream as DeflateStream; + DeflateStream deflateStream = _decompressionStream as DeflateStream; if (deflateStream != null) { rewindableStream.Rewind(deflateStream.InputBuffer); @@ -55,7 +55,7 @@ namespace SharpCompress.Common.Zip Skipped = true; } var reader = new BinaryReader(rewindableStream); - decompressionStream = null; + _decompressionStream = null; return reader; } } diff --git a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs index 1f4df93a..1148c53c 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs @@ -28,25 +28,25 @@ namespace SharpCompress.Common.Zip { ZipHeader header = null; BinaryReader reader = new BinaryReader(rewindableStream); - if (lastEntryHeader != null && - (FlagUtility.HasFlag(lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor) || lastEntryHeader.IsZip64)) + if (_lastEntryHeader != null && + (FlagUtility.HasFlag(_lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor) || _lastEntryHeader.IsZip64)) { - reader = (lastEntryHeader.Part as StreamingZipFilePart).FixStreamedFileLocation(ref rewindableStream); + reader = (_lastEntryHeader.Part as StreamingZipFilePart).FixStreamedFileLocation(ref rewindableStream); long? pos = rewindableStream.CanSeek ? (long?)rewindableStream.Position : null; uint crc = reader.ReadUInt32(); if (crc == POST_DATA_DESCRIPTOR) { crc = reader.ReadUInt32(); } - lastEntryHeader.Crc = crc; - lastEntryHeader.CompressedSize = reader.ReadUInt32(); - lastEntryHeader.UncompressedSize = reader.ReadUInt32(); + _lastEntryHeader.Crc = crc; + _lastEntryHeader.CompressedSize = reader.ReadUInt32(); + _lastEntryHeader.UncompressedSize = reader.ReadUInt32(); if (pos.HasValue) { - lastEntryHeader.DataStartPosition = pos - lastEntryHeader.CompressedSize; + _lastEntryHeader.DataStartPosition = pos - _lastEntryHeader.CompressedSize; } } - lastEntryHeader = null; + _lastEntryHeader = null; uint headerBytes = reader.ReadUInt32(); header = ReadHeader(headerBytes, reader); diff --git a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs index e5618827..62e6cff2 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs @@ -10,25 +10,25 @@ namespace SharpCompress.Common.Zip internal class WinzipAesCryptoStream : Stream { private const int BLOCK_SIZE_IN_BYTES = 16; - private readonly SymmetricAlgorithm cipher; - private readonly byte[] counter = new byte[BLOCK_SIZE_IN_BYTES]; - private readonly Stream stream; - private readonly ICryptoTransform transform; - private int nonce = 1; - private byte[] counterOut = new byte[BLOCK_SIZE_IN_BYTES]; - private bool isFinalBlock; - private long totalBytesLeftToRead; - private bool isDisposed; + private readonly SymmetricAlgorithm _cipher; + private readonly byte[] _counter = new byte[BLOCK_SIZE_IN_BYTES]; + private readonly Stream _stream; + private readonly ICryptoTransform _transform; + private int _nonce = 1; + private byte[] _counterOut = new byte[BLOCK_SIZE_IN_BYTES]; + private bool _isFinalBlock; + private long _totalBytesLeftToRead; + private bool _isDisposed; internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length) { - this.stream = stream; - totalBytesLeftToRead = length; + this._stream = stream; + _totalBytesLeftToRead = length; - cipher = CreateCipher(winzipAesEncryptionData); + _cipher = CreateCipher(winzipAesEncryptionData); var iv = new byte[BLOCK_SIZE_IN_BYTES]; - transform = cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv); + _transform = _cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv); } private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData) @@ -69,17 +69,17 @@ namespace SharpCompress.Common.Zip protected override void Dispose(bool disposing) { - if (isDisposed) + if (_isDisposed) { return; } - isDisposed = true; + _isDisposed = true; if (disposing) { //read out last 10 auth bytes var ten = new byte[10]; - stream.ReadFully(ten); - stream.Dispose(); + _stream.ReadFully(ten); + _stream.Dispose(); } } @@ -90,17 +90,17 @@ namespace SharpCompress.Common.Zip public override int Read(byte[] buffer, int offset, int count) { - if (totalBytesLeftToRead == 0) + if (_totalBytesLeftToRead == 0) { return 0; } int bytesToRead = count; - if (count > totalBytesLeftToRead) + if (count > _totalBytesLeftToRead) { - bytesToRead = (int)totalBytesLeftToRead; + bytesToRead = (int)_totalBytesLeftToRead; } - int read = stream.Read(buffer, offset, bytesToRead); - totalBytesLeftToRead -= read; + int read = _stream.Read(buffer, offset, bytesToRead); + _totalBytesLeftToRead -= read; ReadTransformBlocks(buffer, offset, read); @@ -109,7 +109,7 @@ namespace SharpCompress.Common.Zip private int ReadTransformOneBlock(byte[] buffer, int offset, int last) { - if (isFinalBlock) + if (_isFinalBlock) { throw new InvalidOperationException(); } @@ -120,22 +120,22 @@ namespace SharpCompress.Common.Zip : bytesRemaining; // update the counter - DataConverter.LittleEndian.PutBytes(counter, 0, nonce++); + DataConverter.LittleEndian.PutBytes(_counter, 0, _nonce++); // Determine if this is the final block - if ((bytesToRead == bytesRemaining) && (totalBytesLeftToRead == 0)) + if ((bytesToRead == bytesRemaining) && (_totalBytesLeftToRead == 0)) { - counterOut = transform.TransformFinalBlock(counter, + _counterOut = _transform.TransformFinalBlock(_counter, 0, BLOCK_SIZE_IN_BYTES); - isFinalBlock = true; + _isFinalBlock = true; } else { - transform.TransformBlock(counter, + _transform.TransformBlock(_counter, 0, // offset BLOCK_SIZE_IN_BYTES, - counterOut, + _counterOut, 0); // offset } @@ -148,7 +148,7 @@ namespace SharpCompress.Common.Zip { for (int i = 0; i < count; i++) { - buffer[offset + i] = (byte)(counterOut[i] ^ buffer[offset + i]); + buffer[offset + i] = (byte)(_counterOut[i] ^ buffer[offset + i]); } } diff --git a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs index 0d85bafc..49f3dd24 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs @@ -10,20 +10,20 @@ namespace SharpCompress.Common.Zip { private const int RFC2898_ITERATIONS = 1000; - private readonly byte[] salt; - private readonly WinzipAesKeySize keySize; - private readonly byte[] passwordVerifyValue; - private readonly string password; + private readonly byte[] _salt; + private readonly WinzipAesKeySize _keySize; + private readonly byte[] _passwordVerifyValue; + private readonly string _password; - private byte[] generatedVerifyValue; + private byte[] _generatedVerifyValue; internal WinzipAesEncryptionData(WinzipAesKeySize keySize, byte[] salt, byte[] passwordVerifyValue, string password) { - this.keySize = keySize; - this.salt = salt; - this.passwordVerifyValue = passwordVerifyValue; - this.password = password; + this._keySize = keySize; + this._salt = salt; + this._passwordVerifyValue = passwordVerifyValue; + this._password = password; Initialize(); } @@ -38,7 +38,7 @@ namespace SharpCompress.Common.Zip private int KeySizeInBytes { - get { return KeyLengthInBytes(keySize); + get { return KeyLengthInBytes(_keySize); } } @@ -58,16 +58,16 @@ namespace SharpCompress.Common.Zip private void Initialize() { - var rfc2898 = new Rfc2898DeriveBytes(password, salt, RFC2898_ITERATIONS); + var rfc2898 = new Rfc2898DeriveBytes(_password, _salt, RFC2898_ITERATIONS); KeyBytes = rfc2898.GetBytes(KeySizeInBytes); // 16 or 24 or 32 ??? IvBytes = rfc2898.GetBytes(KeySizeInBytes); - generatedVerifyValue = rfc2898.GetBytes(2); + _generatedVerifyValue = rfc2898.GetBytes(2); - short verify = DataConverter.LittleEndian.GetInt16(passwordVerifyValue, 0); - if (password != null) + short verify = DataConverter.LittleEndian.GetInt16(_passwordVerifyValue, 0); + if (_password != null) { - short generated = DataConverter.LittleEndian.GetInt16(generatedVerifyValue, 0); + short generated = DataConverter.LittleEndian.GetInt16(_generatedVerifyValue, 0); if (verify != generated) { throw new InvalidFormatException("bad password"); diff --git a/src/SharpCompress/Common/Zip/ZipEntry.cs b/src/SharpCompress/Common/Zip/ZipEntry.cs index 2db83216..379534ff 100644 --- a/src/SharpCompress/Common/Zip/ZipEntry.cs +++ b/src/SharpCompress/Common/Zip/ZipEntry.cs @@ -6,13 +6,13 @@ namespace SharpCompress.Common.Zip { public class ZipEntry : Entry { - private readonly ZipFilePart filePart; + private readonly ZipFilePart _filePart; internal ZipEntry(ZipFilePart filePart) { if (filePart != null) { - this.filePart = filePart; + this._filePart = filePart; LastModifiedTime = Utility.DosDateToDateTime(filePart.Header.LastModifiedDate, filePart.Header.LastModifiedTime); } @@ -22,7 +22,7 @@ namespace SharpCompress.Common.Zip { get { - switch (filePart.Header.CompressionMethod) + switch (_filePart.Header.CompressionMethod) { case ZipCompressionMethod.BZip2: { @@ -56,13 +56,13 @@ namespace SharpCompress.Common.Zip } } - public override long Crc => filePart.Header.Crc; + public override long Crc => _filePart.Header.Crc; - public override string Key => filePart.Header.Name; + public override string Key => _filePart.Header.Name; - public override long CompressedSize => filePart.Header.CompressedSize; + public override long CompressedSize => _filePart.Header.CompressedSize; - public override long Size => filePart.Header.UncompressedSize; + public override long Size => _filePart.Header.UncompressedSize; public override DateTime? LastModifiedTime { get; } @@ -72,12 +72,12 @@ namespace SharpCompress.Common.Zip public override DateTime? ArchivedTime => null; - public override bool IsEncrypted => FlagUtility.HasFlag(filePart.Header.Flags, HeaderFlags.Encrypted); + public override bool IsEncrypted => FlagUtility.HasFlag(_filePart.Header.Flags, HeaderFlags.Encrypted); - public override bool IsDirectory => filePart.Header.IsDirectory; + public override bool IsDirectory => _filePart.Header.IsDirectory; public override bool IsSplitAfter => false; - internal override IEnumerable Parts => filePart.AsEnumerable(); + internal override IEnumerable Parts => _filePart.AsEnumerable(); } } \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs index 9fcf9348..bc8187c2 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -21,16 +21,16 @@ namespace SharpCompress.Common.Zip internal const uint ZIP64_END_OF_CENTRAL_DIRECTORY = 0x06064b50; internal const uint ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR = 0x07064b50; - protected LocalEntryHeader lastEntryHeader; - private readonly string password; - private readonly StreamingMode mode; - private readonly ArchiveEncoding archiveEncoding; + protected LocalEntryHeader _lastEntryHeader; + private readonly string _password; + private readonly StreamingMode _mode; + private readonly ArchiveEncoding _archiveEncoding; protected ZipHeaderFactory(StreamingMode mode, string password, ArchiveEncoding archiveEncoding) { - this.mode = mode; - this.password = password; - this.archiveEncoding = archiveEncoding; + this._mode = mode; + this._password = password; + this._archiveEncoding = archiveEncoding; } protected ZipHeader ReadHeader(uint headerBytes, BinaryReader reader, bool zip64 = false) @@ -39,26 +39,26 @@ namespace SharpCompress.Common.Zip { case ENTRY_HEADER_BYTES: { - var entryHeader = new LocalEntryHeader(archiveEncoding); + var entryHeader = new LocalEntryHeader(_archiveEncoding); entryHeader.Read(reader); LoadHeader(entryHeader, reader.BaseStream); - lastEntryHeader = entryHeader; + _lastEntryHeader = entryHeader; return entryHeader; } case DIRECTORY_START_HEADER_BYTES: { - var entry = new DirectoryEntryHeader(archiveEncoding); + var entry = new DirectoryEntryHeader(_archiveEncoding); entry.Read(reader); return entry; } case POST_DATA_DESCRIPTOR: { - if (FlagUtility.HasFlag(lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) + if (FlagUtility.HasFlag(_lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) { - lastEntryHeader.Crc = reader.ReadUInt32(); - lastEntryHeader.CompressedSize = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32(); - lastEntryHeader.UncompressedSize = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32(); + _lastEntryHeader.Crc = reader.ReadUInt32(); + _lastEntryHeader.CompressedSize = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32(); + _lastEntryHeader.UncompressedSize = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32(); } else { @@ -123,12 +123,12 @@ namespace SharpCompress.Common.Zip throw new NotSupportedException("SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner."); } - if (password == null) + if (_password == null) { throw new CryptographicException("No password supplied for encrypted zip."); } - entryHeader.Password = password; + entryHeader.Password = _password; if (entryHeader.CompressionMethod == ZipCompressionMethod.WinzipAes) { @@ -146,7 +146,7 @@ namespace SharpCompress.Common.Zip stream.Read(salt, 0, salt.Length); stream.Read(passwordVerifyValue, 0, 2); entryHeader.WinzipAesEncryptionData = - new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue, password); + new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue, _password); entryHeader.CompressedSize -= (uint)(salt.Length + 2); } @@ -165,7 +165,7 @@ namespace SharpCompress.Common.Zip //} //else //{ - switch (mode) + switch (_mode) { case StreamingMode.Seekable: { diff --git a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs index a7159122..e499eeb7 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs @@ -447,7 +447,7 @@ namespace SharpCompress.Compressors.Deflate } Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4); - _GzipMtime = TarHeader.Epoch.AddSeconds(timet); + _GzipMtime = TarHeader.EPOCH.AddSeconds(timet); totalBytesRead += n; if ((header[3] & 0x04) == 0x04) { diff --git a/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs b/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs index 341dc6ff..be7300c2 100644 --- a/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs +++ b/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs @@ -13,7 +13,7 @@ namespace SharpCompress.Compressors.Deflate64 { public sealed class Deflate64Stream : Stream { - private const int DefaultBufferSize = 8192; + private const int DEFAULT_BUFFER_SIZE = 8192; private Stream _stream; private CompressionMode _mode; @@ -35,7 +35,7 @@ namespace SharpCompress.Compressors.Deflate64 /// /// Sets up this DeflateManagedStream to be used for Inflation/Decompression /// - internal void InitializeInflater(Stream stream, ZipCompressionMethod method = ZipCompressionMethod.Deflate) + private void InitializeInflater(Stream stream, ZipCompressionMethod method = ZipCompressionMethod.Deflate) { Debug.Assert(stream != null); Debug.Assert(method == ZipCompressionMethod.Deflate || method == ZipCompressionMethod.Deflate64); @@ -46,7 +46,7 @@ namespace SharpCompress.Compressors.Deflate64 _stream = stream; _mode = CompressionMode.Decompress; - _buffer = new byte[DefaultBufferSize]; + _buffer = new byte[DEFAULT_BUFFER_SIZE]; } public override bool CanRead diff --git a/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs b/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs index 1e455a46..ecfae42b 100644 --- a/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs +++ b/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs @@ -10,7 +10,7 @@ namespace SharpCompress.Compressors.Deflate64 { // static information for encoding, DO NOT MODIFY - internal static readonly byte[] FastEncoderTreeStructureData = + internal static readonly byte[] FAST_ENCODER_TREE_STRUCTURE_DATA = { 0xec,0xbd,0x07,0x60,0x1c,0x49,0x96,0x25,0x26,0x2f,0x6d,0xca, 0x7b,0x7f,0x4a,0xf5,0x4a,0xd7,0xe0,0x74,0xa1,0x08,0x80,0x60, @@ -23,7 +23,7 @@ namespace SharpCompress.Compressors.Deflate64 0x1f,0x3f }; - internal static readonly byte[] BFinalFastEncoderTreeStructureData = + internal static readonly byte[] B_FINAL_FAST_ENCODER_TREE_STRUCTURE_DATA = { 0xed,0xbd,0x07,0x60,0x1c,0x49,0x96,0x25,0x26,0x2f,0x6d,0xca, 0x7b,0x7f,0x4a,0xf5,0x4a,0xd7,0xe0,0x74,0xa1,0x08,0x80,0x60, @@ -67,7 +67,7 @@ namespace SharpCompress.Compressors.Deflate64 // The least 5 significant bits are the length // and the rest is the code bits. - internal static readonly uint[] FastEncoderLiteralCodeInfo = + internal static readonly uint[] FAST_ENCODER_LITERAL_CODE_INFO = { 0x0000d7ee,0x0004d7ee,0x0002d7ee,0x0006d7ee,0x0001d7ee,0x0005d7ee,0x0003d7ee, 0x0007d7ee,0x000037ee,0x0000c7ec,0x00000126,0x000437ee,0x000237ee,0x000637ee, @@ -145,7 +145,7 @@ namespace SharpCompress.Compressors.Deflate64 0x003de7f1,0x000047eb }; - internal static readonly uint[] FastEncoderDistanceCodeInfo = + internal static readonly uint[] FAST_ENCODER_DISTANCE_CODE_INFO = { 0x00000f06,0x0001ff0a,0x0003ff0b,0x0007ff0b,0x0000ff19,0x00003f18,0x0000bf28, 0x00007f28,0x00001f37,0x00005f37,0x00000d45,0x00002f46,0x00000054,0x00001d55, @@ -154,23 +154,23 @@ namespace SharpCompress.Compressors.Deflate64 0x000007d5,0x000017d5,0x00000000,0x00000100 }; - internal static readonly uint[] BitMask = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 }; - internal static readonly byte[] ExtraLengthBits = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; - internal static readonly byte[] ExtraDistanceBits = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0 }; - internal const int NumChars = 256; - internal const int NumLengthBaseCodes = 29; - internal const int NumDistBaseCodes = 30; + internal static readonly uint[] BIT_MASK = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 }; + internal static readonly byte[] EXTRA_LENGTH_BITS = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 }; + internal static readonly byte[] EXTRA_DISTANCE_BITS = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0 }; + internal const int NUM_CHARS = 256; + internal const int NUM_LENGTH_BASE_CODES = 29; + internal const int NUM_DIST_BASE_CODES = 30; - internal const uint FastEncoderPostTreeBitBuf = 0x0022; - internal const int FastEncoderPostTreeBitCount = 9; + internal const uint FAST_ENCODER_POST_TREE_BIT_BUF = 0x0022; + internal const int FAST_ENCODER_POST_TREE_BIT_COUNT = 9; - internal const uint NoCompressionHeader = 0x0; - internal const int NoCompressionHeaderBitCount = 3; - internal const uint BFinalNoCompressionHeader = 0x1; - internal const int BFinalNoCompressionHeaderBitCount = 3; - internal const int MaxCodeLen = 16; + internal const uint NO_COMPRESSION_HEADER = 0x0; + internal const int NO_COMPRESSION_HEADER_BIT_COUNT = 3; + internal const uint B_FINAL_NO_COMPRESSION_HEADER = 0x1; + internal const int B_FINAL_NO_COMPRESSION_HEADER_BIT_COUNT = 3; + internal const int MAX_CODE_LEN = 16; - private static readonly byte[] s_distLookup = CreateDistanceLookup(); + private static readonly byte[] S_DIST_LOOKUP = CreateDistanceLookup(); private static byte[] CreateDistanceLookup() { @@ -207,15 +207,15 @@ namespace SharpCompress.Compressors.Deflate64 int code; for (code = 0; code < 16; code++) { - for (int n = 0; n < (1 << ExtraDistanceBits[code]); n++) + for (int n = 0; n < (1 << EXTRA_DISTANCE_BITS[code]); n++) result[dist++] = (byte)code; } dist >>= 7; // from now on, all distances are divided by 128 - for (; code < NumDistBaseCodes; code++) + for (; code < NUM_DIST_BASE_CODES; code++) { - for (int n = 0; n < (1 << (ExtraDistanceBits[code] - 7)); n++) + for (int n = 0; n < (1 << (EXTRA_DISTANCE_BITS[code] - 7)); n++) result[256 + dist++] = (byte)code; } @@ -224,22 +224,22 @@ namespace SharpCompress.Compressors.Deflate64 // Return the position slot (0...29) of a match offset (0...32767) internal static int GetSlot(int pos) => - s_distLookup[((pos) < 256) ? (pos) : (256 + ((pos) >> 7))]; + S_DIST_LOOKUP[((pos) < 256) ? (pos) : (256 + ((pos) >> 7))]; // Reverse 'length' of the bits in code public static uint BitReverse(uint code, int length) { - uint new_code = 0; + uint newCode = 0; Debug.Assert(length > 0 && length <= 16, "Invalid len"); do { - new_code |= (code & 1); - new_code <<= 1; + newCode |= (code & 1); + newCode <<= 1; code >>= 1; } while (--length > 0); - return new_code >> 1; + return newCode >> 1; } } } diff --git a/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs b/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs index b57219a2..62c24b59 100644 --- a/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs +++ b/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs @@ -24,10 +24,10 @@ namespace SharpCompress.Compressors.Deflate64 internal sealed class HuffmanTree { - internal const int MaxLiteralTreeElements = 288; - internal const int MaxDistTreeElements = 32; - internal const int EndOfBlockCode = 256; - internal const int NumberOfCodeLengthTreeElements = 19; + internal const int MAX_LITERAL_TREE_ELEMENTS = 288; + internal const int MAX_DIST_TREE_ELEMENTS = 32; + internal const int END_OF_BLOCK_CODE = 256; + internal const int NUMBER_OF_CODE_LENGTH_TREE_ELEMENTS = 19; private readonly int _tableBits; private readonly short[] _table; @@ -48,13 +48,13 @@ namespace SharpCompress.Compressors.Deflate64 public HuffmanTree(byte[] codeLengths) { Debug.Assert( - codeLengths.Length == MaxLiteralTreeElements || - codeLengths.Length == MaxDistTreeElements || - codeLengths.Length == NumberOfCodeLengthTreeElements, + codeLengths.Length == MAX_LITERAL_TREE_ELEMENTS || + codeLengths.Length == MAX_DIST_TREE_ELEMENTS || + codeLengths.Length == NUMBER_OF_CODE_LENGTH_TREE_ELEMENTS, "we only expect three kinds of Length here"); _codeLengthArray = codeLengths; - if (_codeLengthArray.Length == MaxLiteralTreeElements) + if (_codeLengthArray.Length == MAX_LITERAL_TREE_ELEMENTS) { // bits for Literal/Length tree table _tableBits = 9; @@ -80,7 +80,7 @@ namespace SharpCompress.Compressors.Deflate64 // The data is in RFC 1951. private static byte[] GetStaticLiteralTreeLength() { - byte[] literalTreeLength = new byte[MaxLiteralTreeElements]; + byte[] literalTreeLength = new byte[MAX_LITERAL_TREE_ELEMENTS]; for (int i = 0; i <= 143; i++) literalTreeLength[i] = 8; @@ -98,8 +98,8 @@ namespace SharpCompress.Compressors.Deflate64 private static byte[] GetStaticDistanceTreeLength() { - byte[] staticDistanceTreeLength = new byte[MaxDistTreeElements]; - for (int i = 0; i < MaxDistTreeElements; i++) + byte[] staticDistanceTreeLength = new byte[MAX_DIST_TREE_ELEMENTS]; + for (int i = 0; i < MAX_DIST_TREE_ELEMENTS; i++) { staticDistanceTreeLength[i] = 5; } @@ -125,7 +125,7 @@ namespace SharpCompress.Compressors.Deflate64 nextCode[bits] = tempCode; } - uint[] code = new uint[MaxLiteralTreeElements]; + uint[] code = new uint[MAX_LITERAL_TREE_ELEMENTS]; for (int i = 0; i < _codeLengthArray.Length; i++) { int len = _codeLengthArray[i]; diff --git a/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs b/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs index 32194d78..7ce389b7 100644 --- a/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs +++ b/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs @@ -37,23 +37,23 @@ namespace SharpCompress.Compressors.Deflate64 // const tables used in decoding: // Extra bits for length code 257 - 285. - private static readonly byte[] s_extraLengthBits = + private static readonly byte[] S_EXTRA_LENGTH_BITS = { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,16 }; // The base length for length code 257 - 285. // The formula to get the real length for a length code is lengthBase[code - 257] + (value stored in extraBits) - private static readonly int[] s_lengthBase = + private static readonly int[] S_LENGTH_BASE = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,3}; // The base distance for distance code 0 - 31 // The real distance for a distance code is distanceBasePosition[code] + (value stored in extraBits) - private static readonly int[] s_distanceBasePosition = + private static readonly int[] S_DISTANCE_BASE_POSITION = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,32769,49153 }; // code lengths for code length alphabet is stored in following order - private static readonly byte[] s_codeOrder = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + private static readonly byte[] S_CODE_ORDER = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; - private static readonly byte[] s_staticDistanceTreeTable = + private static readonly byte[] S_STATIC_DISTANCE_TREE_TABLE = { 0x00,0x10,0x08,0x18,0x04,0x14,0x0c,0x1c,0x02,0x12,0x0a,0x1a, 0x06,0x16,0x0e,0x1e,0x01,0x11,0x09,0x19,0x05,0x15,0x0d,0x1d, @@ -98,8 +98,8 @@ namespace SharpCompress.Compressors.Deflate64 _output = new OutputWindow(); _input = new InputBuffer(); - _codeList = new byte[HuffmanTree.MaxLiteralTreeElements + HuffmanTree.MaxDistTreeElements]; - _codeLengthTreeCodeLength = new byte[HuffmanTree.NumberOfCodeLengthTreeElements]; + _codeList = new byte[HuffmanTree.MAX_LITERAL_TREE_ELEMENTS + HuffmanTree.MAX_DIST_TREE_ELEMENTS]; + _codeLengthTreeCodeLength = new byte[HuffmanTree.NUMBER_OF_CODE_LENGTH_TREE_ELEMENTS]; _deflate64 = deflate64; //if (reader != null) //{ @@ -308,9 +308,9 @@ namespace SharpCompress.Compressors.Deflate64 // // LEN is the number of data bytes in the block. NLEN is the // one's complement of LEN. - private bool DecodeUncompressedBlock(out bool end_of_block) + private bool DecodeUncompressedBlock(out bool endOfBlock) { - end_of_block = false; + endOfBlock = false; while (true) { switch (_state) @@ -357,7 +357,7 @@ namespace SharpCompress.Compressors.Deflate64 { // Done with this block, need to re-init bit buffer for next block _state = InflaterState.ReadingBFinal; - end_of_block = true; + endOfBlock = true; return true; } @@ -378,9 +378,9 @@ namespace SharpCompress.Compressors.Deflate64 } } - private bool DecodeBlock(out bool end_of_block_code_seen) + private bool DecodeBlock(out bool endOfBlockCodeSeen) { - end_of_block_code_seen = false; + endOfBlockCodeSeen = false; int freeBytes = _output.FreeBytes; // it is a little bit faster than frequently accessing the property while (freeBytes > 65536) @@ -411,7 +411,7 @@ namespace SharpCompress.Compressors.Deflate64 else if (symbol == 256) { // end of block - end_of_block_code_seen = true; + endOfBlockCodeSeen = true; // Reset state _state = InflaterState.ReadingBFinal; return true; @@ -433,11 +433,11 @@ namespace SharpCompress.Compressors.Deflate64 } else { - if (symbol < 0 || symbol >= s_extraLengthBits.Length) + if (symbol < 0 || symbol >= S_EXTRA_LENGTH_BITS.Length) { throw new InvalidDataException("Deflate64: invalid data"); } - _extraBits = s_extraLengthBits[symbol]; + _extraBits = S_EXTRA_LENGTH_BITS[symbol]; Debug.Assert(_extraBits != 0, "We handle other cases separately!"); } _length = symbol; @@ -455,11 +455,11 @@ namespace SharpCompress.Compressors.Deflate64 return false; } - if (_length < 0 || _length >= s_lengthBase.Length) + if (_length < 0 || _length >= S_LENGTH_BASE.Length) { throw new InvalidDataException("Deflate64: invalid data"); } - _length = s_lengthBase[_length] + bits; + _length = S_LENGTH_BASE[_length] + bits; } _state = InflaterState.HaveFullLength; goto case InflaterState.HaveFullLength; @@ -475,7 +475,7 @@ namespace SharpCompress.Compressors.Deflate64 _distanceCode = _input.GetBits(5); if (_distanceCode >= 0) { - _distanceCode = s_staticDistanceTreeTable[_distanceCode]; + _distanceCode = S_STATIC_DISTANCE_TREE_TABLE[_distanceCode]; } } @@ -500,7 +500,7 @@ namespace SharpCompress.Compressors.Deflate64 { return false; } - offset = s_distanceBasePosition[_distanceCode] + bits; + offset = S_DISTANCE_BASE_POSITION[_distanceCode] + bits; } else { @@ -588,13 +588,13 @@ namespace SharpCompress.Compressors.Deflate64 { return false; } - _codeLengthTreeCodeLength[s_codeOrder[_loopCounter]] = (byte)bits; + _codeLengthTreeCodeLength[S_CODE_ORDER[_loopCounter]] = (byte)bits; ++_loopCounter; } - for (int i = _codeLengthCodeCount; i < s_codeOrder.Length; i++) + for (int i = _codeLengthCodeCount; i < S_CODE_ORDER.Length; i++) { - _codeLengthTreeCodeLength[s_codeOrder[i]] = 0; + _codeLengthTreeCodeLength[S_CODE_ORDER[i]] = 0; } // create huffman tree for code length @@ -714,15 +714,15 @@ namespace SharpCompress.Compressors.Deflate64 throw new InvalidDataException("Deflate64: unknown state"); } - byte[] literalTreeCodeLength = new byte[HuffmanTree.MaxLiteralTreeElements]; - byte[] distanceTreeCodeLength = new byte[HuffmanTree.MaxDistTreeElements]; + byte[] literalTreeCodeLength = new byte[HuffmanTree.MAX_LITERAL_TREE_ELEMENTS]; + byte[] distanceTreeCodeLength = new byte[HuffmanTree.MAX_DIST_TREE_ELEMENTS]; // Create literal and distance tables Array.Copy(_codeList, 0, literalTreeCodeLength, 0, _literalLengthCodeCount); Array.Copy(_codeList, _literalLengthCodeCount, distanceTreeCodeLength, 0, _distanceCodeCount); // Make sure there is an end-of-block code, otherwise how could we ever end? - if (literalTreeCodeLength[HuffmanTree.EndOfBlockCode] == 0) + if (literalTreeCodeLength[HuffmanTree.END_OF_BLOCK_CODE] == 0) { throw new InvalidDataException(); } diff --git a/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs b/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs index b5889319..2dbc4442 100644 --- a/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs +++ b/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs @@ -19,32 +19,32 @@ namespace SharpCompress.Compressors.Deflate64 // With Deflate64 we can have up to a 65536 length as well as up to a 65538 distance. This means we need a Window that is at // least 131074 bytes long so we have space to retrieve up to a full 64kb in lookback and place it in our buffer without // overwriting existing data. OutputWindow requires that the WindowSize be an exponent of 2, so we round up to 2^18. - private const int WindowSize = 262144; - private const int WindowMask = 262143; + private const int WINDOW_SIZE = 262144; + private const int WINDOW_MASK = 262143; - private readonly byte[] _window = new byte[WindowSize]; // The window is 2^18 bytes + private readonly byte[] _window = new byte[WINDOW_SIZE]; // The window is 2^18 bytes private int _end; // this is the position to where we should write next byte private int _bytesUsed; // The number of bytes in the output window which is not consumed. /// Add a byte to output window. public void Write(byte b) { - Debug.Assert(_bytesUsed < WindowSize, "Can't add byte when window is full!"); + Debug.Assert(_bytesUsed < WINDOW_SIZE, "Can't add byte when window is full!"); _window[_end++] = b; - _end &= WindowMask; + _end &= WINDOW_MASK; ++_bytesUsed; } public void WriteLengthDistance(int length, int distance) { - Debug.Assert((_bytesUsed + length) <= WindowSize, "No Enough space"); + Debug.Assert((_bytesUsed + length) <= WINDOW_SIZE, "No Enough space"); // move backwards distance bytes in the output stream, // and copy length bytes from this position to the output stream. _bytesUsed += length; - int copyStart = (_end - distance) & WindowMask; // start position for coping. + int copyStart = (_end - distance) & WINDOW_MASK; // start position for coping. - int border = WindowSize - length; + int border = WINDOW_SIZE - length; if (copyStart <= border && _end < border) { if (length <= distance) @@ -70,8 +70,8 @@ namespace SharpCompress.Compressors.Deflate64 while (length-- > 0) { _window[_end++] = _window[copyStart++]; - _end &= WindowMask; - copyStart &= WindowMask; + _end &= WINDOW_MASK; + copyStart &= WINDOW_MASK; } } } @@ -82,11 +82,11 @@ namespace SharpCompress.Compressors.Deflate64 /// public int CopyFrom(InputBuffer input, int length) { - length = Math.Min(Math.Min(length, WindowSize - _bytesUsed), input.AvailableBytes); + length = Math.Min(Math.Min(length, WINDOW_SIZE - _bytesUsed), input.AvailableBytes); int copied; // We might need wrap around to copy all bytes. - int tailLen = WindowSize - _end; + int tailLen = WINDOW_SIZE - _end; if (length > tailLen) { // copy the first part @@ -103,13 +103,13 @@ namespace SharpCompress.Compressors.Deflate64 copied = input.CopyTo(_window, _end, length); } - _end = (_end + copied) & WindowMask; + _end = (_end + copied) & WINDOW_MASK; _bytesUsed += copied; return copied; } /// Free space in output window. - public int FreeBytes => WindowSize - _bytesUsed; + public int FreeBytes => WINDOW_SIZE - _bytesUsed; /// Bytes not consumed in output window. public int AvailableBytes => _bytesUsed; @@ -117,32 +117,32 @@ namespace SharpCompress.Compressors.Deflate64 /// Copy the decompressed bytes to output array. public int CopyTo(byte[] output, int offset, int length) { - int copy_end; + int copyEnd; if (length > _bytesUsed) { // we can copy all the decompressed bytes out - copy_end = _end; + copyEnd = _end; length = _bytesUsed; } else { - copy_end = (_end - _bytesUsed + length) & WindowMask; // copy length of bytes + copyEnd = (_end - _bytesUsed + length) & WINDOW_MASK; // copy length of bytes } int copied = length; - int tailLen = length - copy_end; + int tailLen = length - copyEnd; if (tailLen > 0) { // this means we need to copy two parts separately // copy tailLen bytes from the end of output window - Array.Copy(_window, WindowSize - tailLen, + Array.Copy(_window, WINDOW_SIZE - tailLen, output, offset, tailLen); offset += tailLen; - length = copy_end; + length = copyEnd; } - Array.Copy(_window, copy_end - length, output, offset, length); + Array.Copy(_window, copyEnd - length, output, offset, length); _bytesUsed -= copied; Debug.Assert(_bytesUsed >= 0, "check this function and find why we copied more bytes than we have"); return copied; diff --git a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs index c9c6fd21..1921ebab 100644 --- a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs @@ -43,10 +43,10 @@ namespace SharpCompress.Compressors.LZMA { private static int FindCoderIndexForOutStreamIndex(CFolder folderInfo, int outStreamIndex) { - for (int coderIndex = 0; coderIndex < folderInfo.Coders.Count; coderIndex++) + for (int coderIndex = 0; coderIndex < folderInfo._coders.Count; coderIndex++) { - var coderInfo = folderInfo.Coders[coderIndex]; - outStreamIndex -= coderInfo.NumOutStreams; + var coderInfo = folderInfo._coders[coderIndex]; + outStreamIndex -= coderInfo._numOutStreams; if (outStreamIndex < 0) { return coderIndex; @@ -64,11 +64,11 @@ namespace SharpCompress.Compressors.LZMA primaryOutStreamIndex = -1; for (int outStreamIndex = 0, coderIndex = 0; - coderIndex < folderInfo.Coders.Count; + coderIndex < folderInfo._coders.Count; coderIndex++) { for (int coderOutStreamIndex = 0; - coderOutStreamIndex < folderInfo.Coders[coderIndex].NumOutStreams; + coderOutStreamIndex < folderInfo._coders[coderIndex]._numOutStreams; coderOutStreamIndex++, outStreamIndex++) { if (folderInfo.FindBindPairForOutStream(outStreamIndex) < 0) @@ -94,8 +94,8 @@ namespace SharpCompress.Compressors.LZMA private static Stream CreateDecoderStream(Stream[] packStreams, long[] packSizes, Stream[] outStreams, CFolder folderInfo, int coderIndex, IPasswordProvider pass) { - var coderInfo = folderInfo.Coders[coderIndex]; - if (coderInfo.NumOutStreams != 1) + var coderInfo = folderInfo._coders[coderIndex]; + if (coderInfo._numOutStreams != 1) { throw new NotSupportedException("Multiple output streams are not supported."); } @@ -103,23 +103,23 @@ namespace SharpCompress.Compressors.LZMA int inStreamId = 0; for (int i = 0; i < coderIndex; i++) { - inStreamId += folderInfo.Coders[i].NumInStreams; + inStreamId += folderInfo._coders[i]._numInStreams; } int outStreamId = 0; for (int i = 0; i < coderIndex; i++) { - outStreamId += folderInfo.Coders[i].NumOutStreams; + outStreamId += folderInfo._coders[i]._numOutStreams; } - Stream[] inStreams = new Stream[coderInfo.NumInStreams]; + Stream[] inStreams = new Stream[coderInfo._numInStreams]; for (int i = 0; i < inStreams.Length; i++, inStreamId++) { int bindPairIndex = folderInfo.FindBindPairForInStream(inStreamId); if (bindPairIndex >= 0) { - int pairedOutIndex = folderInfo.BindPairs[bindPairIndex].OutIndex; + int pairedOutIndex = folderInfo._bindPairs[bindPairIndex]._outIndex; if (outStreams[pairedOutIndex] != null) { @@ -153,8 +153,8 @@ namespace SharpCompress.Compressors.LZMA } } - long unpackSize = folderInfo.UnpackSizes[outStreamId]; - return DecoderRegistry.CreateDecoderStream(coderInfo.MethodId, inStreams, coderInfo.Props, pass, unpackSize); + long unpackSize = folderInfo._unpackSizes[outStreamId]; + return DecoderRegistry.CreateDecoderStream(coderInfo._methodId, inStreams, coderInfo._props, pass, unpackSize); } internal static Stream CreateDecoderStream(Stream inStream, long startPos, long[] packSizes, CFolder folderInfo, @@ -165,14 +165,14 @@ namespace SharpCompress.Compressors.LZMA throw new NotSupportedException("Unsupported stream binding structure."); } - Stream[] inStreams = new Stream[folderInfo.PackStreams.Count]; - for (int j = 0; j < folderInfo.PackStreams.Count; j++) + Stream[] inStreams = new Stream[folderInfo._packStreams.Count]; + for (int j = 0; j < folderInfo._packStreams.Count; j++) { inStreams[j] = new BufferedSubStream(inStream, startPos, packSizes[j]); startPos += packSizes[j]; } - Stream[] outStreams = new Stream[folderInfo.UnpackSizes.Count]; + Stream[] outStreams = new Stream[folderInfo._unpackSizes.Count]; int primaryCoderIndex, primaryOutStreamIndex; FindPrimaryOutStreamIndex(folderInfo, out primaryCoderIndex, out primaryOutStreamIndex); diff --git a/src/SharpCompress/Compressors/LZMA/Registry.cs b/src/SharpCompress/Compressors/LZMA/Registry.cs index 9c95a5ae..edc02854 100644 --- a/src/SharpCompress/Compressors/LZMA/Registry.cs +++ b/src/SharpCompress/Compressors/LZMA/Registry.cs @@ -25,7 +25,7 @@ namespace SharpCompress.Compressors.LZMA internal static Stream CreateDecoderStream(CMethodId id, Stream[] inStreams, byte[] info, IPasswordProvider pass, long limit) { - switch (id.Id) + switch (id._id) { case K_COPY: if (info != null) @@ -37,7 +37,7 @@ namespace SharpCompress.Compressors.LZMA case K_LZMA2: return new LzmaStream(info, inStreams.Single(), -1, limit); #if !NO_CRYPTO - case CMethodId.kAESId: + case CMethodId.K_AES_ID: return new AesDecoderStream(inStreams.Single(), info, pass, limit); #endif case K_BCJ: diff --git a/src/SharpCompress/Writers/Tar/TarWriter.cs b/src/SharpCompress/Writers/Tar/TarWriter.cs index 61e98ffd..8c782366 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.cs @@ -83,7 +83,7 @@ namespace SharpCompress.Writers.Tar TarHeader header = new TarHeader(WriterOptions.ArchiveEncoding); - header.LastModifiedTime = modificationTime ?? TarHeader.Epoch; + header.LastModifiedTime = modificationTime ?? TarHeader.EPOCH; header.Name = NormalizeFilename(filename); header.Size = realSize; header.Write(OutputStream); diff --git a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs index 0a388651..1f1e6466 100644 --- a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs +++ b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs @@ -44,7 +44,7 @@ namespace SharpCompress.Writers.Zip var extralength = zip64 ? (2 + 2 + 8 + 8 + 8 + 4) : 0; var version = (byte)(zip64 ? 45 : 20); // Version 20 required for deflate/encryption - HeaderFlags flags = Equals(archiveEncoding.GetEncoding(), Encoding.UTF8) ? HeaderFlags.EFS : HeaderFlags.None; + HeaderFlags flags = Equals(archiveEncoding.GetEncoding(), Encoding.UTF8) ? HeaderFlags.Efs : HeaderFlags.None; if (!outputStream.CanSeek) { // Cannot use data descriptors with zip64: diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index f41e0b8e..89a00c3c 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -174,7 +174,7 @@ namespace SharpCompress.Writers.Zip { OutputStream.Write(new byte[] { 63, 0 }, 0, 2); //version says we used PPMd or LZMA } - HeaderFlags flags = Equals(WriterOptions.ArchiveEncoding.GetEncoding(), Encoding.UTF8) ? HeaderFlags.EFS : 0; + HeaderFlags flags = Equals(WriterOptions.ArchiveEncoding.GetEncoding(), Encoding.UTF8) ? HeaderFlags.Efs : 0; if (!OutputStream.CanSeek) { flags |= HeaderFlags.UsePostDataDescriptor;