From 970e31a1b12e575fa3ef5f9fdaaaad9d640bd417 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 20 Dec 2022 13:45:47 +0000 Subject: [PATCH] cleanup and run csharpier --- .config/dotnet-tools.json | 6 +- .github/workflows/dotnetcore.yml | 2 +- build/Program.cs | 119 +- src/SharpCompress/Algorithms/Adler32.cs | 107 +- src/SharpCompress/Archives/AbstractArchive.cs | 47 +- .../Archives/AbstractWritableArchive.cs | 72 +- src/SharpCompress/Archives/ArchiveFactory.cs | 34 +- .../Archives/ArchiveVolumeFactory.cs | 11 +- .../Archives/GZip/GZipArchive.cs | 88 +- .../Archives/GZip/GZipArchiveEntry.cs | 5 +- .../Archives/GZip/GZipWritableArchiveEntry.cs | 11 +- src/SharpCompress/Archives/IArchive.cs | 4 +- src/SharpCompress/Archives/IArchiveEntry.cs | 2 +- .../Archives/IArchiveEntryExtensions.cs | 52 +- .../Archives/IArchiveExtensions.cs | 9 +- .../Archives/IArchiveExtractionListener.cs | 2 +- src/SharpCompress/Archives/IArchiveFactory.cs | 4 +- .../Archives/IMultiArchiveFactory.cs | 9 +- .../Archives/IWritableArchive.cs | 10 +- .../Archives/IWritableArchiveEntry.cs | 2 +- .../Archives/IWritableArchiveExtensions.cs | 63 +- .../Archives/Rar/FileInfoRarArchiveVolume.cs | 8 +- .../Archives/Rar/FileInfoRarFilePart.cs | 15 +- .../Archives/Rar/RarArchive.Extensions.cs | 2 +- src/SharpCompress/Archives/Rar/RarArchive.cs | 66 +- .../Archives/Rar/RarArchiveEntry.cs | 22 +- .../Archives/Rar/RarArchiveEntryFactory.cs | 14 +- .../Archives/Rar/RarArchiveVolumeFactory.cs | 30 +- .../Archives/Rar/SeekableFilePart.cs | 12 +- .../Archives/Rar/StreamRarArchiveVolume.cs | 12 +- .../Archives/SevenZip/SevenZipArchive.cs | 84 +- .../Archives/SevenZip/SevenZipArchiveEntry.cs | 5 +- src/SharpCompress/Archives/Tar/TarArchive.cs | 114 +- .../Archives/Tar/TarArchiveEntry.cs | 9 +- .../Archives/Tar/TarWritableArchiveEntry.cs | 12 +- src/SharpCompress/Archives/Zip/ZipArchive.cs | 129 +- .../Archives/Zip/ZipArchiveEntry.cs | 5 +- .../Archives/Zip/ZipArchiveVolumeFactory.cs | 18 +- .../Archives/Zip/ZipWritableArchiveEntry.cs | 11 +- src/SharpCompress/Common/ArchiveEncoding.cs | 9 +- src/SharpCompress/Common/ArchiveException.cs | 7 +- .../Common/ArchiveExtractionEventArgs.cs | 2 +- src/SharpCompress/Common/ArchiveType.cs | 2 +- .../Common/CompressedBytesReadEventArgs.cs | 7 +- src/SharpCompress/Common/CompressionType.cs | 2 +- .../Common/CryptographicException.cs | 7 +- src/SharpCompress/Common/Entry.cs | 5 +- src/SharpCompress/Common/EntryStream.cs | 12 +- .../Common/ExtractionException.cs | 12 +- src/SharpCompress/Common/ExtractionMethods.cs | 64 +- src/SharpCompress/Common/ExtractionOptions.cs | 13 +- .../FilePartExtractionBeginEventArgs.cs | 2 +- src/SharpCompress/Common/FlagUtility.cs | 24 +- src/SharpCompress/Common/GZip/GZipEntry.cs | 2 +- src/SharpCompress/Common/GZip/GZipFilePart.cs | 3 +- src/SharpCompress/Common/GZip/GZipVolume.cs | 4 +- src/SharpCompress/Common/IEntry.Extensions.cs | 10 +- .../Common/IncompleteArchiveException.cs | 7 +- .../Common/InvalidFormatException.cs | 12 +- .../Common/MultiVolumeExtractionException.cs | 11 +- .../MultipartStreamRequiredException.cs | 7 +- src/SharpCompress/Common/OptionsBase.cs | 5 +- .../Common/PasswordProtectedException.cs | 13 +- .../Common/Rar/Headers/AVHeader.cs | 2 +- .../Common/Rar/Headers/ArchiveCryptHeader.cs | 14 +- .../Common/Rar/Headers/ArchiveHeader.cs | 9 +- .../Common/Rar/Headers/CommentHeader.cs | 2 +- .../Common/Rar/Headers/EndArchiveHeader.cs | 6 +- .../Common/Rar/Headers/FileHeader.cs | 52 +- .../Common/Rar/Headers/FileNameDecoder.cs | 14 +- src/SharpCompress/Common/Rar/Headers/Flags.cs | 2 +- .../Common/Rar/Headers/MarkHeader.cs | 37 +- .../Common/Rar/Headers/NewSubHeaderType.cs | 2 +- .../Common/Rar/Headers/ProtectHeader.cs | 2 +- .../Common/Rar/Headers/RarHeader.cs | 8 +- .../Common/Rar/Headers/RarHeaderFactory.cs | 177 +- .../Common/Rar/Headers/SignHeader.cs | 2 +- .../Common/Rar/RarCrcBinaryReader.cs | 7 +- .../Common/Rar/RarCryptoBinaryReader.cs | 5 +- src/SharpCompress/Common/Rar/RarEntry.cs | 17 +- src/SharpCompress/Common/Rar/RarFilePart.cs | 3 +- src/SharpCompress/Common/Rar/RarRijndael.cs | 26 +- src/SharpCompress/Common/Rar/RarVolume.cs | 37 +- .../Common/ReaderExtractionEventArgs.cs | 2 +- .../Common/SevenZip/ArchiveDatabase.cs | 16 +- .../Common/SevenZip/ArchiveReader.cs | 316 ++- .../Common/SevenZip/CBindPair.cs | 2 +- .../Common/SevenZip/CCoderInfo.cs | 2 +- .../Common/SevenZip/CFileItem.cs | 2 +- .../Common/SevenZip/CMethodId.cs | 2 +- .../Common/SevenZip/CStreamSwitch.cs | 2 +- .../Common/SevenZip/DataReader.cs | 22 +- .../Common/SevenZip/SevenZipEntry.cs | 5 +- .../Common/SevenZip/SevenZipFilePart.cs | 40 +- .../Common/SevenZip/SevenZipVolume.cs | 4 +- .../Common/Tar/Headers/EntryType.cs | 2 +- .../Common/Tar/Headers/TarHeader.cs | 38 +- src/SharpCompress/Common/Tar/TarEntry.cs | 12 +- src/SharpCompress/Common/Tar/TarFilePart.cs | 5 +- .../Common/Tar/TarHeaderFactory.cs | 16 +- .../Common/Tar/TarReadOnlySubStream.cs | 12 +- src/SharpCompress/Common/Tar/TarVolume.cs | 4 +- src/SharpCompress/Common/Volume.cs | 5 +- .../Common/Zip/Headers/DirectoryEndHeader.cs | 14 +- .../Zip/Headers/DirectoryEntryHeader.cs | 21 +- .../Common/Zip/Headers/HeaderFlags.cs | 5 +- .../Common/Zip/Headers/IgnoreHeader.cs | 11 +- .../Common/Zip/Headers/LocalEntryHeader.cs | 14 +- .../Headers/LocalEntryHeaderExtraFactory.cs | 49 +- .../Common/Zip/Headers/SplitHeader.cs | 7 +- .../Zip/Headers/Zip64DirectoryEndHeader.cs | 14 +- .../Headers/Zip64DirectoryEndLocatorHeader.cs | 7 +- .../Common/Zip/Headers/ZipFileEntry.cs | 15 +- .../Common/Zip/Headers/ZipHeader.cs | 2 +- .../Common/Zip/Headers/ZipHeaderType.cs | 2 +- .../Zip/PkwareTraditionalCryptoStream.cs | 14 +- .../Zip/PkwareTraditionalEncryptionData.cs | 21 +- .../Common/Zip/SeekableZipFilePart.cs | 15 +- .../Common/Zip/SeekableZipHeaderFactory.cs | 22 +- .../Common/Zip/StreamingZipFilePart.cs | 18 +- .../Common/Zip/StreamingZipHeaderFactory.cs | 24 +- .../Common/Zip/WinzipAesCryptoStream.cs | 29 +- .../Common/Zip/WinzipAesEncryptionData.cs | 26 +- .../Common/Zip/WinzipAesKeySize.cs | 2 +- .../Common/Zip/ZipCompressionMethod.cs | 2 +- src/SharpCompress/Common/Zip/ZipEntry.cs | 53 +- src/SharpCompress/Common/Zip/ZipFilePart.cs | 180 +- .../Common/Zip/ZipHeaderFactory.cs | 146 +- src/SharpCompress/Common/Zip/ZipVolume.cs | 4 +- .../Compressors/ADC/ADCStream.cs | 15 +- .../Compressors/BZip2/BZip2Constants.cs | 566 ++++- .../Compressors/BZip2/BZip2Stream.cs | 14 +- .../Compressors/BZip2/CBZip2InputStream.cs | 156 +- .../Compressors/BZip2/CBZip2OutputStream.cs | 216 +- src/SharpCompress/Compressors/BZip2/CRC.cs | 258 ++- .../Compressors/CompressionMode.cs | 2 +- .../Compressors/Deflate/CRC32.cs | 12 +- .../Compressors/Deflate/DeflateManager.cs | 326 ++- .../Compressors/Deflate/DeflateStream.cs | 35 +- .../Compressors/Deflate/FlushType.cs | 6 +- .../Compressors/Deflate/GZipStream.cs | 41 +- .../Compressors/Deflate/InfTree.cs | 1934 +++++++++++++++-- .../Compressors/Deflate/Inflate.cs | 202 +- src/SharpCompress/Compressors/Deflate/Tree.cs | 995 +++++++-- src/SharpCompress/Compressors/Deflate/Zlib.cs | 800 ++++++- .../Compressors/Deflate/ZlibBaseStream.cs | 113 +- .../Compressors/Deflate/ZlibCodec.cs | 183 +- .../Compressors/Deflate/ZlibConstants.cs | 28 +- .../Compressors/Deflate/ZlibStream.cs | 26 +- .../Compressors/Deflate64/Deflate64Stream.cs | 28 +- .../Compressors/Deflate64/DeflateInput.cs | 3 +- .../Deflate64/FastEncoderStatus.cs | 941 +++++++- .../Compressors/Deflate64/HuffmanTree.cs | 26 +- .../Compressors/Deflate64/InflaterManaged.cs | 204 +- .../Compressors/Deflate64/InflaterState.cs | 28 +- .../Compressors/Deflate64/InputBuffer.cs | 15 +- .../Compressors/Deflate64/OutputWindow.cs | 12 +- .../Compressors/Filters/BCJ2Filter.cs | 31 +- .../Compressors/Filters/BCJFilter.cs | 32 +- .../Compressors/Filters/BranchExecFilter.cs | 94 +- .../Compressors/Filters/Filter.cs | 8 +- .../Compressors/LZMA/AesDecoderStream.cs | 10 +- .../Compressors/LZMA/Bcj2DecoderStream.cs | 8 +- .../Compressors/LZMA/BitVector.cs | 5 +- src/SharpCompress/Compressors/LZMA/CRC.cs | 8 +- .../Compressors/LZMA/DecoderStream.cs | 93 +- src/SharpCompress/Compressors/LZMA/ICoder.cs | 23 +- .../Compressors/LZMA/LZ/LzBinTree.cs | 55 +- .../Compressors/LZMA/LZ/LzInWindow.cs | 9 +- .../Compressors/LZMA/LZ/LzOutWindow.cs | 2 +- .../Compressors/LZMA/LZipStream.cs | 40 +- src/SharpCompress/Compressors/LZMA/Log.cs | 2 +- .../Compressors/LZMA/LzmaBase.cs | 6 +- .../Compressors/LZMA/LzmaDecoder.cs | 107 +- .../Compressors/LZMA/LzmaEncoder.cs | 603 +++-- .../Compressors/LZMA/LzmaEncoderProperties.cs | 57 +- .../Compressors/LZMA/LzmaStream.cs | 53 +- .../Compressors/LZMA/RangeCoder/RangeCoder.cs | 5 +- .../LZMA/RangeCoder/RangeCoderBit.cs | 22 +- .../LZMA/RangeCoder/RangeCoderBitTree.cs | 31 +- .../Compressors/LZMA/Registry.cs | 11 +- .../LZMA/Utilites/CrcBuilderStream.cs | 12 +- .../LZMA/Utilites/CrcCheckStream.cs | 10 +- .../LZMA/Utilites/IPasswordProvider.cs | 2 +- .../Compressors/PPMd/H/FreqData.cs | 5 +- .../Compressors/PPMd/H/ModelPPM.cs | 174 +- .../Compressors/PPMd/H/PPMContext.cs | 71 +- .../Compressors/PPMd/H/Pointer.cs | 5 +- .../Compressors/PPMd/H/RangeCoder.cs | 26 +- .../Compressors/PPMd/H/RarMemBlock.cs | 15 +- .../Compressors/PPMd/H/RarNode.cs | 5 +- .../Compressors/PPMd/H/SEE2Context.cs | 20 +- src/SharpCompress/Compressors/PPMd/H/State.cs | 18 +- .../Compressors/PPMd/H/StateRef.cs | 14 +- .../Compressors/PPMd/H/SubAllocator.cs | 46 +- .../Compressors/PPMd/I1/Allocator.cs | 35 +- .../Compressors/PPMd/I1/Coder.cs | 16 +- .../Compressors/PPMd/I1/MemoryNode.cs | 27 +- .../Compressors/PPMd/I1/Model.cs | 154 +- .../PPMd/I1/ModelRestorationMethod.cs | 2 +- .../Compressors/PPMd/I1/Pointer.cs | 48 +- .../Compressors/PPMd/I1/PpmContext.cs | 187 +- .../Compressors/PPMd/I1/PpmState.cs | 25 +- .../Compressors/PPMd/I1/See2Context.cs | 2 +- .../Compressors/PPMd/PpmdProperties.cs | 27 +- .../Compressors/PPMd/PpmdStream.cs | 12 +- .../Compressors/PPMd/PpmdVersion.cs | 2 +- .../Rar/MultiVolumeReadOnlyStream.cs | 40 +- src/SharpCompress/Compressors/Rar/RarCRC.cs | 2 +- .../Compressors/Rar/RarCrcStream.cs | 9 +- .../Compressors/Rar/RarStream.cs | 17 +- .../Rar/UnpackV1/Decode/AudioVariables.cs | 2 +- .../Rar/UnpackV1/Decode/BitDecode.cs | 7 +- .../Rar/UnpackV1/Decode/CodeType.cs | 2 +- .../Compressors/Rar/UnpackV1/Decode/Decode.cs | 7 +- .../Rar/UnpackV1/Decode/DistDecode.cs | 7 +- .../Rar/UnpackV1/Decode/FilterType.cs | 13 +- .../Rar/UnpackV1/Decode/LitDecode.cs | 7 +- .../Rar/UnpackV1/Decode/LowDistDecode.cs | 7 +- .../Rar/UnpackV1/Decode/MultDecode.cs | 7 +- .../Rar/UnpackV1/Decode/PackDef.cs | 3 +- .../Rar/UnpackV1/Decode/RepDecode.cs | 7 +- .../Rar/UnpackV1/PPM/BlockTypes.cs | 2 +- .../Compressors/Rar/UnpackV1/Unpack.cs | 115 +- .../Compressors/Rar/UnpackV1/Unpack15.cs | 216 +- .../Compressors/Rar/UnpackV1/Unpack20.cs | 190 +- .../Compressors/Rar/UnpackV1/Unpack50.cs | 112 +- .../Compressors/Rar/UnpackV1/UnpackFilter.cs | 14 +- .../Compressors/Rar/UnpackV1/UnpackInline.cs | 3 +- .../Compressors/Rar/UnpackV1/UnpackUtility.cs | 20 +- .../Rar/UnpackV2017/BitInput.getbits_cpp.cs | 9 +- .../Rar/UnpackV2017/BitInput.getbits_hpp.cs | 7 +- .../FragmentedWindow.unpack50frag_cpp.cs | 21 +- .../Rar/UnpackV2017/PackDef.compress_hpp.cs | 2 - .../Compressors/Rar/UnpackV2017/Unpack.cs | 14 +- .../Rar/UnpackV2017/Unpack.rawint_hpp.cs | 5 +- .../Rar/UnpackV2017/Unpack.unpack15_cpp.cs | 232 +- .../Rar/UnpackV2017/Unpack.unpack20_cpp.cs | 189 +- .../Rar/UnpackV2017/Unpack.unpack30_cpp.cs | 8 +- .../Rar/UnpackV2017/Unpack.unpack50_cpp.cs | 122 +- .../Rar/UnpackV2017/Unpack.unpack_cpp.cs | 67 +- .../UnpackV2017/Unpack.unpackinline_cpp.cs | 6 +- .../Compressors/Rar/VM/BitInput.cs | 34 +- src/SharpCompress/Compressors/Rar/VM/RarVM.cs | 458 ++-- .../Compressors/Rar/VM/VMCmdFlags.cs | 31 +- .../Compressors/Rar/VM/VMCommands.cs | 23 +- .../Compressors/Rar/VM/VMFlags.cs | 2 +- .../Compressors/Rar/VM/VMOpType.cs | 2 +- .../Compressors/Rar/VM/VMPreparedCommand.cs | 2 +- .../Compressors/Rar/VM/VMPreparedOperand.cs | 2 +- .../Compressors/Rar/VM/VMPreparedProgram.cs | 2 +- .../Rar/VM/VMStandardFilterSignature.cs | 2 +- .../Compressors/Rar/VM/VMStandardFilters.cs | 2 +- .../Compressors/Xz/BinaryUtils.cs | 1 + src/SharpCompress/Compressors/Xz/CheckType.cs | 2 +- src/SharpCompress/Compressors/Xz/Crc64.cs | 1 - .../Compressors/Xz/Filters/ArmFilter.cs | 5 +- .../Compressors/Xz/Filters/ArmThumbFilter.cs | 6 +- .../Compressors/Xz/Filters/BlockFilter.cs | 25 +- .../Compressors/Xz/Filters/IA64Filter.cs | 6 +- .../Compressors/Xz/Filters/Lzma2Filter.cs | 4 +- .../Compressors/Xz/Filters/PowerPCFilter.cs | 1 - .../Compressors/Xz/Filters/SparcFilter.cs | 14 +- .../Compressors/Xz/Filters/X86Filter.cs | 5 +- src/SharpCompress/Compressors/Xz/XZBlock.cs | 21 +- src/SharpCompress/Compressors/Xz/XZFooter.cs | 4 +- src/SharpCompress/Compressors/Xz/XZHeader.cs | 4 +- src/SharpCompress/Compressors/Xz/XZIndex.cs | 5 +- .../Xz/XZIndexMarkerReachedException.cs | 4 +- src/SharpCompress/Compressors/Xz/XZStream.cs | 9 +- src/SharpCompress/Crypto/Crc32Stream.cs | 17 +- src/SharpCompress/Crypto/CryptoException.cs | 22 +- .../Crypto/DataLengthException.cs | 23 +- src/SharpCompress/Crypto/IBlockCipher.cs | 2 +- src/SharpCompress/Crypto/ICipherParameters.cs | 6 +- src/SharpCompress/Crypto/KeyParameter.cs | 13 +- src/SharpCompress/Crypto/RijndaelEngine.cs | 1530 +++++++++++-- src/SharpCompress/Factories/Factory.cs | 12 +- src/SharpCompress/Factories/GZipFactory.cs | 27 +- src/SharpCompress/Factories/IFactory.cs | 3 +- src/SharpCompress/Factories/RarFactory.cs | 9 +- .../Factories/SevenZipFactory.cs | 16 +- src/SharpCompress/Factories/TarFactory.cs | 33 +- src/SharpCompress/Factories/ZipFactory.cs | 21 +- src/SharpCompress/IO/BufferedSubStream.cs | 11 +- .../IO/CountingWritableSubStream.cs | 12 +- src/SharpCompress/IO/ListeningStream.cs | 18 +- src/SharpCompress/IO/MarkingBinaryReader.cs | 13 +- src/SharpCompress/IO/NonDisposingStream.cs | 15 +- src/SharpCompress/IO/ReadOnlySubStream.cs | 14 +- src/SharpCompress/IO/RewindableStream.cs | 1 - src/SharpCompress/IO/SourceStream.cs | 44 +- src/SharpCompress/Lazy.cs | 2 +- .../Polyfills/StringExtensions.cs | 2 +- src/SharpCompress/Readers/AbstractReader.cs | 73 +- src/SharpCompress/Readers/GZip/GZipReader.cs | 3 +- src/SharpCompress/Readers/IReader.cs | 2 +- .../Readers/IReaderExtensions.cs | 52 +- src/SharpCompress/Readers/IReaderFactory.cs | 1 - .../Readers/Rar/MultiVolumeRarReader.cs | 29 +- .../Readers/Rar/NonSeekableStreamFilePart.cs | 7 +- src/SharpCompress/Readers/Rar/RarReader.cs | 20 +- .../Readers/Rar/RarReaderEntry.cs | 2 +- .../Readers/Rar/RarReaderVolume.cs | 4 +- .../Readers/Rar/SingleVolumeRarReader.cs | 8 +- src/SharpCompress/Readers/ReaderFactory.cs | 19 +- src/SharpCompress/Readers/ReaderOptions.cs | 2 +- src/SharpCompress/Readers/ReaderProgress.cs | 4 +- src/SharpCompress/Readers/Tar/TarReader.cs | 59 +- src/SharpCompress/Readers/Zip/ZipReader.cs | 19 +- src/SharpCompress/Utility.cs | 57 +- src/SharpCompress/Writers/AbstractWriter.cs | 2 +- src/SharpCompress/Writers/GZip/GZipWriter.cs | 11 +- .../Writers/GZip/GZipWriterOptions.cs | 10 +- src/SharpCompress/Writers/IWriter.cs | 2 +- .../Writers/IWriterExtensions.cs | 25 +- src/SharpCompress/Writers/Tar/TarWriter.cs | 27 +- .../Writers/Tar/TarWriterOptions.cs | 2 +- src/SharpCompress/Writers/WriterFactory.cs | 9 +- src/SharpCompress/Writers/WriterOptions.cs | 3 +- .../Writers/Zip/ZipCentralDirectoryEntry.cs | 33 +- src/SharpCompress/Writers/Zip/ZipWriter.cs | 224 +- .../Writers/Zip/ZipWriterEntryOptions.cs | 9 +- .../Writers/Zip/ZipWriterOptions.cs | 21 +- tests/SharpCompress.Test/ADCTest.cs | 51 +- tests/SharpCompress.Test/ArchiveTests.cs | 203 +- .../Filters/BranchExecTests.cs | 1232 ++++++++++- .../GZip/GZipArchiveTests.cs | 18 +- .../GZip/GZipReaderTests.cs | 7 +- .../GZip/GZipWriterTests.cs | 55 +- .../Mocks/FlushOnDisposeStream.cs | 6 +- .../Mocks/ForwardOnlyStream.cs | 2 +- tests/SharpCompress.Test/Mocks/TestStream.cs | 5 +- .../SharpCompress.Test/Rar/RarArchiveTests.cs | 384 ++-- .../Rar/RarHeaderFactoryTest.cs | 16 +- .../SharpCompress.Test/Rar/RarReaderTests.cs | 257 ++- tests/SharpCompress.Test/ReaderTests.cs | 36 +- .../SevenZip/SevenZipArchiveTests.cs | 65 +- .../Streams/LzmaStreamTests.cs | 528 ++++- .../Streams/ZlibBaseStreamTests.cs | 43 +- .../SharpCompress.Test/Tar/TarArchiveTests.cs | 66 +- .../SharpCompress.Test/Tar/TarReaderTests.cs | 98 +- .../SharpCompress.Test/Tar/TarWriterTests.cs | 48 +- tests/SharpCompress.Test/TestBase.cs | 44 +- tests/SharpCompress.Test/WriterTests.cs | 28 +- tests/SharpCompress.Test/Xz/Crc32Tests.cs | 4 +- tests/SharpCompress.Test/Xz/Crc64Tests.cs | 4 +- .../SharpCompress.Test/Xz/Filters/BCJTests.cs | 1 + tests/SharpCompress.Test/Xz/XZBlockTests.cs | 10 +- tests/SharpCompress.Test/Xz/XZHeaderTests.cs | 15 +- tests/SharpCompress.Test/Xz/XZIndexTests.cs | 21 +- tests/SharpCompress.Test/Xz/XZTestsBase.cs | 1185 +++++++++- tests/SharpCompress.Test/Zip/Zip64Tests.cs | 69 +- .../SharpCompress.Test/Zip/ZipArchiveTests.cs | 292 ++- .../SharpCompress.Test/Zip/ZipReaderTests.cs | 197 +- .../SharpCompress.Test/Zip/ZipWriterTests.cs | 51 +- 356 files changed, 17199 insertions(+), 5194 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 034cae45..d1ac7eef 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -2,10 +2,10 @@ "version": 1, "isRoot": true, "tools": { - "dotnet-format": { - "version": "4.1.131201", + "csharpier": { + "version": "0.21.0", "commands": [ - "dotnet-format" + "dotnet-csharpier" ] } } diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 53aa0a9a..530ec766 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-dotnet@v3 with: dotnet-version: 7.0.x - - run: dotnet run -p build/build.csproj + - run: dotnet run --project build/build.csproj - uses: actions/upload-artifact@v3 with: name: ${{ matrix.os }}-sharpcompress.nupkg diff --git a/build/Program.cs b/build/Program.cs index f5a31098..358082aa 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; @@ -7,76 +7,75 @@ using static Bullseye.Targets; using static SimpleExec.Command; const string Clean = "clean"; -const string Format = "format"; const string Build = "build"; const string Test = "test"; const string Publish = "publish"; -Target(Clean, - ForEach("**/bin", "**/obj"), - dir => - { - IEnumerable GetDirectories(string d) - { - return Glob.Directories(".", d); - } +Target( + Clean, + ForEach("**/bin", "**/obj"), + dir => + { + IEnumerable GetDirectories(string d) + { + return Glob.Directories(".", d); + } - void RemoveDirectory(string d) - { - if (Directory.Exists(d)) - { - Console.WriteLine(d); - Directory.Delete(d, true); - } - } + void RemoveDirectory(string d) + { + if (Directory.Exists(d)) + { + Console.WriteLine(d); + Directory.Delete(d, true); + } + } - foreach (var d in GetDirectories(dir)) - { - RemoveDirectory(d); - } - }); + foreach (var d in GetDirectories(dir)) + { + RemoveDirectory(d); + } + } +); -Target(Format, - () => - { - Run("dotnet", "tool restore"); - Run("dotnet", "format --check"); - }); +Target( + Build, + () => + { + Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release"); + } +); -Target(Build, - DependsOn(Format), - framework => - { - Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release"); - }); +Target( + Test, + DependsOn(Build), + ForEach("net7.0", "net462"), + framework => + { + IEnumerable GetFiles(string d) + { + return Glob.Files(".", d); + } -Target(Test, - DependsOn(Build), - ForEach("net7.0", "net462"), - framework => - { - IEnumerable GetFiles(string d) - { - return Glob.Files(".", d); - } + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && framework == "net462") + { + return; + } - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && framework == "net462") - { - return; - } + foreach (var file in GetFiles("**/*.Test.csproj")) + { + Run("dotnet", $"test {file} -c Release -f {framework}"); + } + } +); - foreach (var file in GetFiles("**/*.Test.csproj")) - { - Run("dotnet", $"test {file} -c Release -f {framework}"); - } - }); - -Target(Publish, - DependsOn(Test), - () => - { - Run("dotnet", "pack src/SharpCompress/SharpCompress.csproj -c Release -o artifacts/"); - }); +Target( + Publish, + DependsOn(Test), + () => + { + Run("dotnet", "pack src/SharpCompress/SharpCompress.csproj -c Release -o artifacts/"); + } +); Target("default", DependsOn(Publish), () => Console.WriteLine("Done!")); diff --git a/src/SharpCompress/Algorithms/Adler32.cs b/src/SharpCompress/Algorithms/Adler32.cs index e98c864e..0d4de7fa 100644 --- a/src/SharpCompress/Algorithms/Adler32.cs +++ b/src/SharpCompress/Algorithms/Adler32.cs @@ -82,7 +82,7 @@ namespace SharpCompress.Algorithms public static int EvenReduceSum(Vector256 accumulator) { Vector128 vsum = Sse2.Add(accumulator.GetLower(), accumulator.GetUpper()); // add upper lane to lower lane - vsum = Sse2.Add(vsum, Sse2.Shuffle(vsum, 0b_11_10_11_10)); // add high to low + vsum = Sse2.Add(vsum, Sse2.Shuffle(vsum, 0b_11_10_11_10)); // add high to low // Vector128.ToScalar() isn't optimized pre-net5.0 https://github.com/dotnet/runtime/pull/37882 return Sse2.ConvertToInt32(vsum); @@ -107,11 +107,42 @@ namespace SharpCompress.Algorithms private const int BlockSize = 1 << 5; // The C# compiler emits this as a compile-time constant embedded in the PE file. - private static ReadOnlySpan Tap1Tap2 => new byte[] - { - 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, // tap1 - 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 // tap2 - }; + private static ReadOnlySpan Tap1Tap2 => + new byte[] + { + 32, + 31, + 30, + 29, + 28, + 27, + 26, + 25, + 24, + 23, + 22, + 21, + 20, + 19, + 18, + 17, // tap1 + 16, + 15, + 14, + 13, + 12, + 11, + 10, + 9, + 8, + 7, + 6, + 5, + 4, + 3, + 2, + 1 // tap2 + }; #endif /// @@ -120,8 +151,7 @@ namespace SharpCompress.Algorithms /// The readonly span of bytes. /// The . [MethodImpl(InliningOptions.ShortMethod)] - public static uint Calculate(ReadOnlySpan buffer) - => Calculate(SeedValue, buffer); + public static uint Calculate(ReadOnlySpan buffer) => Calculate(SeedValue, buffer); /// /// Calculates the Adler32 checksum with the bytes taken from the span and seed. @@ -181,7 +211,7 @@ namespace SharpCompress.Algorithms while (blocks > 0) { - uint n = NMAX / BlockSize; /* The NMAX constraint. */ + uint n = NMAX / BlockSize; /* The NMAX constraint. */ if (n > blocks) { n = blocks; @@ -206,23 +236,28 @@ namespace SharpCompress.Algorithms // Horizontally add the bytes for s1, multiply-adds the // bytes by [ 32, 31, 30, ... ] for s2. - v_s1 = Sse2.Add(v_s1, Sse2.SumAbsoluteDifferences(bytes1, zero).AsUInt32()); + v_s1 = Sse2.Add( + v_s1, + Sse2.SumAbsoluteDifferences(bytes1, zero).AsUInt32() + ); Vector128 mad1 = Ssse3.MultiplyAddAdjacent(bytes1, tap1); v_s2 = Sse2.Add(v_s2, Sse2.MultiplyAddAdjacent(mad1, ones).AsUInt32()); - v_s1 = Sse2.Add(v_s1, Sse2.SumAbsoluteDifferences(bytes2, zero).AsUInt32()); + v_s1 = Sse2.Add( + v_s1, + Sse2.SumAbsoluteDifferences(bytes2, zero).AsUInt32() + ); Vector128 mad2 = Ssse3.MultiplyAddAdjacent(bytes2, tap2); v_s2 = Sse2.Add(v_s2, Sse2.MultiplyAddAdjacent(mad2, ones).AsUInt32()); localBufferPtr += BlockSize; - } - while (--n > 0); + } while (--n > 0); v_s2 = Sse2.Add(v_s2, Sse2.ShiftLeftLogical(v_ps, 5)); // Sum epi32 ints v_s1(s2) and accumulate in s1(s2). - const byte S2301 = 0b1011_0001; // A B C D -> B A D C - const byte S1032 = 0b0100_1110; // A B C D -> C D A B + const byte S2301 = 0b1011_0001; // A B C D -> B A D C + const byte S1032 = 0b0100_1110; // A B C D -> C D A B v_s1 = Sse2.Add(v_s1, Sse2.Shuffle(v_s1, S1032)); @@ -262,7 +297,40 @@ namespace SharpCompress.Algorithms Vector256 zero = Vector256.Zero; var dot3v = Vector256.Create((short)1); - var dot2v = Vector256.Create(32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1); + var dot2v = Vector256.Create( + 32, + 31, + 30, + 29, + 28, + 27, + 26, + 25, + 24, + 23, + 22, + 21, + 20, + 19, + 18, + 17, + 16, + 15, + 14, + 13, + 12, + 11, + 10, + 9, + 8, + 7, + 6, + 5, + 4, + 3, + 2, + 1 + ); // Process n blocks of data. At most NMAX data bytes can be // processed before s2 must be reduced modulo BASE. @@ -325,7 +393,12 @@ namespace SharpCompress.Algorithms } } - private static unsafe void HandleLeftOver(byte* localBufferPtr, uint length, ref uint s1, ref uint s2) + private static unsafe void HandleLeftOver( + byte* localBufferPtr, + uint length, + ref uint s1, + ref uint s2 + ) { if (length >= 16) { diff --git a/src/SharpCompress/Archives/AbstractArchive.cs b/src/SharpCompress/Archives/AbstractArchive.cs index b6c0ef76..16b07864 100644 --- a/src/SharpCompress/Archives/AbstractArchive.cs +++ b/src/SharpCompress/Archives/AbstractArchive.cs @@ -42,13 +42,17 @@ namespace SharpCompress.Archives lazyVolumes = new LazyReadOnlyCollection(Enumerable.Empty()); lazyEntries = new LazyReadOnlyCollection(Enumerable.Empty()); } + #nullable enable public ArchiveType Type { get; } void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry) { - EntryExtractionBegin?.Invoke(this, new ArchiveExtractionEventArgs(entry)); + EntryExtractionBegin?.Invoke( + this, + new ArchiveExtractionEventArgs(entry) + ); } void IArchiveExtractionListener.FireEntryExtractionEnd(IArchiveEntry entry) @@ -78,12 +82,14 @@ namespace SharpCompress.Archives /// /// The total size of the files compressed in the archive. /// - public virtual long TotalSize => Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); + public virtual long TotalSize => + Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); /// /// The total size of the files as uncompressed in the archive. /// - public virtual long TotalUncompressSize => Entries.Aggregate(0L, (total, cf) => total + cf.Size); + public virtual long TotalUncompressSize => + Entries.Aggregate(0L, (total, cf) => total + cf.Size); protected abstract IEnumerable LoadVolumes(SourceStream srcStream); protected abstract IEnumerable LoadEntries(IEnumerable volumes); @@ -110,21 +116,34 @@ namespace SharpCompress.Archives lazyVolumes.EnsureFullyLoaded(); } - void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes) + void IExtractionListener.FireCompressedBytesRead( + long currentPartCompressedBytes, + long compressedReadBytes + ) { - CompressedBytesRead?.Invoke(this, new CompressedBytesReadEventArgs( - currentFilePartCompressedBytesRead: currentPartCompressedBytes, - compressedBytesRead: compressedReadBytes - )); + CompressedBytesRead?.Invoke( + this, + new CompressedBytesReadEventArgs( + currentFilePartCompressedBytesRead: currentPartCompressedBytes, + compressedBytesRead: compressedReadBytes + ) + ); } - void IExtractionListener.FireFilePartExtractionBegin(string name, long size, long compressedSize) + void IExtractionListener.FireFilePartExtractionBegin( + string name, + long size, + long compressedSize + ) { - FilePartExtractionBegin?.Invoke(this, new FilePartExtractionBeginEventArgs( - compressedSize: compressedSize, - size: size, - name: name - )); + FilePartExtractionBegin?.Invoke( + this, + new FilePartExtractionBeginEventArgs( + compressedSize: compressedSize, + size: size, + name: name + ) + ); } /// diff --git a/src/SharpCompress/Archives/AbstractWritableArchive.cs b/src/SharpCompress/Archives/AbstractWritableArchive.cs index 42a8213e..fc877cbd 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.cs @@ -9,7 +9,9 @@ using SharpCompress.Writers; namespace SharpCompress.Archives { - public abstract class AbstractWritableArchive : AbstractArchive, IWritableArchive + public abstract class AbstractWritableArchive + : AbstractArchive, + IWritableArchive where TEntry : IArchiveEntry where TVolume : IVolume { @@ -29,6 +31,7 @@ namespace SharpCompress.Archives archive.RebuildModifiedCollection(); } } + private readonly List newEntries = new List(); private readonly List removedEntries = new List(); @@ -36,15 +39,10 @@ namespace SharpCompress.Archives private bool hasModifications; private bool pauseRebuilding; - internal AbstractWritableArchive(ArchiveType type) - : base(type) - { - } + internal AbstractWritableArchive(ArchiveType type) : base(type) { } internal AbstractWritableArchive(ArchiveType type, SourceStream srcStream) - : base(type, srcStream) - { - } + : base(type, srcStream) { } public override ICollection Entries { @@ -75,7 +73,10 @@ namespace SharpCompress.Archives modifiedEntries.AddRange(OldEntries.Concat(newEntries)); } - private IEnumerable OldEntries { get { return base.Entries.Where(x => !removedEntries.Contains(x)); } } + private IEnumerable OldEntries + { + get { return base.Entries.Where(x => !removedEntries.Contains(x)); } + } public void RemoveEntry(TEntry entry) { @@ -91,19 +92,29 @@ namespace SharpCompress.Archives RemoveEntry((TEntry)entry); } - public TEntry AddEntry(string key, Stream source, - long size = 0, DateTime? modified = null) + public TEntry AddEntry(string key, Stream source, long size = 0, DateTime? modified = null) { return AddEntry(key, source, false, size, modified); } - IArchiveEntry IWritableArchive.AddEntry(string key, Stream source, bool closeStream, long size, DateTime? modified) + IArchiveEntry IWritableArchive.AddEntry( + string key, + Stream source, + bool closeStream, + long size, + DateTime? modified + ) { return AddEntry(key, source, closeStream, size, modified); } - public TEntry AddEntry(string key, Stream source, bool closeStream, - long size = 0, DateTime? modified = null) + public TEntry AddEntry( + string key, + Stream source, + bool closeStream, + long size = 0, + DateTime? modified = null + ) { if (key.Length > 0 && key[0] is '/' or '\\') { @@ -136,24 +147,43 @@ namespace SharpCompress.Archives public void SaveTo(Stream stream, WriterOptions options) { //reset streams of new entries - newEntries.Cast().ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin)); + newEntries + .Cast() + .ForEach(x => x.Stream.Seek(0, SeekOrigin.Begin)); SaveTo(stream, options, OldEntries, newEntries); } - protected TEntry CreateEntry(string key, Stream source, long size, DateTime? modified, - bool closeStream) + protected TEntry CreateEntry( + string key, + Stream source, + long size, + DateTime? modified, + bool closeStream + ) { if (!source.CanRead || !source.CanSeek) { - throw new ArgumentException("Streams must be readable and seekable to use the Writing Archive API"); + throw new ArgumentException( + "Streams must be readable and seekable to use the Writing Archive API" + ); } return CreateEntryInternal(key, source, size, modified, closeStream); } - protected abstract TEntry CreateEntryInternal(string key, Stream source, long size, DateTime? modified, - bool closeStream); + protected abstract TEntry CreateEntryInternal( + string key, + Stream source, + long size, + DateTime? modified, + bool closeStream + ); - protected abstract void SaveTo(Stream stream, WriterOptions options, IEnumerable oldEntries, IEnumerable newEntries); + protected abstract void SaveTo( + Stream stream, + WriterOptions options, + IEnumerable oldEntries, + IEnumerable newEntries + ); public override void Dispose() { diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs index 71c0358e..f5c5cdee 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.cs @@ -31,14 +31,13 @@ namespace SharpCompress.Archives public static IWritableArchive Create(ArchiveType type) { - var factory = Factories.Factory - .Factories + var factory = Factories.Factory.Factories .OfType() .Where(item => item.KnownArchiveType == type) .FirstOrDefault(); if (factory != null) - return factory.CreateWriteableArchive(); + return factory.CreateWriteableArchive(); throw new NotSupportedException("Cannot create Archives of type: " + type); } @@ -60,7 +59,7 @@ namespace SharpCompress.Archives /// /// public static IArchive Open(FileInfo fileInfo, ReaderOptions? options = null) - { + { options ??= new ReaderOptions { LeaveStreamOpen = false }; return FindFactory(fileInfo).Open(fileInfo, options); @@ -105,14 +104,17 @@ namespace SharpCompress.Archives firstStream.CheckNotNull(nameof(firstStream)); options ??= new ReaderOptions(); - return FindFactory(firstStream).Open(streamsArray, options); - } + return FindFactory(firstStream).Open(streamsArray, options); + } /// /// Extract to specific directory, retaining filename /// - public static void WriteToDirectory(string sourceArchive, string destinationDirectory, - ExtractionOptions? options = null) + public static void WriteToDirectory( + string sourceArchive, + string destinationDirectory, + ExtractionOptions? options = null + ) { using IArchive archive = Open(sourceArchive); foreach (IArchiveEntry entry in archive.Entries) @@ -121,8 +123,7 @@ namespace SharpCompress.Archives } } - private static T FindFactory(FileInfo finfo) - where T : IFactory + private static T FindFactory(FileInfo finfo) where T : IFactory { finfo.CheckNotNull(nameof(finfo)); using (Stream stream = finfo.OpenRead()) @@ -131,8 +132,7 @@ namespace SharpCompress.Archives } } - private static T FindFactory(Stream stream) - where T: IFactory + private static T FindFactory(Stream stream) where T : IFactory { stream.CheckNotNull(nameof(stream)); if (!stream.CanRead || !stream.CanSeek) @@ -158,7 +158,9 @@ namespace SharpCompress.Archives var extensions = string.Join(", ", factories.Select(item => item.Name)); - throw new InvalidOperationException($"Cannot determine compressed stream type. Supported Archive Formats: {extensions}"); + throw new InvalidOperationException( + $"Cannot determine compressed stream type. Supported Archive Formats: {extensions}" + ); } public static bool IsArchive(string filePath, out ArchiveType? type) @@ -180,7 +182,7 @@ namespace SharpCompress.Archives var startPosition = stream.Position; - foreach(var factory in Factories.Factory.Factories) + foreach (var factory in Factories.Factory.Factories) { stream.Position = startPosition; @@ -213,9 +215,9 @@ namespace SharpCompress.Archives public static IEnumerable GetFileParts(FileInfo part1) { part1.CheckNotNull(nameof(part1)); - yield return part1; + yield return part1; - foreach(var factory in Factory.Factories.OfType()) + foreach (var factory in Factory.Factories.OfType()) { int i = 1; FileInfo? part = factory.GetFilePart(i++, part1); diff --git a/src/SharpCompress/Archives/ArchiveVolumeFactory.cs b/src/SharpCompress/Archives/ArchiveVolumeFactory.cs index 09315b40..fc68399b 100644 --- a/src/SharpCompress/Archives/ArchiveVolumeFactory.cs +++ b/src/SharpCompress/Archives/ArchiveVolumeFactory.cs @@ -18,12 +18,19 @@ namespace SharpCompress.Archives //split 001, 002 ... Match m = Regex.Match(part1.Name, @"^(.*\.)([0-9]+)$", RegexOptions.IgnoreCase); if (m.Success) - item = new FileInfo(Path.Combine(part1.DirectoryName!, String.Concat(m.Groups[1].Value, (index + 1).ToString().PadLeft(m.Groups[2].Value.Length, '0')))); + item = new FileInfo( + Path.Combine( + part1.DirectoryName!, + String.Concat( + m.Groups[1].Value, + (index + 1).ToString().PadLeft(m.Groups[2].Value.Length, '0') + ) + ) + ); if (item != null && item.Exists) return item; return null; } - } } diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs index 845e05fb..ed1b6a6b 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs @@ -33,7 +33,13 @@ namespace SharpCompress.Archives.GZip public static GZipArchive Open(FileInfo fileInfo, ReaderOptions? readerOptions = null) { fileInfo.CheckNotNull(nameof(fileInfo)); - return new GZipArchive(new SourceStream(fileInfo, i => ArchiveVolumeFactory.GetFilePart(i, fileInfo), readerOptions ?? new ReaderOptions())); + return new GZipArchive( + new SourceStream( + fileInfo, + i => ArchiveVolumeFactory.GetFilePart(i, fileInfo), + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -41,11 +47,20 @@ namespace SharpCompress.Archives.GZip /// /// /// - public static GZipArchive Open(IEnumerable fileInfos, ReaderOptions? readerOptions = null) + public static GZipArchive Open( + IEnumerable fileInfos, + ReaderOptions? readerOptions = null + ) { fileInfos.CheckNotNull(nameof(fileInfos)); FileInfo[] files = fileInfos.ToArray(); - return new GZipArchive(new SourceStream(files[0], i => i < files.Length ? files[i] : null, readerOptions ?? new ReaderOptions())); + return new GZipArchive( + new SourceStream( + files[0], + i => i < files.Length ? files[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -53,11 +68,20 @@ namespace SharpCompress.Archives.GZip /// /// /// - public static GZipArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) + public static GZipArchive Open( + IEnumerable streams, + ReaderOptions? readerOptions = null + ) { streams.CheckNotNull(nameof(streams)); Stream[] strms = streams.ToArray(); - return new GZipArchive(new SourceStream(strms[0], i => i < strms.Length ? strms[i] : null, readerOptions ?? new ReaderOptions())); + return new GZipArchive( + new SourceStream( + strms[0], + i => i < strms.Length ? strms[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -68,7 +92,9 @@ namespace SharpCompress.Archives.GZip public static GZipArchive Open(Stream stream, ReaderOptions? readerOptions = null) { stream.CheckNotNull(nameof(stream)); - return new GZipArchive(new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions())); + return new GZipArchive( + new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions()) + ); } public static GZipArchive Create() @@ -81,10 +107,7 @@ namespace SharpCompress.Archives.GZip /// /// /// - internal GZipArchive(SourceStream srcStream) - : base(ArchiveType.Tar, srcStream) - { - } + internal GZipArchive(SourceStream srcStream) : base(ArchiveType.Tar, srcStream) { } protected override IEnumerable LoadVolumes(SourceStream srcStream) { @@ -92,6 +115,7 @@ namespace SharpCompress.Archives.GZip int idx = 0; return srcStream.Streams.Select(a => new GZipVolume(a, ReaderOptions, idx++)); } + public static bool IsGZipFile(string filePath) { return IsGZipFile(new FileInfo(filePath)); @@ -140,24 +164,36 @@ namespace SharpCompress.Archives.GZip return true; } - internal GZipArchive() - : base(ArchiveType.GZip) - { - } + internal GZipArchive() : base(ArchiveType.GZip) { } - protected override GZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified, - bool closeStream) + protected override GZipArchiveEntry CreateEntryInternal( + string filePath, + Stream source, + long size, + DateTime? modified, + bool closeStream + ) { if (Entries.Any()) { throw new InvalidOperationException("Only one entry is allowed in a GZip Archive"); } - return new GZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream); + return new GZipWritableArchiveEntry( + this, + source, + filePath, + size, + modified, + closeStream + ); } - protected override void SaveTo(Stream stream, WriterOptions options, - IEnumerable oldEntries, - IEnumerable newEntries) + protected override void SaveTo( + Stream stream, + WriterOptions options, + IEnumerable oldEntries, + IEnumerable newEntries + ) { if (Entries.Count > 1) { @@ -165,8 +201,7 @@ namespace SharpCompress.Archives.GZip } using (var writer = new GZipWriter(stream, new GZipWriterOptions(options))) { - foreach (var entry in oldEntries.Concat(newEntries) - .Where(x => !x.IsDirectory)) + foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory)) { using (var entryStream = entry.OpenEntryStream()) { @@ -176,10 +211,15 @@ namespace SharpCompress.Archives.GZip } } - protected override IEnumerable LoadEntries(IEnumerable volumes) + protected override IEnumerable LoadEntries( + IEnumerable volumes + ) { Stream stream = volumes.Single().Stream; - yield return new GZipArchiveEntry(this, new GZipFilePart(stream, ReaderOptions.ArchiveEncoding)); + yield return new GZipArchiveEntry( + this, + new GZipFilePart(stream, ReaderOptions.ArchiveEncoding) + ); } protected override IReader CreateReaderForSolidExtraction() diff --git a/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs b/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs index 237a5247..23316046 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs @@ -6,8 +6,7 @@ namespace SharpCompress.Archives.GZip { public class GZipArchiveEntry : GZipEntry, IArchiveEntry { - internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part) - : base(part) + internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part) : base(part) { Archive = archive; } @@ -31,4 +30,4 @@ namespace SharpCompress.Archives.GZip #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs b/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs index 4a315571..4f35f24d 100644 --- a/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs @@ -13,9 +13,14 @@ namespace SharpCompress.Archives.GZip private readonly bool closeStream; private readonly Stream stream; - internal GZipWritableArchiveEntry(GZipArchive archive, Stream stream, - string path, long size, DateTime? lastModified, bool closeStream) - : base(archive, null) + internal GZipWritableArchiveEntry( + GZipArchive archive, + Stream stream, + string path, + long size, + DateTime? lastModified, + bool closeStream + ) : base(archive, null) { this.stream = stream; Key = path; diff --git a/src/SharpCompress/Archives/IArchive.cs b/src/SharpCompress/Archives/IArchive.cs index 2ba84a39..acb2bf11 100644 --- a/src/SharpCompress/Archives/IArchive.cs +++ b/src/SharpCompress/Archives/IArchive.cs @@ -20,7 +20,7 @@ namespace SharpCompress.Archives /// /// Use this method to extract all entries in an archive in order. - /// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be + /// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be /// extracted sequentially for the best performance. /// IReader ExtractAllEntries(); @@ -46,4 +46,4 @@ namespace SharpCompress.Archives /// long TotalUncompressSize { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IArchiveEntry.cs b/src/SharpCompress/Archives/IArchiveEntry.cs index 43e681b4..e3351582 100644 --- a/src/SharpCompress/Archives/IArchiveEntry.cs +++ b/src/SharpCompress/Archives/IArchiveEntry.cs @@ -21,4 +21,4 @@ namespace SharpCompress.Archives /// IArchive Archive { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs index 829b8bbd..d5eac3f9 100644 --- a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs @@ -16,7 +16,11 @@ namespace SharpCompress.Archives var streamListener = (IArchiveExtractionListener)archiveEntry.Archive; streamListener.EnsureEntriesLoaded(); streamListener.FireEntryExtractionBegin(archiveEntry); - streamListener.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize); + streamListener.FireFilePartExtractionBegin( + archiveEntry.Key, + archiveEntry.Size, + archiveEntry.CompressedSize + ); var entryStream = archiveEntry.OpenEntryStream(); if (entryStream is null) { @@ -35,29 +39,41 @@ namespace SharpCompress.Archives /// /// Extract to specific directory, retaining filename /// - public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory, - ExtractionOptions? options = null) + public static void WriteToDirectory( + this IArchiveEntry entry, + string destinationDirectory, + ExtractionOptions? options = null + ) { - ExtractionMethods.WriteEntryToDirectory(entry, destinationDirectory, options, - entry.WriteToFile); + ExtractionMethods.WriteEntryToDirectory( + entry, + destinationDirectory, + options, + entry.WriteToFile + ); } /// /// Extract to specific file /// - public static void WriteToFile(this IArchiveEntry entry, - string destinationFileName, - ExtractionOptions? options = null) + public static void WriteToFile( + this IArchiveEntry entry, + string destinationFileName, + ExtractionOptions? options = null + ) { - - ExtractionMethods.WriteEntryToFile(entry, destinationFileName, options, - (x, fm) => - { - using (FileStream fs = File.Open(destinationFileName, fm)) - { - entry.WriteTo(fs); - } - }); + ExtractionMethods.WriteEntryToFile( + entry, + destinationFileName, + options, + (x, fm) => + { + using (FileStream fs = File.Open(destinationFileName, fm)) + { + entry.WriteTo(fs); + } + } + ); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IArchiveExtensions.cs b/src/SharpCompress/Archives/IArchiveExtensions.cs index 23b8a27e..c0a9e1dd 100644 --- a/src/SharpCompress/Archives/IArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveExtensions.cs @@ -8,8 +8,11 @@ namespace SharpCompress.Archives /// /// Extract to specific directory, retaining filename /// - public static void WriteToDirectory(this IArchive archive, string destinationDirectory, - ExtractionOptions? options = null) + public static void WriteToDirectory( + this IArchive archive, + string destinationDirectory, + ExtractionOptions? options = null + ) { foreach (IArchiveEntry entry in archive.Entries.Where(x => !x.IsDirectory)) { @@ -17,4 +20,4 @@ namespace SharpCompress.Archives } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IArchiveExtractionListener.cs b/src/SharpCompress/Archives/IArchiveExtractionListener.cs index 9ce07e8a..b352691e 100644 --- a/src/SharpCompress/Archives/IArchiveExtractionListener.cs +++ b/src/SharpCompress/Archives/IArchiveExtractionListener.cs @@ -8,4 +8,4 @@ namespace SharpCompress.Archives void FireEntryExtractionBegin(IArchiveEntry entry); void FireEntryExtractionEnd(IArchiveEntry entry); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IArchiveFactory.cs b/src/SharpCompress/Archives/IArchiveFactory.cs index 98014688..6ba64079 100644 --- a/src/SharpCompress/Archives/IArchiveFactory.cs +++ b/src/SharpCompress/Archives/IArchiveFactory.cs @@ -16,8 +16,8 @@ namespace SharpCompress.Archives /// /// /// - /// - /// + /// + /// /// /// /// diff --git a/src/SharpCompress/Archives/IMultiArchiveFactory.cs b/src/SharpCompress/Archives/IMultiArchiveFactory.cs index 6ba39280..7610b146 100644 --- a/src/SharpCompress/Archives/IMultiArchiveFactory.cs +++ b/src/SharpCompress/Archives/IMultiArchiveFactory.cs @@ -16,8 +16,8 @@ namespace SharpCompress.Archives /// /// /// - /// - /// + /// + /// /// /// /// @@ -35,6 +35,9 @@ namespace SharpCompress.Archives /// /// /// reading options. - IArchive Open(IReadOnlyList fileInfos, ReaderOptions? readerOptions = null); + IArchive Open( + IReadOnlyList fileInfos, + ReaderOptions? readerOptions = null + ); } } diff --git a/src/SharpCompress/Archives/IWritableArchive.cs b/src/SharpCompress/Archives/IWritableArchive.cs index 3b1b0328..02b76f66 100644 --- a/src/SharpCompress/Archives/IWritableArchive.cs +++ b/src/SharpCompress/Archives/IWritableArchive.cs @@ -8,7 +8,13 @@ namespace SharpCompress.Archives { void RemoveEntry(IArchiveEntry entry); - IArchiveEntry AddEntry(string key, Stream source, bool closeStream, long size = 0, DateTime? modified = null); + IArchiveEntry AddEntry( + string key, + Stream source, + bool closeStream, + long size = 0, + DateTime? modified = null + ); void SaveTo(Stream stream, WriterOptions options); @@ -18,4 +24,4 @@ namespace SharpCompress.Archives /// IDisposeable to resume entry rebuilding IDisposable PauseEntryRebuilding(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IWritableArchiveEntry.cs b/src/SharpCompress/Archives/IWritableArchiveEntry.cs index 044eb1c7..f3d5eb26 100644 --- a/src/SharpCompress/Archives/IWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/IWritableArchiveEntry.cs @@ -6,4 +6,4 @@ namespace SharpCompress.Archives { Stream Stream { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/IWritableArchiveExtensions.cs b/src/SharpCompress/Archives/IWritableArchiveExtensions.cs index 468622a7..1827e9e8 100644 --- a/src/SharpCompress/Archives/IWritableArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IWritableArchiveExtensions.cs @@ -6,24 +6,40 @@ namespace SharpCompress.Archives { public static class IWritableArchiveExtensions { - public static void AddEntry(this IWritableArchive writableArchive, - string entryPath, string filePath) + public static void AddEntry( + this IWritableArchive writableArchive, + string entryPath, + string filePath + ) { var fileInfo = new FileInfo(filePath); if (!fileInfo.Exists) { throw new FileNotFoundException("Could not AddEntry: " + filePath); } - writableArchive.AddEntry(entryPath, new FileInfo(filePath).OpenRead(), true, fileInfo.Length, - fileInfo.LastWriteTime); + writableArchive.AddEntry( + entryPath, + new FileInfo(filePath).OpenRead(), + true, + fileInfo.Length, + fileInfo.LastWriteTime + ); } - public static void SaveTo(this IWritableArchive writableArchive, string filePath, WriterOptions options) + public static void SaveTo( + this IWritableArchive writableArchive, + string filePath, + WriterOptions options + ) { writableArchive.SaveTo(new FileInfo(filePath), options); } - public static void SaveTo(this IWritableArchive writableArchive, FileInfo fileInfo, WriterOptions options) + public static void SaveTo( + this IWritableArchive writableArchive, + FileInfo fileInfo, + WriterOptions options + ) { using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write)) { @@ -33,25 +49,46 @@ namespace SharpCompress.Archives public static void AddAllFromDirectory( this IWritableArchive writableArchive, - string filePath, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories) + string filePath, + string searchPattern = "*.*", + SearchOption searchOption = SearchOption.AllDirectories + ) { using (writableArchive.PauseEntryRebuilding()) { - foreach (var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption)) + foreach ( + var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption) + ) { var fileInfo = new FileInfo(path); - writableArchive.AddEntry(path.Substring(filePath.Length), fileInfo.OpenRead(), true, fileInfo.Length, - fileInfo.LastWriteTime); + writableArchive.AddEntry( + path.Substring(filePath.Length), + fileInfo.OpenRead(), + true, + fileInfo.Length, + fileInfo.LastWriteTime + ); } } } - public static IArchiveEntry AddEntry(this IWritableArchive writableArchive, string key, FileInfo fileInfo) + + public static IArchiveEntry AddEntry( + this IWritableArchive writableArchive, + string key, + FileInfo fileInfo + ) { if (!fileInfo.Exists) { throw new ArgumentException("FileInfo does not exist."); } - return writableArchive.AddEntry(key, fileInfo.OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime); + return writableArchive.AddEntry( + key, + fileInfo.OpenRead(), + true, + fileInfo.Length, + fileInfo.LastWriteTime + ); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs index 1afba647..78ec29e8 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs @@ -33,7 +33,13 @@ namespace SharpCompress.Archives.Rar internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader) { - return new FileInfoRarFilePart(this, ReaderOptions.Password, markHeader, fileHeader, FileInfo); + return new FileInfoRarFilePart( + this, + ReaderOptions.Password, + markHeader, + fileHeader, + FileInfo + ); } internal override IEnumerable ReadFileParts() diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs index b2134e6d..1908c8af 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs @@ -5,8 +5,13 @@ namespace SharpCompress.Archives.Rar { internal sealed class FileInfoRarFilePart : SeekableFilePart { - internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, string? password, MarkHeader mh, FileHeader fh, FileInfo fi) - : base(mh, fh, volume.Index, volume.Stream, password) + internal FileInfoRarFilePart( + FileInfoRarArchiveVolume volume, + string? password, + MarkHeader mh, + FileHeader fh, + FileInfo fi + ) : base(mh, fh, volume.Index, volume.Stream, password) { FileInfo = fi; } @@ -15,11 +20,7 @@ namespace SharpCompress.Archives.Rar internal override string FilePartName { - get - { - return "Rar File: " + FileInfo.FullName - + " File Entry: " + FileHeader.FileName; - } + get { return "Rar File: " + FileInfo.FullName + " File Entry: " + FileHeader.FileName; } } } } diff --git a/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs b/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs index 7eefef9c..41abe3f4 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.Extensions.cs @@ -20,4 +20,4 @@ namespace SharpCompress.Archives.Rar return archive.Volumes.First().IsMultiVolume; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index 6d43a46b..67a4d070 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -11,22 +11,19 @@ using SharpCompress.Readers.Rar; namespace SharpCompress.Archives.Rar { - public class - RarArchive : AbstractArchive + public class RarArchive : AbstractArchive { - internal Lazy UnpackV2017 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); - internal Lazy UnpackV1 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); - + internal Lazy UnpackV2017 { get; } = + new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); + internal Lazy UnpackV1 { get; } = + new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); /// /// Constructor with a SourceStream able to handle FileInfo and Streams. /// /// /// - internal RarArchive(SourceStream srcStream) - : base(ArchiveType.Rar, srcStream) - { - } + internal RarArchive(SourceStream srcStream) : base(ArchiveType.Rar, srcStream) { } protected override IEnumerable LoadEntries(IEnumerable volumes) { @@ -44,7 +41,9 @@ namespace SharpCompress.Archives.Rar streams[1].Position = 0; base.SrcStream.Position = 0; - return srcStream.Streams.Select(a => new StreamRarArchiveVolume(a, ReaderOptions, idx++)); + return srcStream.Streams.Select( + a => new StreamRarArchiveVolume(a, ReaderOptions, idx++) + ); } else //split mode or single file return new StreamRarArchiveVolume(base.SrcStream, ReaderOptions, idx++).AsEnumerable(); @@ -72,7 +71,13 @@ namespace SharpCompress.Archives.Rar { filePath.CheckNotNullOrEmpty(nameof(filePath)); FileInfo fileInfo = new FileInfo(filePath); - return new RarArchive(new SourceStream(fileInfo, i => RarArchiveVolumeFactory.GetFilePart(i, fileInfo), options ?? new ReaderOptions())); + return new RarArchive( + new SourceStream( + fileInfo, + i => RarArchiveVolumeFactory.GetFilePart(i, fileInfo), + options ?? new ReaderOptions() + ) + ); } /// @@ -83,7 +88,13 @@ namespace SharpCompress.Archives.Rar public static RarArchive Open(FileInfo fileInfo, ReaderOptions? options = null) { fileInfo.CheckNotNull(nameof(fileInfo)); - return new RarArchive(new SourceStream(fileInfo, i => RarArchiveVolumeFactory.GetFilePart(i, fileInfo), options ?? new ReaderOptions())); + return new RarArchive( + new SourceStream( + fileInfo, + i => RarArchiveVolumeFactory.GetFilePart(i, fileInfo), + options ?? new ReaderOptions() + ) + ); } /// @@ -94,7 +105,9 @@ namespace SharpCompress.Archives.Rar public static RarArchive Open(Stream stream, ReaderOptions? options = null) { stream.CheckNotNull(nameof(stream)); - return new RarArchive(new SourceStream(stream, i => null, options ?? new ReaderOptions())); + return new RarArchive( + new SourceStream(stream, i => null, options ?? new ReaderOptions()) + ); } /// @@ -102,11 +115,20 @@ namespace SharpCompress.Archives.Rar /// /// /// - public static RarArchive Open(IEnumerable fileInfos, ReaderOptions? readerOptions = null) + public static RarArchive Open( + IEnumerable fileInfos, + ReaderOptions? readerOptions = null + ) { fileInfos.CheckNotNull(nameof(fileInfos)); FileInfo[] files = fileInfos.ToArray(); - return new RarArchive(new SourceStream(files[0], i => i < files.Length ? files[i] : null, readerOptions ?? new ReaderOptions())); + return new RarArchive( + new SourceStream( + files[0], + i => i < files.Length ? files[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -114,14 +136,22 @@ namespace SharpCompress.Archives.Rar /// /// /// - public static RarArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) + public static RarArchive Open( + IEnumerable streams, + ReaderOptions? readerOptions = null + ) { streams.CheckNotNull(nameof(streams)); Stream[] strms = streams.ToArray(); - return new RarArchive(new SourceStream(strms[0], i => i < strms.Length ? strms[i] : null, readerOptions ?? new ReaderOptions())); + return new RarArchive( + new SourceStream( + strms[0], + i => i < strms.Length ? strms[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } - public static bool IsRarFile(string filePath) { return IsRarFile(new FileInfo(filePath)); diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs index fb2ba0f8..a5f4d038 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntry.cs @@ -16,7 +16,11 @@ namespace SharpCompress.Archives.Rar private readonly RarArchive archive; private readonly ReaderOptions readerOptions; - internal RarArchiveEntry(RarArchive archive, IEnumerable parts, ReaderOptions readerOptions) + internal RarArchiveEntry( + RarArchive archive, + IEnumerable parts, + ReaderOptions readerOptions + ) { this.parts = parts.ToList(); this.archive = archive; @@ -63,10 +67,18 @@ namespace SharpCompress.Archives.Rar { if (IsRarV3) { - return new RarStream(archive.UnpackV1.Value, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive)); + return new RarStream( + archive.UnpackV1.Value, + FileHeader, + new MultiVolumeReadOnlyStream(Parts.Cast(), archive) + ); } - return new RarStream(archive.UnpackV2017.Value, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast(), archive)); + return new RarStream( + archive.UnpackV2017.Value, + FileHeader, + new MultiVolumeReadOnlyStream(Parts.Cast(), archive) + ); } public bool IsComplete @@ -82,7 +94,9 @@ namespace SharpCompress.Archives.Rar { if (!readerOptions.DisableCheckIncomplete && !IsComplete) { - throw new IncompleteArchiveException("ArchiveEntry is incomplete and cannot perform this operation."); + throw new IncompleteArchiveException( + "ArchiveEntry is incomplete and cannot perform this operation." + ); } } } diff --git a/src/SharpCompress/Archives/Rar/RarArchiveEntryFactory.cs b/src/SharpCompress/Archives/Rar/RarArchiveEntryFactory.cs index 2d471c18..e345e8d3 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveEntryFactory.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveEntryFactory.cs @@ -17,7 +17,9 @@ namespace SharpCompress.Archives.Rar } } - private static IEnumerable> GetMatchedFileParts(IEnumerable parts) + private static IEnumerable> GetMatchedFileParts( + IEnumerable parts + ) { var groupedParts = new List(); foreach (RarFilePart fp in GetFileParts(parts)) @@ -36,9 +38,11 @@ namespace SharpCompress.Archives.Rar } } - internal static IEnumerable GetEntries(RarArchive archive, - IEnumerable rarParts, - ReaderOptions readerOptions) + internal static IEnumerable GetEntries( + RarArchive archive, + IEnumerable rarParts, + ReaderOptions readerOptions + ) { foreach (var groupedParts in GetMatchedFileParts(rarParts)) { @@ -46,4 +50,4 @@ namespace SharpCompress.Archives.Rar } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs b/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs index abbd73b3..58ab96eb 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs @@ -17,15 +17,38 @@ namespace SharpCompress.Archives.Rar FileInfo? item = null; //new style rar - ..part1 | /part01 | part001 .... - Match m = Regex.Match(part1.Name, @"^(.*\.part)([0-9]+)(\.rar)$", RegexOptions.IgnoreCase); + Match m = Regex.Match( + part1.Name, + @"^(.*\.part)([0-9]+)(\.rar)$", + RegexOptions.IgnoreCase + ); if (m.Success) - item = new FileInfo(Path.Combine(part1.DirectoryName!, String.Concat(m.Groups[1].Value, (index + 1).ToString().PadLeft(m.Groups[2].Value.Length, '0'), m.Groups[3].Value))); + item = new FileInfo( + Path.Combine( + part1.DirectoryName!, + String.Concat( + m.Groups[1].Value, + (index + 1).ToString().PadLeft(m.Groups[2].Value.Length, '0'), + m.Groups[3].Value + ) + ) + ); else { //old style - ...rar, .r00, .r01 ... m = Regex.Match(part1.Name, @"^(.*\.r)(ar|[0-9]+)$", RegexOptions.IgnoreCase); if (m.Success) - item = new FileInfo(Path.Combine(part1.DirectoryName!, String.Concat(m.Groups[1].Value, index == 0 ? "ar" : (index - 1).ToString().PadLeft(m.Groups[2].Value.Length, '0')))); + item = new FileInfo( + Path.Combine( + part1.DirectoryName!, + String.Concat( + m.Groups[1].Value, + index == 0 + ? "ar" + : (index - 1).ToString().PadLeft(m.Groups[2].Value.Length, '0') + ) + ) + ); else //split .001, .002 .... return ArchiveVolumeFactory.GetFilePart(index, part1); } @@ -35,6 +58,5 @@ namespace SharpCompress.Archives.Rar return null; //no more items } - } } diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs index 1e4758ad..601c9788 100644 --- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs @@ -9,8 +9,13 @@ namespace SharpCompress.Archives.Rar private readonly Stream stream; private readonly string? password; - internal SeekableFilePart(MarkHeader mh, FileHeader fh, int index, Stream stream, string? password) - : base(mh, fh, index) + internal SeekableFilePart( + MarkHeader mh, + FileHeader fh, + int index, + Stream stream, + string? password + ) : base(mh, fh, index) { this.stream = stream; this.password = password; @@ -26,6 +31,7 @@ namespace SharpCompress.Archives.Rar return stream; } - internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; + internal override string FilePartName => + "Unknown Stream - File Entry: " + FileHeader.FileName; } } diff --git a/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs index 68def3f7..ac5dc5de 100644 --- a/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/StreamRarArchiveVolume.cs @@ -10,9 +10,7 @@ namespace SharpCompress.Archives.Rar internal class StreamRarArchiveVolume : RarVolume { internal StreamRarArchiveVolume(Stream stream, ReaderOptions options, int index = 0) - : base(StreamingMode.Seekable, stream, options, index) - { - } + : base(StreamingMode.Seekable, stream, options, index) { } internal override IEnumerable ReadFileParts() { @@ -21,7 +19,13 @@ namespace SharpCompress.Archives.Rar internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader) { - return new SeekableFilePart(markHeader, fileHeader, this.Index, Stream, ReaderOptions.Password); + return new SeekableFilePart( + markHeader, + fileHeader, + this.Index, + Stream, + ReaderOptions.Password + ); } } } diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index 276f1399..99c455d7 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -15,6 +15,7 @@ namespace SharpCompress.Archives.SevenZip public class SevenZipArchive : AbstractArchive { private ArchiveDatabase database; + /// /// Constructor expects a filepath to an existing file. /// @@ -34,7 +35,13 @@ namespace SharpCompress.Archives.SevenZip public static SevenZipArchive Open(FileInfo fileInfo, ReaderOptions readerOptions = null) { fileInfo.CheckNotNull("fileInfo"); - return new SevenZipArchive(new SourceStream(fileInfo, i => ArchiveVolumeFactory.GetFilePart(i, fileInfo), readerOptions ?? new ReaderOptions())); + return new SevenZipArchive( + new SourceStream( + fileInfo, + i => ArchiveVolumeFactory.GetFilePart(i, fileInfo), + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -42,11 +49,20 @@ namespace SharpCompress.Archives.SevenZip /// /// /// - public static SevenZipArchive Open(IEnumerable fileInfos, ReaderOptions readerOptions = null) + public static SevenZipArchive Open( + IEnumerable fileInfos, + ReaderOptions readerOptions = null + ) { fileInfos.CheckNotNull(nameof(fileInfos)); FileInfo[] files = fileInfos.ToArray(); - return new SevenZipArchive(new SourceStream(files[0], i => i < files.Length ? files[i] : null, readerOptions ?? new ReaderOptions())); + return new SevenZipArchive( + new SourceStream( + files[0], + i => i < files.Length ? files[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -54,11 +70,20 @@ namespace SharpCompress.Archives.SevenZip /// /// /// - public static SevenZipArchive Open(IEnumerable streams, ReaderOptions readerOptions = null) + public static SevenZipArchive Open( + IEnumerable streams, + ReaderOptions readerOptions = null + ) { streams.CheckNotNull(nameof(streams)); Stream[] strms = streams.ToArray(); - return new SevenZipArchive(new SourceStream(strms[0], i => i < strms.Length ? strms[i] : null, readerOptions ?? new ReaderOptions())); + return new SevenZipArchive( + new SourceStream( + strms[0], + i => i < strms.Length ? strms[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -69,7 +94,9 @@ namespace SharpCompress.Archives.SevenZip public static SevenZipArchive Open(Stream stream, ReaderOptions readerOptions = null) { stream.CheckNotNull("stream"); - return new SevenZipArchive(new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions())); + return new SevenZipArchive( + new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions()) + ); } /// @@ -77,10 +104,7 @@ namespace SharpCompress.Archives.SevenZip /// /// /// - internal SevenZipArchive(SourceStream srcStream) - : base(ArchiveType.SevenZip, srcStream) - { - } + internal SevenZipArchive(SourceStream srcStream) : base(ArchiveType.SevenZip, srcStream) { } protected override IEnumerable LoadVolumes(SourceStream srcStream) { @@ -106,12 +130,11 @@ namespace SharpCompress.Archives.SevenZip } } - internal SevenZipArchive() - : base(ArchiveType.SevenZip) - { - } + internal SevenZipArchive() : base(ArchiveType.SevenZip) { } - protected override IEnumerable LoadEntries(IEnumerable volumes) + protected override IEnumerable LoadEntries( + IEnumerable volumes + ) { var stream = volumes.Single().Stream; LoadFactory(stream); @@ -119,9 +142,14 @@ namespace SharpCompress.Archives.SevenZip for (int i = 0; i < database._files.Count; i++) { var file = database._files[i]; - entries[i] = new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file, ReaderOptions.ArchiveEncoding)); + entries[i] = new SevenZipArchiveEntry( + this, + new SevenZipFilePart(stream, database, i, file, ReaderOptions.ArchiveEncoding) + ); } - foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder)) + foreach ( + var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder) + ) { var isSolid = false; foreach (var entry in group) @@ -157,7 +185,8 @@ namespace SharpCompress.Archives.SevenZip } } - private static ReadOnlySpan SIGNATURE => new byte[] { (byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C }; + private static ReadOnlySpan SIGNATURE => + new byte[] { (byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C }; private static bool SignatureMatch(Stream stream) { @@ -171,7 +200,14 @@ namespace SharpCompress.Archives.SevenZip return new SevenZipReader(ReaderOptions, this); } - public override bool IsSolid { get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; } } + public override bool IsSolid + { + get + { + return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() + > 1; + } + } public override long TotalSize { @@ -205,7 +241,9 @@ namespace SharpCompress.Archives.SevenZip { yield return dir; } - foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder)) + foreach ( + var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder) + ) { currentFolder = group.Key; if (group.Key is null) @@ -214,7 +252,11 @@ namespace SharpCompress.Archives.SevenZip } else { - currentStream = archive.database.GetFolderStream(stream, currentFolder, new PasswordProvider(Options.Password)); + currentStream = archive.database.GetFolderStream( + stream, + currentFolder, + new PasswordProvider(Options.Password) + ); } foreach (var entry in group) { diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs index ea80b5cb..c276eade 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs @@ -5,8 +5,7 @@ namespace SharpCompress.Archives.SevenZip { public class SevenZipArchiveEntry : SevenZipEntry, IArchiveEntry { - internal SevenZipArchiveEntry(SevenZipArchive archive, SevenZipFilePart part) - : base(part) + internal SevenZipArchiveEntry(SevenZipArchive archive, SevenZipFilePart part) : base(part) { Archive = archive; } @@ -25,4 +24,4 @@ namespace SharpCompress.Archives.SevenZip /// public bool IsAnti => FilePart.Header.IsAnti; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs index 51bdbc1f..1357660f 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.cs @@ -34,7 +34,13 @@ namespace SharpCompress.Archives.Tar public static TarArchive Open(FileInfo fileInfo, ReaderOptions? readerOptions = null) { fileInfo.CheckNotNull(nameof(fileInfo)); - return new TarArchive(new SourceStream(fileInfo, i => ArchiveVolumeFactory.GetFilePart(i, fileInfo), readerOptions ?? new ReaderOptions())); + return new TarArchive( + new SourceStream( + fileInfo, + i => ArchiveVolumeFactory.GetFilePart(i, fileInfo), + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -42,11 +48,20 @@ namespace SharpCompress.Archives.Tar /// /// /// - public static TarArchive Open(IEnumerable fileInfos, ReaderOptions? readerOptions = null) + public static TarArchive Open( + IEnumerable fileInfos, + ReaderOptions? readerOptions = null + ) { fileInfos.CheckNotNull(nameof(fileInfos)); FileInfo[] files = fileInfos.ToArray(); - return new TarArchive(new SourceStream(files[0], i => i < files.Length ? files[i] : null, readerOptions ?? new ReaderOptions())); + return new TarArchive( + new SourceStream( + files[0], + i => i < files.Length ? files[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -54,11 +69,20 @@ namespace SharpCompress.Archives.Tar /// /// /// - public static TarArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) + public static TarArchive Open( + IEnumerable streams, + ReaderOptions? readerOptions = null + ) { streams.CheckNotNull(nameof(streams)); Stream[] strms = streams.ToArray(); - return new TarArchive(new SourceStream(strms[0], i => i < strms.Length ? strms[i] : null, readerOptions ?? new ReaderOptions())); + return new TarArchive( + new SourceStream( + strms[0], + i => i < strms.Length ? strms[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -69,7 +93,9 @@ namespace SharpCompress.Archives.Tar public static TarArchive Open(Stream stream, ReaderOptions? readerOptions = null) { stream.CheckNotNull(nameof(stream)); - return new TarArchive(new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions())); + return new TarArchive( + new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions()) + ); } public static bool IsTarFile(string filePath) @@ -95,12 +121,13 @@ namespace SharpCompress.Archives.Tar { TarHeader tarHeader = new TarHeader(new ArchiveEncoding()); bool readSucceeded = tarHeader.Read(new BinaryReader(stream)); - bool isEmptyArchive = tarHeader.Name.Length == 0 && tarHeader.Size == 0 && Enum.IsDefined(typeof(EntryType), tarHeader.EntryType); + bool isEmptyArchive = + tarHeader.Name.Length == 0 + && tarHeader.Size == 0 + && Enum.IsDefined(typeof(EntryType), tarHeader.EntryType); return readSucceeded || isEmptyArchive; } - catch - { - } + catch { } return false; } @@ -116,21 +143,21 @@ namespace SharpCompress.Archives.Tar /// /// /// - internal TarArchive(SourceStream srcStream) - : base(ArchiveType.Tar, srcStream) - { - } + internal TarArchive(SourceStream srcStream) : base(ArchiveType.Tar, srcStream) { } - internal TarArchive() - : base(ArchiveType.Tar) - { - } + internal TarArchive() : base(ArchiveType.Tar) { } protected override IEnumerable LoadEntries(IEnumerable volumes) { Stream stream = volumes.Single().Stream; TarHeader? previousHeader = null; - foreach (TarHeader? header in TarHeaderFactory.ReadHeader(StreamingMode.Seekable, stream, ReaderOptions.ArchiveEncoding)) + foreach ( + TarHeader? header in TarHeaderFactory.ReadHeader( + StreamingMode.Seekable, + stream, + ReaderOptions.ArchiveEncoding + ) + ) { if (header != null) { @@ -142,8 +169,11 @@ namespace SharpCompress.Archives.Tar { if (previousHeader != null) { - var entry = new TarArchiveEntry(this, new TarFilePart(previousHeader, stream), - CompressionType.None); + var entry = new TarArchiveEntry( + this, + new TarFilePart(previousHeader, stream), + CompressionType.None + ); var oldStreamPos = stream.Position; @@ -155,7 +185,9 @@ namespace SharpCompress.Archives.Tar memoryStream.Position = 0; var bytes = memoryStream.ToArray(); - header.Name = ReaderOptions.ArchiveEncoding.Decode(bytes).TrimNulls(); + header.Name = ReaderOptions.ArchiveEncoding + .Decode(bytes) + .TrimNulls(); } } @@ -163,7 +195,11 @@ namespace SharpCompress.Archives.Tar previousHeader = null; } - yield return new TarArchiveEntry(this, new TarFilePart(header, stream), CompressionType.None); + yield return new TarArchiveEntry( + this, + new TarFilePart(header, stream), + CompressionType.None + ); } } } @@ -174,21 +210,35 @@ namespace SharpCompress.Archives.Tar return new TarArchive(); } - protected override TarArchiveEntry CreateEntryInternal(string filePath, Stream source, - long size, DateTime? modified, bool closeStream) + protected override TarArchiveEntry CreateEntryInternal( + string filePath, + Stream source, + long size, + DateTime? modified, + bool closeStream + ) { - return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified, - closeStream); + return new TarWritableArchiveEntry( + this, + source, + CompressionType.Unknown, + filePath, + size, + modified, + closeStream + ); } - protected override void SaveTo(Stream stream, WriterOptions options, - IEnumerable oldEntries, - IEnumerable newEntries) + protected override void SaveTo( + Stream stream, + WriterOptions options, + IEnumerable oldEntries, + IEnumerable newEntries + ) { using (var writer = new TarWriter(stream, new TarWriterOptions(options))) { - foreach (var entry in oldEntries.Concat(newEntries) - .Where(x => !x.IsDirectory)) + foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory)) { using (var entryStream = entry.OpenEntryStream()) { diff --git a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs index 51a0a49b..99a2498f 100644 --- a/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs +++ b/src/SharpCompress/Archives/Tar/TarArchiveEntry.cs @@ -7,8 +7,11 @@ namespace SharpCompress.Archives.Tar { public class TarArchiveEntry : TarEntry, IArchiveEntry { - internal TarArchiveEntry(TarArchive archive, TarFilePart part, CompressionType compressionType) - : base(part, compressionType) + internal TarArchiveEntry( + TarArchive archive, + TarFilePart part, + CompressionType compressionType + ) : base(part, compressionType) { Archive = archive; } @@ -26,4 +29,4 @@ namespace SharpCompress.Archives.Tar #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs index 1f96ca3d..7c6cfbcb 100644 --- a/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs @@ -13,9 +13,15 @@ namespace SharpCompress.Archives.Tar private readonly bool closeStream; private readonly Stream stream; - internal TarWritableArchiveEntry(TarArchive archive, Stream stream, CompressionType compressionType, - string path, long size, DateTime? lastModified, bool closeStream) - : base(archive, null, compressionType) + internal TarWritableArchiveEntry( + TarArchive archive, + Stream stream, + CompressionType compressionType, + string path, + long size, + DateTime? lastModified, + bool closeStream + ) : base(archive, null, compressionType) { this.stream = stream; Key = path; diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 97f83e02..f5c52863 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -18,6 +18,7 @@ namespace SharpCompress.Archives.Zip { #nullable disable private readonly SeekableZipHeaderFactory headerFactory; + #nullable enable /// @@ -31,10 +32,12 @@ namespace SharpCompress.Archives.Zip /// /// /// - internal ZipArchive(SourceStream srcStream) - : base(ArchiveType.Zip, srcStream) + internal ZipArchive(SourceStream srcStream) : base(ArchiveType.Zip, srcStream) { - headerFactory = new SeekableZipHeaderFactory(srcStream.ReaderOptions.Password, srcStream.ReaderOptions.ArchiveEncoding); + headerFactory = new SeekableZipHeaderFactory( + srcStream.ReaderOptions.Password, + srcStream.ReaderOptions.ArchiveEncoding + ); } /// @@ -56,7 +59,13 @@ namespace SharpCompress.Archives.Zip public static ZipArchive Open(FileInfo fileInfo, ReaderOptions? readerOptions = null) { fileInfo.CheckNotNull(nameof(fileInfo)); - return new ZipArchive(new SourceStream(fileInfo, i => ZipArchiveVolumeFactory.GetFilePart(i, fileInfo), readerOptions ?? new ReaderOptions())); + return new ZipArchive( + new SourceStream( + fileInfo, + i => ZipArchiveVolumeFactory.GetFilePart(i, fileInfo), + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -64,11 +73,20 @@ namespace SharpCompress.Archives.Zip /// /// /// - public static ZipArchive Open(IEnumerable fileInfos, ReaderOptions? readerOptions = null) + public static ZipArchive Open( + IEnumerable fileInfos, + ReaderOptions? readerOptions = null + ) { fileInfos.CheckNotNull(nameof(fileInfos)); FileInfo[] files = fileInfos.ToArray(); - return new ZipArchive(new SourceStream(files[0], i => i < files.Length ? files[i] : null, readerOptions ?? new ReaderOptions())); + return new ZipArchive( + new SourceStream( + files[0], + i => i < files.Length ? files[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -76,11 +94,20 @@ namespace SharpCompress.Archives.Zip /// /// /// - public static ZipArchive Open(IEnumerable streams, ReaderOptions? readerOptions = null) + public static ZipArchive Open( + IEnumerable streams, + ReaderOptions? readerOptions = null + ) { streams.CheckNotNull(nameof(streams)); Stream[] strms = streams.ToArray(); - return new ZipArchive(new SourceStream(strms[0], i => i < strms.Length ? strms[i] : null, readerOptions ?? new ReaderOptions())); + return new ZipArchive( + new SourceStream( + strms[0], + i => i < strms.Length ? strms[i] : null, + readerOptions ?? new ReaderOptions() + ) + ); } /// @@ -91,7 +118,9 @@ namespace SharpCompress.Archives.Zip public static ZipArchive Open(Stream stream, ReaderOptions? readerOptions = null) { stream.CheckNotNull(nameof(stream)); - return new ZipArchive(new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions())); + return new ZipArchive( + new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions()) + ); } public static bool IsZipFile(string filePath, string? password = null) @@ -113,10 +142,15 @@ namespace SharpCompress.Archives.Zip public static bool IsZipFile(Stream stream, string? password = null) { - StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding()); + StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory( + password, + new ArchiveEncoding() + ); try { - ZipHeader? header = headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); + ZipHeader? header = headerFactory + .ReadStreamHeader(stream) + .FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); if (header is null) { return false; @@ -135,15 +169,23 @@ namespace SharpCompress.Archives.Zip public static bool IsZipMulti(Stream stream, string? password = null) { - StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding()); + StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory( + password, + new ArchiveEncoding() + ); try { - ZipHeader? header = headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); + ZipHeader? header = headerFactory + .ReadStreamHeader(stream) + .FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); if (header is null) { if (stream.CanSeek) //could be multipart. Test for central directory - might not be z64 safe { - SeekableZipHeaderFactory z = new SeekableZipHeaderFactory(password, new ArchiveEncoding()); + SeekableZipHeaderFactory z = new SeekableZipHeaderFactory( + password, + new ArchiveEncoding() + ); var x = z.ReadSeekableHeader(stream).FirstOrDefault(); return x?.ZipHeaderType == ZipHeaderType.DirectoryEntry; } @@ -191,10 +233,7 @@ namespace SharpCompress.Archives.Zip return new ZipVolume(base.SrcStream, ReaderOptions, idx++).AsEnumerable(); } - internal ZipArchive() - : base(ArchiveType.Zip) - { - } + internal ZipArchive() : base(ArchiveType.Zip) { } protected override IEnumerable LoadEntries(IEnumerable volumes) { @@ -206,19 +245,30 @@ namespace SharpCompress.Archives.Zip switch (h.ZipHeaderType) { case ZipHeaderType.DirectoryEntry: - { - DirectoryEntryHeader deh = (DirectoryEntryHeader)h; - Stream s; - if (deh.RelativeOffsetOfEntryHeader + deh.CompressedSize > vols[deh.DiskNumberStart].Stream.Length) + { - var v = vols.Skip(deh.DiskNumberStart).ToArray(); - s = new SourceStream(v[0].Stream, i => i < v.Length ? v[i].Stream : null, new ReaderOptions() { LeaveStreamOpen = true }); + DirectoryEntryHeader deh = (DirectoryEntryHeader)h; + Stream s; + if ( + deh.RelativeOffsetOfEntryHeader + deh.CompressedSize + > vols[deh.DiskNumberStart].Stream.Length + ) + { + var v = vols.Skip(deh.DiskNumberStart).ToArray(); + s = new SourceStream( + v[0].Stream, + i => i < v.Length ? v[i].Stream : null, + new ReaderOptions() { LeaveStreamOpen = true } + ); + } + else + s = vols[deh.DiskNumberStart].Stream; + yield return new ZipArchiveEntry( + this, + new SeekableZipFilePart(headerFactory, deh, s) + ); } - else - s = vols[deh.DiskNumberStart].Stream; - yield return new ZipArchiveEntry(this, new SeekableZipFilePart(headerFactory, deh, s)); - } - break; + break; case ZipHeaderType.DirectoryEnd: { byte[] bytes = ((DirectoryEndHeader)h).Comment ?? Array.Empty(); @@ -235,14 +285,16 @@ namespace SharpCompress.Archives.Zip SaveTo(stream, new WriterOptions(CompressionType.Deflate)); } - protected override void SaveTo(Stream stream, WriterOptions options, - IEnumerable oldEntries, - IEnumerable newEntries) + protected override void SaveTo( + Stream stream, + WriterOptions options, + IEnumerable oldEntries, + IEnumerable newEntries + ) { using (var writer = new ZipWriter(stream, new ZipWriterOptions(options))) { - foreach (var entry in oldEntries.Concat(newEntries) - .Where(x => !x.IsDirectory)) + foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory)) { using (var entryStream = entry.OpenEntryStream()) { @@ -252,8 +304,13 @@ namespace SharpCompress.Archives.Zip } } - protected override ZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified, - bool closeStream) + protected override ZipArchiveEntry CreateEntryInternal( + string filePath, + Stream source, + long size, + DateTime? modified, + bool closeStream + ) { return new ZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream); } diff --git a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs index 2aad807b..dd1354fd 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs @@ -6,8 +6,7 @@ namespace SharpCompress.Archives.Zip { public class ZipArchiveEntry : ZipEntry, IArchiveEntry { - internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart? part) - : base(part) + internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart? part) : base(part) { Archive = archive; } @@ -27,4 +26,4 @@ namespace SharpCompress.Archives.Zip public string? Comment => ((SeekableZipFilePart)Parts.Single()).Comment; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Archives/Zip/ZipArchiveVolumeFactory.cs b/src/SharpCompress/Archives/Zip/ZipArchiveVolumeFactory.cs index 439e5a70..e38e4af1 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchiveVolumeFactory.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchiveVolumeFactory.cs @@ -18,9 +18,22 @@ namespace SharpCompress.Archives.Zip //load files with zip/zipx first. Swapped to end once loaded in ZipArchive //new style .zip, z01.. | .zipx, zx01 - if the numbers go beyond 99 then they use 100 ...1000 etc - Match m = Regex.Match(part1.Name, @"^(.*\.)(zipx?|zx?[0-9]+)$", RegexOptions.IgnoreCase); + Match m = Regex.Match( + part1.Name, + @"^(.*\.)(zipx?|zx?[0-9]+)$", + RegexOptions.IgnoreCase + ); if (m.Success) - item = new FileInfo(Path.Combine(part1.DirectoryName!, String.Concat(m.Groups[1].Value, Regex.Replace(m.Groups[2].Value, @"[^xz]", ""), index.ToString().PadLeft(2, '0')))); + item = new FileInfo( + Path.Combine( + part1.DirectoryName!, + String.Concat( + m.Groups[1].Value, + Regex.Replace(m.Groups[2].Value, @"[^xz]", ""), + index.ToString().PadLeft(2, '0') + ) + ) + ); else //split - 001, 002 ... return ArchiveVolumeFactory.GetFilePart(index, part1); @@ -29,6 +42,5 @@ namespace SharpCompress.Archives.Zip return null; //no more items } - } } diff --git a/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs index 7a91993a..ac595792 100644 --- a/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs +++ b/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs @@ -12,9 +12,14 @@ namespace SharpCompress.Archives.Zip private readonly Stream stream; private bool isDisposed; - internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size, - DateTime? lastModified, bool closeStream) - : base(archive, null) + internal ZipWritableArchiveEntry( + ZipArchive archive, + Stream stream, + string path, + long size, + DateTime? lastModified, + bool closeStream + ) : base(archive, null) { this.stream = stream; Key = path; diff --git a/src/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs index 81e81099..d50f0930 100644 --- a/src/SharpCompress/Common/ArchiveEncoding.cs +++ b/src/SharpCompress/Common/ArchiveEncoding.cs @@ -26,10 +26,8 @@ namespace SharpCompress.Common /// string Func(bytes, index, length) public Func? CustomDecoder { get; set; } - public ArchiveEncoding() - : this(Encoding.Default, Encoding.Default) - { - } + public ArchiveEncoding() : this(Encoding.Default, Encoding.Default) { } + public ArchiveEncoding(Encoding def, Encoding password) { Default = def; @@ -70,7 +68,8 @@ namespace SharpCompress.Common public Func GetDecoder() { - return CustomDecoder ?? ((bytes, index, count) => GetEncoding().GetString(bytes, index, count)); + return CustomDecoder + ?? ((bytes, index, count) => GetEncoding().GetString(bytes, index, count)); } } } diff --git a/src/SharpCompress/Common/ArchiveException.cs b/src/SharpCompress/Common/ArchiveException.cs index 18207c64..51fe7463 100644 --- a/src/SharpCompress/Common/ArchiveException.cs +++ b/src/SharpCompress/Common/ArchiveException.cs @@ -4,9 +4,6 @@ namespace SharpCompress.Common { public class ArchiveException : Exception { - public ArchiveException(string message) - : base(message) - { - } + public ArchiveException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs b/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs index b1c9fc75..0be0383c 100644 --- a/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs +++ b/src/SharpCompress/Common/ArchiveExtractionEventArgs.cs @@ -11,4 +11,4 @@ namespace SharpCompress.Common public T Item { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/ArchiveType.cs b/src/SharpCompress/Common/ArchiveType.cs index a0d3097a..1a899398 100644 --- a/src/SharpCompress/Common/ArchiveType.cs +++ b/src/SharpCompress/Common/ArchiveType.cs @@ -8,4 +8,4 @@ SevenZip, GZip } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/CompressedBytesReadEventArgs.cs b/src/SharpCompress/Common/CompressedBytesReadEventArgs.cs index 322a3c64..c87a3588 100644 --- a/src/SharpCompress/Common/CompressedBytesReadEventArgs.cs +++ b/src/SharpCompress/Common/CompressedBytesReadEventArgs.cs @@ -4,7 +4,10 @@ namespace SharpCompress.Common { public sealed class CompressedBytesReadEventArgs : EventArgs { - public CompressedBytesReadEventArgs(long compressedBytesRead, long currentFilePartCompressedBytesRead) + public CompressedBytesReadEventArgs( + long compressedBytesRead, + long currentFilePartCompressedBytesRead + ) { CompressedBytesRead = compressedBytesRead; CurrentFilePartCompressedBytesRead = currentFilePartCompressedBytesRead; @@ -20,4 +23,4 @@ namespace SharpCompress.Common /// public long CurrentFilePartCompressedBytesRead { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/CompressionType.cs b/src/SharpCompress/Common/CompressionType.cs index 23ed354f..7dfc857c 100644 --- a/src/SharpCompress/Common/CompressionType.cs +++ b/src/SharpCompress/Common/CompressionType.cs @@ -16,4 +16,4 @@ Unknown, Deflate64 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/CryptographicException.cs b/src/SharpCompress/Common/CryptographicException.cs index 450cd237..3bdfccb5 100644 --- a/src/SharpCompress/Common/CryptographicException.cs +++ b/src/SharpCompress/Common/CryptographicException.cs @@ -4,9 +4,6 @@ namespace SharpCompress.Common { public class CryptographicException : Exception { - public CryptographicException(string message) - : base(message) - { - } + public CryptographicException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Entry.cs b/src/SharpCompress/Common/Entry.cs index 06afcabd..17ecc31b 100644 --- a/src/SharpCompress/Common/Entry.cs +++ b/src/SharpCompress/Common/Entry.cs @@ -73,6 +73,7 @@ namespace SharpCompress.Common public int VolumeIndexFirst => this.Parts?.FirstOrDefault()?.Index ?? 0; public int VolumeIndexLast => this.Parts?.LastOrDefault()?.Index ?? 0; + /// public override string ToString() => Key; @@ -80,9 +81,7 @@ namespace SharpCompress.Common public bool IsSolid { get; set; } - internal virtual void Close() - { - } + internal virtual void Close() { } /// /// Entry file attribute. diff --git a/src/SharpCompress/Common/EntryStream.cs b/src/SharpCompress/Common/EntryStream.cs index 43ca0537..44d8e235 100644 --- a/src/SharpCompress/Common/EntryStream.cs +++ b/src/SharpCompress/Common/EntryStream.cs @@ -47,13 +47,15 @@ namespace SharpCompress.Common public override bool CanWrite => false; - public override void Flush() - { - } + public override void Flush() { } public override long Length => _stream.Length; - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -90,4 +92,4 @@ namespace SharpCompress.Common throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/ExtractionException.cs b/src/SharpCompress/Common/ExtractionException.cs index be5e688c..51f9bc1e 100644 --- a/src/SharpCompress/Common/ExtractionException.cs +++ b/src/SharpCompress/Common/ExtractionException.cs @@ -4,14 +4,8 @@ namespace SharpCompress.Common { public class ExtractionException : Exception { - public ExtractionException(string message) - : base(message) - { - } + public ExtractionException(string message) : base(message) { } - public ExtractionException(string message, Exception inner) - : base(message, inner) - { - } + public ExtractionException(string message, Exception inner) : base(message, inner) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/ExtractionMethods.cs b/src/SharpCompress/Common/ExtractionMethods.cs index 51ded979..7a6cb9db 100644 --- a/src/SharpCompress/Common/ExtractionMethods.cs +++ b/src/SharpCompress/Common/ExtractionMethods.cs @@ -8,41 +8,49 @@ namespace SharpCompress.Common /// /// Extract to specific directory, retaining filename /// - public static void WriteEntryToDirectory(IEntry entry, - string destinationDirectory, - ExtractionOptions? options, - Action write) + public static void WriteEntryToDirectory( + IEntry entry, + string destinationDirectory, + ExtractionOptions? options, + Action write + ) { string destinationFileName; string fullDestinationDirectoryPath = Path.GetFullPath(destinationDirectory); //check for trailing slash. - if (fullDestinationDirectoryPath[fullDestinationDirectoryPath.Length - 1] != Path.DirectorySeparatorChar) + if ( + fullDestinationDirectoryPath[fullDestinationDirectoryPath.Length - 1] + != Path.DirectorySeparatorChar + ) { fullDestinationDirectoryPath += Path.DirectorySeparatorChar; } if (!Directory.Exists(fullDestinationDirectoryPath)) { - throw new ExtractionException($"Directory does not exist to extract to: {fullDestinationDirectoryPath}"); + throw new ExtractionException( + $"Directory does not exist to extract to: {fullDestinationDirectoryPath}" + ); } - options ??= new ExtractionOptions() - { - Overwrite = true - }; + options ??= new ExtractionOptions() { Overwrite = true }; string file = Path.GetFileName(entry.Key); if (options.ExtractFullPath) { string folder = Path.GetDirectoryName(entry.Key)!; - string destdir = Path.GetFullPath(Path.Combine(fullDestinationDirectoryPath, folder)); + string destdir = Path.GetFullPath( + Path.Combine(fullDestinationDirectoryPath, folder) + ); if (!Directory.Exists(destdir)) { if (!destdir.StartsWith(fullDestinationDirectoryPath, StringComparison.Ordinal)) { - throw new ExtractionException("Entry is trying to create a directory outside of the destination directory."); + throw new ExtractionException( + "Entry is trying to create a directory outside of the destination directory." + ); } Directory.CreateDirectory(destdir); @@ -52,16 +60,22 @@ namespace SharpCompress.Common else { destinationFileName = Path.Combine(fullDestinationDirectoryPath, file); - } if (!entry.IsDirectory) { destinationFileName = Path.GetFullPath(destinationFileName); - if (!destinationFileName.StartsWith(fullDestinationDirectoryPath, StringComparison.Ordinal)) + if ( + !destinationFileName.StartsWith( + fullDestinationDirectoryPath, + StringComparison.Ordinal + ) + ) { - throw new ExtractionException("Entry is trying to write a file outside of the destination directory."); + throw new ExtractionException( + "Entry is trying to write a file outside of the destination directory." + ); } write(destinationFileName, options); } @@ -71,25 +85,27 @@ namespace SharpCompress.Common } } - public static void WriteEntryToFile(IEntry entry, string destinationFileName, - ExtractionOptions? options, - Action openAndWrite) + public static void WriteEntryToFile( + IEntry entry, + string destinationFileName, + ExtractionOptions? options, + Action openAndWrite + ) { if (entry.LinkTarget != null) { if (options?.WriteSymbolicLink is null) { - throw new ExtractionException("Entry is a symbolic link but ExtractionOptions.WriteSymbolicLink delegate is null"); + throw new ExtractionException( + "Entry is a symbolic link but ExtractionOptions.WriteSymbolicLink delegate is null" + ); } options.WriteSymbolicLink(destinationFileName, entry.LinkTarget); } else { FileMode fm = FileMode.Create; - options ??= new ExtractionOptions() - { - Overwrite = true - }; + options ??= new ExtractionOptions() { Overwrite = true }; if (!options.Overwrite) { @@ -101,4 +117,4 @@ namespace SharpCompress.Common } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/ExtractionOptions.cs b/src/SharpCompress/Common/ExtractionOptions.cs index 54dbe79f..650708cc 100644 --- a/src/SharpCompress/Common/ExtractionOptions.cs +++ b/src/SharpCompress/Common/ExtractionOptions.cs @@ -31,10 +31,11 @@ namespace SharpCompress.Common /// public delegate void SymbolicLinkWriterDelegate(string sourcePath, string targetPath); - public SymbolicLinkWriterDelegate WriteSymbolicLink = - (sourcePath, targetPath) => - { - Console.WriteLine($"Could not write symlink {sourcePath} -> {targetPath}, for more information please see https://github.com/dotnet/runtime/issues/24271"); - }; + public SymbolicLinkWriterDelegate WriteSymbolicLink = (sourcePath, targetPath) => + { + Console.WriteLine( + $"Could not write symlink {sourcePath} -> {targetPath}, for more information please see https://github.com/dotnet/runtime/issues/24271" + ); + }; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs b/src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs index ee80a4ab..c05ff46e 100644 --- a/src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs +++ b/src/SharpCompress/Common/FilePartExtractionBeginEventArgs.cs @@ -26,4 +26,4 @@ namespace SharpCompress.Common /// public long CompressedSize { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/FlagUtility.cs b/src/SharpCompress/Common/FlagUtility.cs index 8a3aaee1..67aa1428 100644 --- a/src/SharpCompress/Common/FlagUtility.cs +++ b/src/SharpCompress/Common/FlagUtility.cs @@ -6,35 +6,33 @@ namespace SharpCompress.Common { /// /// Returns true if the flag is set on the specified bit field. - /// Currently only works with 32-bit bitfields. + /// Currently only works with 32-bit bitfields. /// /// Enumeration with Flags attribute /// Flagged variable /// Flag to test /// - public static bool HasFlag(long bitField, T flag) - where T : struct + public static bool HasFlag(long bitField, T flag) where T : struct { return HasFlag(bitField, flag); } /// /// Returns true if the flag is set on the specified bit field. - /// Currently only works with 32-bit bitfields. + /// Currently only works with 32-bit bitfields. /// /// Enumeration with Flags attribute /// Flagged variable /// Flag to test /// - public static bool HasFlag(ulong bitField, T flag) - where T : struct + public static bool HasFlag(ulong bitField, T flag) where T : struct { return HasFlag(bitField, flag); } /// /// Returns true if the flag is set on the specified bit field. - /// Currently only works with 32-bit bitfields. + /// Currently only works with 32-bit bitfields. /// /// Flagged variable /// Flag to test @@ -51,21 +49,20 @@ namespace SharpCompress.Common /// /// Returns true if the flag is set on the specified bit field. - /// Currently only works with 32-bit bitfields. + /// Currently only works with 32-bit bitfields. /// /// Enumeration with Flags attribute /// Flagged variable /// Flag to test /// - public static bool HasFlag(T bitField, T flag) - where T : struct + public static bool HasFlag(T bitField, T flag) where T : struct { return HasFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag)); } /// /// Returns true if the flag is set on the specified bit field. - /// Currently only works with 32-bit bitfields. + /// Currently only works with 32-bit bitfields. /// /// Flagged variable /// Flag to test @@ -99,10 +96,9 @@ namespace SharpCompress.Common /// Flag to change /// bool /// The flagged variable with the flag changed - public static long SetFlag(T bitField, T flag, bool on) - where T : struct + public static long SetFlag(T bitField, T flag, bool on) where T : struct { return SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), on); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/GZip/GZipEntry.cs b/src/SharpCompress/Common/GZip/GZipEntry.cs index 1204cfd7..9da986ee 100644 --- a/src/SharpCompress/Common/GZip/GZipEntry.cs +++ b/src/SharpCompress/Common/GZip/GZipEntry.cs @@ -46,4 +46,4 @@ namespace SharpCompress.Common.GZip yield return new GZipEntry(new GZipFilePart(stream, options.ArchiveEncoding)); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs index c6fd9849..a5062267 100644 --- a/src/SharpCompress/Common/GZip/GZipFilePart.cs +++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs @@ -129,8 +129,7 @@ namespace SharpCompress.Common.GZip { list.Add(buf1[0]); } - } - while (!done); + } while (!done); byte[] buffer = list.ToArray(); return ArchiveEncoding.Decode(buffer); } diff --git a/src/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs index 6d77029f..10e0574d 100644 --- a/src/SharpCompress/Common/GZip/GZipVolume.cs +++ b/src/SharpCompress/Common/GZip/GZipVolume.cs @@ -6,9 +6,7 @@ namespace SharpCompress.Common.GZip public class GZipVolume : Volume { public GZipVolume(Stream stream, ReaderOptions options, int index = 0) - : base(stream, options, index) - { - } + : base(stream, options, index) { } public GZipVolume(FileInfo fileInfo, ReaderOptions options) : base(fileInfo.OpenRead(), options) diff --git a/src/SharpCompress/Common/IEntry.Extensions.cs b/src/SharpCompress/Common/IEntry.Extensions.cs index 02acd59a..fdf321bd 100644 --- a/src/SharpCompress/Common/IEntry.Extensions.cs +++ b/src/SharpCompress/Common/IEntry.Extensions.cs @@ -4,8 +4,11 @@ namespace SharpCompress.Common { internal static class EntryExtensions { - internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName, - ExtractionOptions options) + internal static void PreserveExtractionOptions( + this IEntry entry, + string destinationFileName, + ExtractionOptions options + ) { if (options.PreserveFileTime || options.PreserveAttributes) { @@ -38,7 +41,8 @@ namespace SharpCompress.Common { if (entry.Attrib.HasValue) { - nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value); + nf.Attributes = (FileAttributes) + System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value); } } } diff --git a/src/SharpCompress/Common/IncompleteArchiveException.cs b/src/SharpCompress/Common/IncompleteArchiveException.cs index 78d567f4..aca34349 100644 --- a/src/SharpCompress/Common/IncompleteArchiveException.cs +++ b/src/SharpCompress/Common/IncompleteArchiveException.cs @@ -2,9 +2,6 @@ { public class IncompleteArchiveException : ArchiveException { - public IncompleteArchiveException(string message) - : base(message) - { - } + public IncompleteArchiveException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/InvalidFormatException.cs b/src/SharpCompress/Common/InvalidFormatException.cs index fa141cb4..ffb16003 100644 --- a/src/SharpCompress/Common/InvalidFormatException.cs +++ b/src/SharpCompress/Common/InvalidFormatException.cs @@ -4,14 +4,8 @@ namespace SharpCompress.Common { public class InvalidFormatException : ExtractionException { - public InvalidFormatException(string message) - : base(message) - { - } + public InvalidFormatException(string message) : base(message) { } - public InvalidFormatException(string message, Exception inner) - : base(message, inner) - { - } + public InvalidFormatException(string message, Exception inner) : base(message, inner) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/MultiVolumeExtractionException.cs b/src/SharpCompress/Common/MultiVolumeExtractionException.cs index d9b97fa3..7e6da358 100644 --- a/src/SharpCompress/Common/MultiVolumeExtractionException.cs +++ b/src/SharpCompress/Common/MultiVolumeExtractionException.cs @@ -4,14 +4,9 @@ namespace SharpCompress.Common { public class MultiVolumeExtractionException : ExtractionException { - public MultiVolumeExtractionException(string message) - : base(message) - { - } + public MultiVolumeExtractionException(string message) : base(message) { } public MultiVolumeExtractionException(string message, Exception inner) - : base(message, inner) - { - } + : base(message, inner) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/MultipartStreamRequiredException.cs b/src/SharpCompress/Common/MultipartStreamRequiredException.cs index cf030ed6..84b673ef 100644 --- a/src/SharpCompress/Common/MultipartStreamRequiredException.cs +++ b/src/SharpCompress/Common/MultipartStreamRequiredException.cs @@ -2,9 +2,6 @@ { public class MultipartStreamRequiredException : ExtractionException { - public MultipartStreamRequiredException(string message) - : base(message) - { - } + public MultipartStreamRequiredException(string message) : base(message) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/OptionsBase.cs b/src/SharpCompress/Common/OptionsBase.cs index b98f0a60..6591f975 100644 --- a/src/SharpCompress/Common/OptionsBase.cs +++ b/src/SharpCompress/Common/OptionsBase.cs @@ -1,5 +1,4 @@ - -namespace SharpCompress.Common +namespace SharpCompress.Common { public class OptionsBase { @@ -10,4 +9,4 @@ namespace SharpCompress.Common public ArchiveEncoding ArchiveEncoding { get; set; } = new ArchiveEncoding(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/PasswordProtectedException.cs b/src/SharpCompress/Common/PasswordProtectedException.cs index 58dc7660..ade0a55d 100644 --- a/src/SharpCompress/Common/PasswordProtectedException.cs +++ b/src/SharpCompress/Common/PasswordProtectedException.cs @@ -4,14 +4,9 @@ namespace SharpCompress.Common { public class PasswordProtectedException : ExtractionException { - public PasswordProtectedException(string message) - : base(message) - { - } + public PasswordProtectedException(string message) : base(message) { } - public PasswordProtectedException(string message, Exception inner) - : base(message, inner) - { - } + public PasswordProtectedException(string message, Exception inner) : base(message, inner) + { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/AVHeader.cs b/src/SharpCompress/Common/Rar/Headers/AVHeader.cs index 44d2b15a..b235e5ce 100644 --- a/src/SharpCompress/Common/Rar/Headers/AVHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/AVHeader.cs @@ -29,4 +29,4 @@ namespace SharpCompress.Common.Rar.Headers internal byte AvVersion { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs index 51cf05b2..56784c52 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveCryptHeader.cs @@ -6,7 +6,6 @@ namespace SharpCompress.Common.Rar.Headers { internal class ArchiveCryptHeader : RarHeader { - private const int CRYPT_VERSION = 0; // Supported encryption version. private const int SIZE_SALT50 = 16; private const int SIZE_SALT30 = 8; @@ -16,7 +15,6 @@ namespace SharpCompress.Common.Rar.Headers private const int CRYPT5_KDF_LG2_COUNT = 15; // LOG2 of PDKDF2 iteration count. private const int CRYPT5_KDF_LG2_COUNT_MAX = 24; // LOG2 of maximum accepted iteration count. - private bool _usePswCheck; private uint _lg2Count; // Log2 of PBKDF2 repetition count. private byte[] _salt; @@ -24,9 +22,7 @@ namespace SharpCompress.Common.Rar.Headers private byte[] _pswCheckCsm; public ArchiveCryptHeader(RarHeader header, RarCrcBinaryReader reader) - : base(header, reader, HeaderType.Crypt) - { - } + : base(header, reader, HeaderType.Crypt) { } protected override void ReadFinish(MarkingBinaryReader reader) { @@ -37,10 +33,12 @@ namespace SharpCompress.Common.Rar.Headers return; } var encryptionFlags = reader.ReadRarVIntUInt32(); - _usePswCheck = FlagUtility.HasFlag(encryptionFlags, EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK); + _usePswCheck = FlagUtility.HasFlag( + encryptionFlags, + EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK + ); _lg2Count = reader.ReadRarVIntByte(1); - //UsePswCheck = HasHeaderFlag(EncryptionFlagsV5.CHFL_CRYPT_PSWCHECK); if (_lg2Count > CRYPT5_KDF_LG2_COUNT_MAX) { @@ -56,4 +54,4 @@ namespace SharpCompress.Common.Rar.Headers } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs index 39249656..33bc6e9a 100644 --- a/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs @@ -5,9 +5,7 @@ namespace SharpCompress.Common.Rar.Headers internal sealed class ArchiveHeader : RarHeader { public ArchiveHeader(RarHeader header, RarCrcBinaryReader reader) - : base(header, reader, HeaderType.Archive) - { - } + : base(header, reader, HeaderType.Archive) { } protected override void ReadFinish(MarkingBinaryReader reader) { @@ -81,8 +79,9 @@ namespace SharpCompress.Common.Rar.Headers public bool IsVolume => HasFlag(IsRar5 ? ArchiveFlagsV5.VOLUME : ArchiveFlagsV4.VOLUME); // RAR5: Volume number field is present. True for all volumes except first. - public bool IsFirstVolume => IsRar5 ? VolumeNumber is null : HasFlag(ArchiveFlagsV4.FIRST_VOLUME); + public bool IsFirstVolume => + IsRar5 ? VolumeNumber is null : HasFlag(ArchiveFlagsV4.FIRST_VOLUME); public bool IsSolid => HasFlag(IsRar5 ? ArchiveFlagsV5.SOLID : ArchiveFlagsV4.SOLID); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/CommentHeader.cs b/src/SharpCompress/Common/Rar/Headers/CommentHeader.cs index 00a9cc25..1742aabe 100644 --- a/src/SharpCompress/Common/Rar/Headers/CommentHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/CommentHeader.cs @@ -28,4 +28,4 @@ namespace SharpCompress.Common.Rar.Headers internal byte UnpMethod { get; private set; } internal short CommCrc { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs b/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs index d993f1d9..bff19b76 100644 --- a/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/EndArchiveHeader.cs @@ -5,9 +5,7 @@ namespace SharpCompress.Common.Rar.Headers internal class EndArchiveHeader : RarHeader { public EndArchiveHeader(RarHeader header, RarCrcBinaryReader reader) - : base(header, reader, HeaderType.EndArchive) - { - } + : base(header, reader, HeaderType.EndArchive) { } protected override void ReadFinish(MarkingBinaryReader reader) { @@ -40,4 +38,4 @@ namespace SharpCompress.Common.Rar.Headers internal short? VolumeNumber { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs index 2c361a09..8ef40ec5 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs @@ -22,9 +22,7 @@ namespace SharpCompress.Common.Rar.Headers private uint _fileCrc; public FileHeader(RarHeader header, RarCrcBinaryReader reader, HeaderType headerType) - : base(header, reader, headerType) - { - } + : base(header, reader, headerType) { } protected override void ReadFinish(MarkingBinaryReader reader) { @@ -68,7 +66,7 @@ namespace SharpCompress.Common.Rar.Headers // them. CompressionAlgorithm = (byte)((compressionInfo & 0x3f) + 50); - // 7th bit (0x0040) defines the solid flag. If it is set, RAR continues to use the compression dictionary left after processing preceding files. + // 7th bit (0x0040) defines the solid flag. If it is set, RAR continues to use the compression dictionary left after processing preceding files. // It can be set only for file headers and is never set for service headers. IsSolid = (compressionInfo & 0x40) == 0x40; @@ -89,7 +87,7 @@ namespace SharpCompress.Common.Rar.Headers // TODO: not sure if anything needs to be done to handle the following: // If Unix file name contains any high ASCII characters which cannot be correctly converted to Unicode and UTF-8 // we map such characters to to 0xE080 - 0xE0FF private use Unicode area and insert 0xFFFE Unicode non-character - // to resulting string to indicate that it contains mapped characters, which need to be converted back when extracting. + // to resulting string to indicate that it contains mapped characters, which need to be converted back when extracting. // Concrete position of 0xFFFE is not defined, we need to search the entire string for it. Such mapped names are not // portable and can be correctly unpacked only on the same system where they were created. // @@ -119,6 +117,7 @@ namespace SharpCompress.Common.Rar.Headers { //TODO case 1: // file encryption + { isEncryptedRar5 = true; @@ -132,6 +131,7 @@ namespace SharpCompress.Common.Rar.Headers // } // break; case 3: // file time + { ushort flags = reader.ReadRarVIntUInt16(); var isWindowsTime = (flags & 1) == 0; @@ -190,7 +190,6 @@ namespace SharpCompress.Common.Rar.Headers } } - private static DateTime ReadExtendedTimeV5(MarkingBinaryReader reader, bool isWindowsTime) { if (isWindowsTime) @@ -213,12 +212,13 @@ namespace SharpCompress.Common.Rar.Headers return path; } - private void ReadFromReaderV4(MarkingBinaryReader reader) { Flags = HeaderFlags; IsSolid = HasFlag(FileFlagsV4.SOLID); - WindowSize = IsDirectory ? 0U : ((size_t)0x10000) << ((Flags & FileFlagsV4.WINDOW_MASK) >> 5); + WindowSize = IsDirectory + ? 0U + : ((size_t)0x10000) << ((Flags & FileFlagsV4.WINDOW_MASK) >> 5); uint lowUncompressedSize = reader.ReadUInt32(); @@ -263,12 +263,12 @@ namespace SharpCompress.Common.Rar.Headers switch (HeaderCode) { case HeaderCodeV.RAR4_FILE_HEADER: + { if (HasFlag(FileFlagsV4.UNICODE)) { int length = 0; - while (length < fileNameBytes.Length - && fileNameBytes[length] != 0) + while (length < fileNameBytes.Length && fileNameBytes[length] != 0) { length++; } @@ -290,6 +290,7 @@ namespace SharpCompress.Common.Rar.Headers } break; case HeaderCodeV.RAR4_NEW_SUB_HEADER: + { int datasize = HeaderSize - newLhdSize - nameSize; if (HasFlag(FileFlagsV4.SALT)) @@ -303,8 +304,11 @@ namespace SharpCompress.Common.Rar.Headers if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes)) { - RecoverySectors = SubData[8] + (SubData[9] << 8) - + (SubData[10] << 16) + (SubData[11] << 24); + RecoverySectors = + SubData[8] + + (SubData[9] << 8) + + (SubData[10] << 16) + + (SubData[11] << 24); } } break; @@ -321,7 +325,12 @@ namespace SharpCompress.Common.Rar.Headers if (RemainingHeaderBytes(reader) >= 2) { ushort extendedFlags = reader.ReadUInt16(); - FileLastModifiedTime = ProcessExtendedTimeV4(extendedFlags, FileLastModifiedTime, reader, 0); + FileLastModifiedTime = ProcessExtendedTimeV4( + extendedFlags, + FileLastModifiedTime, + reader, + 0 + ); FileCreatedTime = ProcessExtendedTimeV4(extendedFlags, null, reader, 1); FileLastAccessedTime = ProcessExtendedTimeV4(extendedFlags, null, reader, 2); FileArchivedTime = ProcessExtendedTimeV4(extendedFlags, null, reader, 3); @@ -336,7 +345,12 @@ namespace SharpCompress.Common.Rar.Headers return l + y; } - private static DateTime? ProcessExtendedTimeV4(ushort extendedFlags, DateTime? time, MarkingBinaryReader reader, int i) + private static DateTime? ProcessExtendedTimeV4( + ushort extendedFlags, + DateTime? time, + MarkingBinaryReader reader, + int i + ) { uint rmode = (uint)extendedFlags >> (3 - i) * 4; if ((rmode & 8) == 0) @@ -395,7 +409,7 @@ namespace SharpCompress.Common.Rar.Headers { if (IsRar5 && !HasFlag(FileFlagsV5.HAS_CRC32)) { - //!!! rar5: + //!!! rar5: throw new InvalidOperationException("TODO rar5"); } return _fileCrc; @@ -437,8 +451,10 @@ namespace SharpCompress.Common.Rar.Headers internal long DataStartPosition { get; set; } public Stream PackedStream { get; set; } - public bool IsSplitBefore => IsRar5 ? HasHeaderFlag(HeaderFlagsV5.SPLIT_BEFORE) : HasFlag(FileFlagsV4.SPLIT_BEFORE); - public bool IsSplitAfter => IsRar5 ? HasHeaderFlag(HeaderFlagsV5.SPLIT_AFTER) : HasFlag(FileFlagsV4.SPLIT_AFTER); + public bool IsSplitBefore => + IsRar5 ? HasHeaderFlag(HeaderFlagsV5.SPLIT_BEFORE) : HasFlag(FileFlagsV4.SPLIT_BEFORE); + public bool IsSplitAfter => + IsRar5 ? HasHeaderFlag(HeaderFlagsV5.SPLIT_AFTER) : HasFlag(FileFlagsV4.SPLIT_AFTER); public bool IsDirectory => HasFlag(IsRar5 ? FileFlagsV5.DIRECTORY : FileFlagsV4.DIRECTORY); @@ -453,4 +469,4 @@ namespace SharpCompress.Common.Rar.Headers internal DateTime? FileArchivedTime { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs b/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs index 98da75da..f2afaa39 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileNameDecoder.cs @@ -54,7 +54,11 @@ namespace SharpCompress.Common.Rar.Headers if ((length & 0x80) != 0) { int correction = GetChar(name, encPos++); - for (length = (length & 0x7f) + 2; length > 0 && decPos < name.Length; length--, decPos++) + for ( + length = (length & 0x7f) + 2; + length > 0 && decPos < name.Length; + length--, decPos++ + ) { low = (GetChar(name, decPos) + correction) & 0xff; buf.Append((char)((highByte << 8) + low)); @@ -62,7 +66,11 @@ namespace SharpCompress.Common.Rar.Headers } else { - for (length += 2; length > 0 && decPos < name.Length; length--, decPos++) + for ( + length += 2; + length > 0 && decPos < name.Length; + length--, decPos++ + ) { buf.Append((char)(GetChar(name, decPos))); } @@ -75,4 +83,4 @@ namespace SharpCompress.Common.Rar.Headers return buf.ToString(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/Flags.cs b/src/SharpCompress/Common/Rar/Headers/Flags.cs index 7925ca5f..7f6ad0aa 100644 --- a/src/SharpCompress/Common/Rar/Headers/Flags.cs +++ b/src/SharpCompress/Common/Rar/Headers/Flags.cs @@ -54,7 +54,7 @@ namespace SharpCompress.Common.Rar.Headers { public const ushort HAS_EXTRA = 0x0001; public const ushort HAS_DATA = 0x0002; - public const ushort KEEP = 0x0004; // block must be kept during an update + public const ushort KEEP = 0x0004; // block must be kept during an update public const ushort SPLIT_BEFORE = 0x0008; public const ushort SPLIT_AFTER = 0x0010; public const ushort CHILD = 0x0020; // ??? Block depends on preceding file block. diff --git a/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs b/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs index 82b40ad8..8416270d 100644 --- a/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/MarkHeader.cs @@ -34,7 +34,8 @@ namespace SharpCompress.Common.Rar.Headers try { int start = -1; - var b = GetByte(stream); start++; + var b = GetByte(stream); + start++; while (start <= maxScanIndex) { // Rar old signature: 52 45 7E 5E @@ -42,37 +43,44 @@ namespace SharpCompress.Common.Rar.Headers // Rar5 signature: 52 61 72 21 1A 07 01 00 if (b == 0x52) { - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b == 0x61) { - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0x72) { continue; } - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0x21) { continue; } - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0x1a) { continue; } - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0x07) { continue; } - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b == 1) { - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0) { continue; @@ -87,24 +95,29 @@ namespace SharpCompress.Common.Rar.Headers } else if (b == 0x45) { - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0x7e) { continue; } - b = GetByte(stream); start++; + b = GetByte(stream); + start++; if (b != 0x5e) { continue; } - throw new InvalidFormatException("Rar format version pre-4 is unsupported."); + throw new InvalidFormatException( + "Rar format version pre-4 is unsupported." + ); } } else { - b = GetByte(stream); start++; + b = GetByte(stream); + start++; } } } diff --git a/src/SharpCompress/Common/Rar/Headers/NewSubHeaderType.cs b/src/SharpCompress/Common/Rar/Headers/NewSubHeaderType.cs index 5e07c92e..9814d6bc 100644 --- a/src/SharpCompress/Common/Rar/Headers/NewSubHeaderType.cs +++ b/src/SharpCompress/Common/Rar/Headers/NewSubHeaderType.cs @@ -46,4 +46,4 @@ namespace SharpCompress.Common.Rar.Headers return other is not null && Equals(other._bytes); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs b/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs index 27d5297b..9785f369 100644 --- a/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs @@ -28,4 +28,4 @@ namespace SharpCompress.Common.Rar.Headers internal uint TotalBlocks { get; private set; } internal byte[]? Mark { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeader.cs b/src/SharpCompress/Common/Rar/Headers/RarHeader.cs index cb58b51e..732bfab4 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeader.cs @@ -11,7 +11,11 @@ namespace SharpCompress.Common.Rar.Headers private readonly HeaderType _headerType; private readonly bool _isRar5; - internal static RarHeader? TryReadBase(RarCrcBinaryReader reader, bool isRar5, ArchiveEncoding archiveEncoding) + internal static RarHeader? TryReadBase( + RarCrcBinaryReader reader, + bool isRar5, + ArchiveEncoding archiveEncoding + ) { try { @@ -131,4 +135,4 @@ namespace SharpCompress.Common.Rar.Headers /// protected long AdditionalDataSize { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs index 4ac686a2..d5641959 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs @@ -21,7 +21,11 @@ namespace SharpCompress.Common.Rar.Headers public IEnumerable ReadHeaders(Stream stream) { - var markHeader = MarkHeader.Read(stream, Options.LeaveStreamOpen, Options.LookForHeader); + var markHeader = MarkHeader.Read( + stream, + Options.LeaveStreamOpen, + Options.LookForHeader + ); _isRar5 = markHeader.IsRar5; yield return markHeader; @@ -49,7 +53,9 @@ namespace SharpCompress.Common.Rar.Headers { if (Options.Password is null) { - throw new CryptographicException("Encrypted Rar archive has no password specified."); + throw new CryptographicException( + "Encrypted Rar archive has no password specified." + ); } reader = new RarCryptoBinaryReader(stream, Options.Password); } @@ -63,102 +69,113 @@ namespace SharpCompress.Common.Rar.Headers { case HeaderCodeV.RAR5_ARCHIVE_HEADER: case HeaderCodeV.RAR4_ARCHIVE_HEADER: + { + var ah = new ArchiveHeader(header, reader); + if (ah.IsEncrypted == true) { - var ah = new ArchiveHeader(header, reader); - if (ah.IsEncrypted == true) - { - //!!! rar5 we don't know yet - IsEncrypted = true; - } - return ah; + //!!! rar5 we don't know yet + IsEncrypted = true; } + return ah; + } case HeaderCodeV.RAR4_PROTECT_HEADER: + { + var ph = new ProtectHeader(header, reader); + // skip the recovery record data, we do not use it. + switch (StreamingMode) { - var ph = new ProtectHeader(header, reader); - // skip the recovery record data, we do not use it. - switch (StreamingMode) - { - case StreamingMode.Seekable: - { - reader.BaseStream.Position += ph.DataSize; - } - break; - case StreamingMode.Streaming: - { - reader.BaseStream.Skip(ph.DataSize); - } - break; - default: - { - throw new InvalidFormatException("Invalid StreamingMode"); - } - } + case StreamingMode.Seekable: - return ph; + { + reader.BaseStream.Position += ph.DataSize; + } + break; + case StreamingMode.Streaming: + + { + reader.BaseStream.Skip(ph.DataSize); + } + break; + default: + { + throw new InvalidFormatException("Invalid StreamingMode"); + } } + return ph; + } + case HeaderCodeV.RAR5_SERVICE_HEADER: - { - var fh = new FileHeader(header, reader, HeaderType.Service); - SkipData(fh, reader); - return fh; - } + { + var fh = new FileHeader(header, reader, HeaderType.Service); + SkipData(fh, reader); + return fh; + } case HeaderCodeV.RAR4_NEW_SUB_HEADER: - { - var fh = new FileHeader(header, reader, HeaderType.NewSub); - SkipData(fh, reader); - return fh; - } + { + var fh = new FileHeader(header, reader, HeaderType.NewSub); + SkipData(fh, reader); + return fh; + } case HeaderCodeV.RAR5_FILE_HEADER: case HeaderCodeV.RAR4_FILE_HEADER: + { + var fh = new FileHeader(header, reader, HeaderType.File); + switch (StreamingMode) { - var fh = new FileHeader(header, reader, HeaderType.File); - switch (StreamingMode) + case StreamingMode.Seekable: + + { + fh.DataStartPosition = reader.BaseStream.Position; + reader.BaseStream.Position += fh.CompressedSize; + } + break; + case StreamingMode.Streaming: + + { + var ms = new ReadOnlySubStream( + reader.BaseStream, + fh.CompressedSize + ); + if (fh.R4Salt is null) + { + fh.PackedStream = ms; + } + else + { + fh.PackedStream = new RarCryptoWrapper( + ms, + Options.Password!, + fh.R4Salt + ); + } + } + break; + default: { - case StreamingMode.Seekable: - { - fh.DataStartPosition = reader.BaseStream.Position; - reader.BaseStream.Position += fh.CompressedSize; - } - break; - case StreamingMode.Streaming: - { - var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize); - if (fh.R4Salt is null) - { - fh.PackedStream = ms; - } - else - { - fh.PackedStream = new RarCryptoWrapper(ms, Options.Password!, fh.R4Salt); - } - } - break; - default: - { - throw new InvalidFormatException("Invalid StreamingMode"); - } + throw new InvalidFormatException("Invalid StreamingMode"); } - return fh; } + return fh; + } case HeaderCodeV.RAR5_END_ARCHIVE_HEADER: case HeaderCodeV.RAR4_END_ARCHIVE_HEADER: - { - return new EndArchiveHeader(header, reader); - } + { + return new EndArchiveHeader(header, reader); + } case HeaderCodeV.RAR5_ARCHIVE_ENCRYPTION_HEADER: - { - var ch = new ArchiveCryptHeader(header, reader); - IsEncrypted = true; - return ch; - } + { + var ch = new ArchiveCryptHeader(header, reader); + IsEncrypted = true; + return ch; + } default: - { - throw new InvalidFormatException("Unknown Rar Header: " + header.HeaderCode); - } + { + throw new InvalidFormatException("Unknown Rar Header: " + header.HeaderCode); + } } } @@ -167,21 +184,23 @@ namespace SharpCompress.Common.Rar.Headers switch (StreamingMode) { case StreamingMode.Seekable: + { fh.DataStartPosition = reader.BaseStream.Position; reader.BaseStream.Position += fh.CompressedSize; } break; case StreamingMode.Streaming: + { //skip the data because it's useless? reader.BaseStream.Skip(fh.CompressedSize); } break; default: - { - throw new InvalidFormatException("Invalid StreamingMode"); - } + { + throw new InvalidFormatException("Invalid StreamingMode"); + } } } } diff --git a/src/SharpCompress/Common/Rar/Headers/SignHeader.cs b/src/SharpCompress/Common/Rar/Headers/SignHeader.cs index b45c76b2..c03a60f1 100644 --- a/src/SharpCompress/Common/Rar/Headers/SignHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/SignHeader.cs @@ -26,4 +26,4 @@ namespace SharpCompress.Common.Rar.Headers internal short UserNameSize { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs index ddfd8b98..34a64d16 100644 --- a/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs +++ b/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs @@ -8,10 +8,7 @@ namespace SharpCompress.Common.Rar { private uint _currentCrc; - public RarCrcBinaryReader(Stream stream) - : base(stream) - { - } + public RarCrcBinaryReader(Stream stream) : base(stream) { } public uint GetCrc32() { @@ -47,4 +44,4 @@ namespace SharpCompress.Common.Rar return result; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs index e5b7cf33..728690e3 100644 --- a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs +++ b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs @@ -11,8 +11,7 @@ namespace SharpCompress.Common.Rar private readonly Queue _data = new Queue(); private long _readCount; - public RarCryptoBinaryReader(Stream stream, string password) - : base(stream) + public RarCryptoBinaryReader(Stream stream, string password) : base(stream) { _password = password; @@ -108,4 +107,4 @@ namespace SharpCompress.Common.Rar ClearQueue(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarEntry.cs b/src/SharpCompress/Common/Rar/RarEntry.cs index fc084d5c..05ab67ec 100644 --- a/src/SharpCompress/Common/Rar/RarEntry.cs +++ b/src/SharpCompress/Common/Rar/RarEntry.cs @@ -10,7 +10,11 @@ namespace SharpCompress.Common.Rar /// /// As the V2017 port isn't complete, add this check to use the legacy Rar code. /// - internal bool IsRarV3 => FileHeader.CompressionAlgorithm == 20 || FileHeader.CompressionAlgorithm == 26 || FileHeader.CompressionAlgorithm == 29 || FileHeader.CompressionAlgorithm == 36; //Nanook - Added 20+26 as Test arc from WinRar2.8 (algo 20) was failing with 2017 code + internal bool IsRarV3 => + FileHeader.CompressionAlgorithm == 20 + || FileHeader.CompressionAlgorithm == 26 + || FileHeader.CompressionAlgorithm == 29 + || FileHeader.CompressionAlgorithm == 36; //Nanook - Added 20+26 as Test arc from WinRar2.8 (algo 20) was failing with 2017 code /// /// The File's 32 bit CRC Hash @@ -58,8 +62,13 @@ namespace SharpCompress.Common.Rar public override string ToString() { - return string.Format("Entry Path: {0} Compressed Size: {1} Uncompressed Size: {2} CRC: {3}", - Key, CompressedSize, Size, Crc); + return string.Format( + "Entry Path: {0} Compressed Size: {1} Uncompressed Size: {2} CRC: {3}", + Key, + CompressedSize, + Size, + Crc + ); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Rar/RarFilePart.cs b/src/SharpCompress/Common/Rar/RarFilePart.cs index 4075198e..b57ab184 100644 --- a/src/SharpCompress/Common/Rar/RarFilePart.cs +++ b/src/SharpCompress/Common/Rar/RarFilePart.cs @@ -8,8 +8,7 @@ namespace SharpCompress.Common.Rar /// internal abstract class RarFilePart : FilePart { - internal RarFilePart(MarkHeader mh, FileHeader fh, int index) - : base(fh.ArchiveEncoding) + internal RarFilePart(MarkHeader mh, FileHeader fh, int index) : base(fh.ArchiveEncoding) { MarkHeader = mh; FileHeader = fh; diff --git a/src/SharpCompress/Common/Rar/RarRijndael.cs b/src/SharpCompress/Common/Rar/RarRijndael.cs index 44531159..a2a5731f 100644 --- a/src/SharpCompress/Common/Rar/RarRijndael.cs +++ b/src/SharpCompress/Common/Rar/RarRijndael.cs @@ -24,7 +24,6 @@ namespace SharpCompress.Common.Rar private void Initialize() { - _rijndael = new RijndaelEngine(); _aesInitializationVector = new byte[CRYPTO_BLOCK_SIZE]; int rawLength = 2 * _password.Length; @@ -52,11 +51,14 @@ namespace SharpCompress.Common.Rar data[i * (rawPassword.Length + iblock) + rawPassword.Length + 0] = (byte)i; data[i * (rawPassword.Length + iblock) + rawPassword.Length + 1] = (byte)(i >> 8); - data[i * (rawPassword.Length + iblock) + rawPassword.Length + 2] = (byte)(i >> CRYPTO_BLOCK_SIZE); + data[i * (rawPassword.Length + iblock) + rawPassword.Length + 2] = (byte)( + i >> CRYPTO_BLOCK_SIZE + ); if (i % (noOfRounds / CRYPTO_BLOCK_SIZE) == 0) { - digest = SHA1.Create().ComputeHash(data, 0, (i + 1) * (rawPassword.Length + iblock)); + digest = SHA1.Create() + .ComputeHash(data, 0, (i + 1) * (rawPassword.Length + iblock)); _aesInitializationVector[i / (noOfRounds / CRYPTO_BLOCK_SIZE)] = digest[19]; } } @@ -68,16 +70,18 @@ namespace SharpCompress.Common.Rar { for (int j = 0; j < 4; j++) { - aesKey[i * 4 + j] = (byte) - (((digest[i * 4] * 0x1000000) & 0xff000000 | - (uint)((digest[i * 4 + 1] * 0x10000) & 0xff0000) | - (uint)((digest[i * 4 + 2] * 0x100) & 0xff00) | - (uint)(digest[i * 4 + 3] & 0xff)) >> (j * 8)); + aesKey[i * 4 + j] = (byte)( + ( + (digest[i * 4] * 0x1000000) & 0xff000000 + | (uint)((digest[i * 4 + 1] * 0x10000) & 0xff0000) + | (uint)((digest[i * 4 + 2] * 0x100) & 0xff00) + | (uint)(digest[i * 4 + 3] & 0xff) + ) >> (j * 8) + ); } } _rijndael.Init(false, new KeyParameter(aesKey)); - } public static RarRijndael InitializeFrom(string password, byte[] salt) @@ -106,8 +110,6 @@ namespace SharpCompress.Common.Rar return decryptedBytes; } - public void Dispose() - { - } + public void Dispose() { } } } diff --git a/src/SharpCompress/Common/Rar/RarVolume.cs b/src/SharpCompress/Common/Rar/RarVolume.cs index 4efbdd92..8e6a8026 100644 --- a/src/SharpCompress/Common/Rar/RarVolume.cs +++ b/src/SharpCompress/Common/Rar/RarVolume.cs @@ -24,6 +24,7 @@ namespace SharpCompress.Common.Rar #nullable disable internal ArchiveHeader ArchiveHeader { get; private set; } + #nullable enable internal StreamingMode Mode => _headerFactory.StreamingMode; @@ -40,16 +41,19 @@ namespace SharpCompress.Common.Rar switch (header.HeaderType) { case HeaderType.Mark: + { lastMarkHeader = (MarkHeader)header; } break; case HeaderType.Archive: + { ArchiveHeader = (ArchiveHeader)header; } break; case HeaderType.File: + { var fh = (FileHeader)header; if (_maxCompressionAlgorithm < fh.CompressionAlgorithm) @@ -58,17 +62,22 @@ namespace SharpCompress.Common.Rar } break; case HeaderType.Service: - { - var fh = (FileHeader)header; - if (fh.FileName == "CMT") - { - var part = CreateFilePart(lastMarkHeader!, fh); - var buffer = new byte[fh.CompressedSize]; - part.GetCompressedStream().Read(buffer, 0, buffer.Length); - Comment = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length - 1); - } - } - break; + + { + var fh = (FileHeader)header; + if (fh.FileName == "CMT") + { + var part = CreateFilePart(lastMarkHeader!, fh); + var buffer = new byte[fh.CompressedSize]; + part.GetCompressedStream().Read(buffer, 0, buffer.Length); + Comment = System.Text.Encoding.UTF8.GetString( + buffer, + 0, + buffer.Length - 1 + ); + } + } + break; } } } @@ -79,7 +88,9 @@ namespace SharpCompress.Common.Rar { if (Mode == StreamingMode.Streaming) { - throw new InvalidOperationException("ArchiveHeader should never been null in a streaming read."); + throw new InvalidOperationException( + "ArchiveHeader should never been null in a streaming read." + ); } // we only want to load the archive header to avoid overhead but have to do the nasty thing and reset the stream @@ -157,7 +168,7 @@ namespace SharpCompress.Common.Rar return 1; } } - + public string? Comment { get; internal set; } } } diff --git a/src/SharpCompress/Common/ReaderExtractionEventArgs.cs b/src/SharpCompress/Common/ReaderExtractionEventArgs.cs index 32d5b710..87362b68 100644 --- a/src/SharpCompress/Common/ReaderExtractionEventArgs.cs +++ b/src/SharpCompress/Common/ReaderExtractionEventArgs.cs @@ -15,4 +15,4 @@ namespace SharpCompress.Common public ReaderProgress? ReaderProgress { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs b/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs index 2722bf55..e16751e6 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs @@ -48,10 +48,10 @@ namespace SharpCompress.Common.SevenZip internal bool IsEmpty() { return _packSizes.Count == 0 - && _packCrCs.Count == 0 - && _folders.Count == 0 - && _numUnpackStreamsVector.Count == 0 - && _files.Count == 0; + && _packCrCs.Count == 0 + && _folders.Count == 0 + && _numUnpackStreamsVector.Count == 0 + && _files.Count == 0; } private void FillStartPos() @@ -161,7 +161,13 @@ namespace SharpCompress.Common.SevenZip packSizes[j] = _packSizes[packStreamIndex + j]; } - return DecoderStreamHelper.CreateDecoderStream(stream, folderStartPackPos, packSizes, folder, pw); + return DecoderStreamHelper.CreateDecoderStream( + stream, + folderStartPackPos, + packSizes, + folder, + pw + ); } private long GetFolderPackStreamSize(int folderIndex, int streamIndex) diff --git a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs index 6a2b8ea4..babae147 100644 --- a/src/SharpCompress/Common/SevenZip/ArchiveReader.cs +++ b/src/SharpCompress/Common/SevenZip/ArchiveReader.cs @@ -154,7 +154,11 @@ namespace SharpCompress.Common.SevenZip return ReadBitVector(length); } - private void ReadNumberVector(List dataVector, int numFiles, Action action) + private void ReadNumberVector( + List dataVector, + int numFiles, + Action action + ) { var defined = ReadOptionalBitVector(numFiles); @@ -191,12 +195,24 @@ namespace SharpCompress.Common.SevenZip return null; } - private void ReadDateTimeVector(List dataVector, int numFiles, Action action) + private void ReadDateTimeVector( + List dataVector, + int numFiles, + Action action + ) { - ReadNumberVector(dataVector, numFiles, (index, value) => action(index, TranslateTime(value))); + ReadNumberVector( + dataVector, + numFiles, + (index, value) => action(index, TranslateTime(value)) + ); } - private void ReadAttributeVector(List dataVector, int numFiles, Action action) + private void ReadAttributeVector( + List dataVector, + int numFiles, + Action action + ) { BitVector boolVector = ReadOptionalBitVector(numFiles); using (var streamSwitch = new CStreamSwitch()) @@ -251,7 +267,16 @@ namespace SharpCompress.Common.SevenZip 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) { @@ -269,7 +294,13 @@ namespace SharpCompress.Common.SevenZip 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 @@ -287,7 +318,13 @@ namespace SharpCompress.Common.SevenZip 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 } @@ -414,7 +451,11 @@ 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 --"); @@ -568,8 +609,12 @@ namespace SharpCompress.Common.SevenZip } } - private void ReadSubStreamsInfo(List folders, out List numUnpackStreamsInFolders, - out List unpackSizes, out List digests) + private void ReadSubStreamsInfo( + List folders, + out List numUnpackStreamsInFolders, + out List unpackSizes, + out List digests + ) { #if DEBUG Log.WriteLine("-- ReadSubStreamsInfo --"); @@ -739,7 +784,8 @@ namespace SharpCompress.Common.SevenZip out List folders, out List numUnpackStreamsInFolders, out List unpackSizes, - out List digests) + out List digests + ) { #if DEBUG Log.WriteLine("-- ReadStreamsInfo --"); @@ -768,7 +814,12 @@ namespace SharpCompress.Common.SevenZip ReadUnpackInfo(dataVector, out folders); break; case BlockType.SubStreamsInfo: - ReadSubStreamsInfo(folders, out numUnpackStreamsInFolders, out unpackSizes, out digests); + ReadSubStreamsInfo( + folders, + out numUnpackStreamsInFolders, + out unpackSizes, + out digests + ); break; default: throw new InvalidOperationException(); @@ -791,14 +842,16 @@ namespace SharpCompress.Common.SevenZip #endif try { - ReadStreamsInfo(null, - out long dataStartPos, - out List packSizes, - out List packCrCs, - out List folders, - out List numUnpackStreamsInFolders, - out List unpackSizes, - out List digests); + ReadStreamsInfo( + null, + out long dataStartPos, + out List packSizes, + out List packCrCs, + out List folders, + out List numUnpackStreamsInFolders, + out List unpackSizes, + out List digests + ); dataStartPos += baseOffset; @@ -815,23 +868,35 @@ namespace SharpCompress.Common.SevenZip dataStartPos += packSize; } - var outStream = DecoderStreamHelper.CreateDecoderStream(_stream, oldDataStartPos, myPackSizes, - folder, pass); + var outStream = DecoderStreamHelper.CreateDecoderStream( + _stream, + oldDataStartPos, + myPackSizes, + folder, + pass + ); int unpackSize = checked((int)folder.GetUnpackSize()); byte[] data = new byte[unpackSize]; outStream.ReadExact(data, 0, data.Length); if (outStream.ReadByte() >= 0) { - throw new InvalidOperationException("Decoded stream is longer than expected."); + throw new InvalidOperationException( + "Decoded stream is longer than expected." + ); } dataVector.Add(data); 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."); + throw new InvalidOperationException( + "Decoded stream does not match expected CRC." + ); } } } @@ -864,7 +929,10 @@ namespace SharpCompress.Common.SevenZip List dataVector = null; if (type == BlockType.AdditionalStreamsInfo) { - dataVector = ReadAndDecodePackedStreams(db._startPositionAfterHeader, getTextPassword); + dataVector = ReadAndDecodePackedStreams( + db._startPositionAfterHeader, + getTextPassword + ); type = ReadId(); } @@ -873,14 +941,16 @@ 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 unpackSizes, - out digests); + ReadStreamsInfo( + dataVector, + out db._dataStartPosition, + out db._packSizes, + out db._packCrCs, + out db._folders, + out db._numUnpackStreamsVector, + out unpackSizes, + out digests + ); db._dataStartPosition += db._startPositionAfterHeader; type = ReadId(); @@ -961,35 +1031,41 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write("WinAttributes:"); #endif - ReadAttributeVector(dataVector, numFiles, delegate (int i, uint? attr) - { - // Some third party implementations established an unofficial extension - // of the 7z archive format by placing posix file attributes in the high - // bits of the windows file attributes. This makes use of the fact that - // the official implementation does not perform checks on this value. - // - // Newer versions of the official 7z GUI client will try to parse this - // extension, thus acknowledging the unofficial use of these bits. - // - // For us it is safe to just discard the upper bits if they are set and - // keep the windows attributes from the lower bits (which should be set - // properly even if posix file attributes are present, in order to be - // compatible with older 7z archive readers) - // - // Note that the 15th bit is used by some implementations to indicate - // presence of the extension, but not all implementations do that so - // we can't trust that bit and must ignore it. - // - if (attr.HasValue && (attr.Value >> 16) != 0) - { - attr = attr.Value & 0x7FFFu; - } + ReadAttributeVector( + dataVector, + numFiles, + delegate(int i, uint? attr) + { + // Some third party implementations established an unofficial extension + // of the 7z archive format by placing posix file attributes in the high + // bits of the windows file attributes. This makes use of the fact that + // the official implementation does not perform checks on this value. + // + // Newer versions of the official 7z GUI client will try to parse this + // extension, thus acknowledging the unofficial use of these bits. + // + // For us it is safe to just discard the upper bits if they are set and + // keep the windows attributes from the lower bits (which should be set + // properly even if posix file attributes are present, in order to be + // compatible with older 7z archive readers) + // + // Note that the 15th bit is used by some implementations to indicate + // presence of the extension, but not all implementations do that so + // we can't trust that bit and must ignore it. + // + if (attr.HasValue && (attr.Value >> 16) != 0) + { + 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")); + Log.Write( + " " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a") + ); #endif - }); + } + ); #if DEBUG Log.WriteLine(); #endif @@ -1049,13 +1125,24 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write("StartPos:"); #endif - ReadNumberVector(dataVector, numFiles, delegate (int i, long? startPos) - { - db._files[i].StartPos = startPos; + ReadNumberVector( + dataVector, + numFiles, + delegate(int i, long? startPos) + { + db._files[i].StartPos = startPos; #if DEBUG - Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a")); + Log.Write( + " " + + ( + startPos.HasValue + ? startPos.Value.ToString() + : "n/a" + ) + ); #endif - }); + } + ); #if DEBUG Log.WriteLine(); #endif @@ -1064,13 +1151,19 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write("CTime:"); #endif - ReadDateTimeVector(dataVector, numFiles, delegate (int i, DateTime? time) - { - db._files[i].CTime = time; + ReadDateTimeVector( + dataVector, + numFiles, + delegate(int i, DateTime? time) + { + db._files[i].CTime = time; #if DEBUG - Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); + Log.Write( + " " + (time.HasValue ? time.Value.ToString() : "n/a") + ); #endif - }); + } + ); #if DEBUG Log.WriteLine(); #endif @@ -1079,13 +1172,19 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write("ATime:"); #endif - ReadDateTimeVector(dataVector, numFiles, delegate (int i, DateTime? time) - { - db._files[i].ATime = time; + ReadDateTimeVector( + dataVector, + numFiles, + delegate(int i, DateTime? time) + { + db._files[i].ATime = time; #if DEBUG - Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); + Log.Write( + " " + (time.HasValue ? time.Value.ToString() : "n/a") + ); #endif - }); + } + ); #if DEBUG Log.WriteLine(); #endif @@ -1094,13 +1193,19 @@ namespace SharpCompress.Common.SevenZip #if DEBUG Log.Write("MTime:"); #endif - ReadDateTimeVector(dataVector, numFiles, delegate (int i, DateTime? time) - { - db._files[i].MTime = time; + ReadDateTimeVector( + dataVector, + numFiles, + delegate(int i, DateTime? time) + { + db._files[i].MTime = time; #if DEBUG - Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a")); + Log.Write( + " " + (time.HasValue ? time.Value.ToString() : "n/a") + ); #endif - }); + } + ); #if DEBUG Log.WriteLine(); #endif @@ -1175,7 +1280,7 @@ namespace SharpCompress.Common.SevenZip // TODO: Check Signature! _header = new byte[0x20]; - for (int offset = 0; offset < 0x20;) + for (int offset = 0; offset < 0x20; ) { int delta = stream.Read(_header, offset, 0x20 - offset); if (delta == 0) @@ -1273,7 +1378,10 @@ 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) @@ -1346,7 +1454,11 @@ namespace SharpCompress.Common.SevenZip public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -1369,7 +1481,10 @@ 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(); @@ -1449,8 +1564,13 @@ namespace SharpCompress.Common.SevenZip packSizes[j] = db._packSizes[packStreamIndex + j]; } - s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes, folderInfo, - db.PasswordProvider); + s = DecoderStreamHelper.CreateDecoderStream( + _stream, + folderStartPackPos, + packSizes, + folderInfo, + db.PasswordProvider + ); _cachedStreams.Add(folderIndex, s); } return s; @@ -1482,9 +1602,7 @@ namespace SharpCompress.Common.SevenZip { bool allFilesMode = (indices is null); - int numItems = allFilesMode - ? db._files.Count - : indices.Length; + int numItems = allFilesMode ? db._files.Count : indices.Length; if (numItems == 0) { @@ -1503,7 +1621,10 @@ namespace SharpCompress.Common.SevenZip continue; } - if (extractFolderInfoVector.Count == 0 || folderIndex != extractFolderInfoVector.Last()._folderIndex) + if ( + extractFolderInfoVector.Count == 0 + || folderIndex != extractFolderInfoVector.Last()._folderIndex + ) { extractFolderInfoVector.Add(new CExtractFolderInfo(-1, folderIndex)); } @@ -1511,7 +1632,11 @@ namespace SharpCompress.Common.SevenZip CExtractFolderInfo efi = extractFolderInfoVector.Last(); int startIndex = db._folderStartFileIndex[folderIndex]; - for (int index = efi._extractStatuses.Count; index <= fileIndex - startIndex; index++) + for ( + int index = efi._extractStatuses.Count; + index <= fileIndex - startIndex; + index++ + ) { efi._extractStatuses.Add(index == fileIndex - startIndex); } @@ -1552,8 +1677,13 @@ namespace SharpCompress.Common.SevenZip // TODO: If the decoding fails the last file may be extracted incompletely. Delete it? - Stream s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes, - folderInfo, db.PasswordProvider); + Stream s = DecoderStreamHelper.CreateDecoderStream( + _stream, + folderStartPackPos, + packSizes, + folderInfo, + db.PasswordProvider + ); buffer ??= new byte[4 << 10]; for (; ; ) { diff --git a/src/SharpCompress/Common/SevenZip/CBindPair.cs b/src/SharpCompress/Common/SevenZip/CBindPair.cs index ad947967..1d76acf0 100644 --- a/src/SharpCompress/Common/SevenZip/CBindPair.cs +++ b/src/SharpCompress/Common/SevenZip/CBindPair.cs @@ -5,4 +5,4 @@ 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 af6345d3..5db367b2 100644 --- a/src/SharpCompress/Common/SevenZip/CCoderInfo.cs +++ b/src/SharpCompress/Common/SevenZip/CCoderInfo.cs @@ -9,4 +9,4 @@ namespace SharpCompress.Common.SevenZip internal int _numInStreams; internal int _numOutStreams; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/CFileItem.cs b/src/SharpCompress/Common/SevenZip/CFileItem.cs index 7624f8b3..a97d2c9b 100644 --- a/src/SharpCompress/Common/SevenZip/CFileItem.cs +++ b/src/SharpCompress/Common/SevenZip/CFileItem.cs @@ -35,4 +35,4 @@ namespace SharpCompress.Common.SevenZip HasStream = true; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/CMethodId.cs b/src/SharpCompress/Common/SevenZip/CMethodId.cs index 5069b051..871989e4 100644 --- a/src/SharpCompress/Common/SevenZip/CMethodId.cs +++ b/src/SharpCompress/Common/SevenZip/CMethodId.cs @@ -54,4 +54,4 @@ return bytes; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/CStreamSwitch.cs b/src/SharpCompress/Common/SevenZip/CStreamSwitch.cs index c1cd51c9..706bfc55 100644 --- a/src/SharpCompress/Common/SevenZip/CStreamSwitch.cs +++ b/src/SharpCompress/Common/SevenZip/CStreamSwitch.cs @@ -66,4 +66,4 @@ namespace SharpCompress.Common.SevenZip } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/DataReader.cs b/src/SharpCompress/Common/SevenZip/DataReader.cs index 48fcd099..ad20a491 100644 --- a/src/SharpCompress/Common/SevenZip/DataReader.cs +++ b/src/SharpCompress/Common/SevenZip/DataReader.cs @@ -12,21 +12,21 @@ namespace SharpCompress.Common.SevenZip public static uint Get32(byte[] buffer, int offset) { return buffer[offset] - + ((uint)buffer[offset + 1] << 8) - + ((uint)buffer[offset + 2] << 16) - + ((uint)buffer[offset + 3] << 24); + + ((uint)buffer[offset + 1] << 8) + + ((uint)buffer[offset + 2] << 16) + + ((uint)buffer[offset + 3] << 24); } public static ulong Get64(byte[] buffer, int offset) { return buffer[offset] - + ((ulong)buffer[offset + 1] << 8) - + ((ulong)buffer[offset + 2] << 16) - + ((ulong)buffer[offset + 3] << 24) - + ((ulong)buffer[offset + 4] << 32) - + ((ulong)buffer[offset + 5] << 40) - + ((ulong)buffer[offset + 6] << 48) - + ((ulong)buffer[offset + 7] << 56); + + ((ulong)buffer[offset + 1] << 8) + + ((ulong)buffer[offset + 2] << 16) + + ((ulong)buffer[offset + 3] << 24) + + ((ulong)buffer[offset + 4] << 32) + + ((ulong)buffer[offset + 5] << 40) + + ((ulong)buffer[offset + 6] << 48) + + ((ulong)buffer[offset + 7] << 56); } #endregion @@ -183,4 +183,4 @@ namespace SharpCompress.Common.SevenZip #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs b/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs index d2dd2cd1..7be12a96 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipEntry.cs @@ -38,8 +38,9 @@ namespace SharpCompress.Common.SevenZip public override bool IsSplitAfter => false; - public override int? Attrib => FilePart.Header.Attrib.HasValue ? (int?)FilePart.Header.Attrib.Value : null; + public override int? Attrib => + FilePart.Header.Attrib.HasValue ? (int?)FilePart.Header.Attrib.Value : null; internal override IEnumerable Parts => FilePart.AsEnumerable(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs index 4a5a8d43..e6927712 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs @@ -11,8 +11,13 @@ namespace SharpCompress.Common.SevenZip private readonly Stream _stream; private readonly ArchiveDatabase _database; - internal SevenZipFilePart(Stream stream, ArchiveDatabase database, int index, CFileItem fileEntry, ArchiveEncoding archiveEncoding) - : base(archiveEncoding) + internal SevenZipFilePart( + Stream stream, + ArchiveDatabase database, + int index, + CFileItem fileEntry, + ArchiveEncoding archiveEncoding + ) : base(archiveEncoding) { _stream = stream; _database = database; @@ -40,9 +45,15 @@ namespace SharpCompress.Common.SevenZip { return null!; } - var folderStream = _database.GetFolderStream(_stream, Folder!, _database.PasswordProvider); + 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++) @@ -86,22 +97,23 @@ namespace SharpCompress.Common.SevenZip { case K_LZMA: case K_LZMA2: - { - return CompressionType.LZMA; - } + { + return CompressionType.LZMA; + } case K_PPMD: - { - return CompressionType.PPMd; - } + { + return CompressionType.PPMd; + } case K_B_ZIP2: - { - return CompressionType.BZip2; - } + { + return CompressionType.BZip2; + } default: throw new NotImplementedException(); } } - internal bool IsEncrypted => Folder!._coders.FindIndex(c => c._methodId._id == CMethodId.K_AES_ID) != -1; + internal bool IsEncrypted => + Folder!._coders.FindIndex(c => c._methodId._id == CMethodId.K_AES_ID) != -1; } } diff --git a/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs b/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs index 79d6c9d0..19e7b2f0 100644 --- a/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs +++ b/src/SharpCompress/Common/SevenZip/SevenZipVolume.cs @@ -6,8 +6,6 @@ namespace SharpCompress.Common.SevenZip public class SevenZipVolume : Volume { public SevenZipVolume(Stream stream, ReaderOptions readerFactoryOptions, int index = 0) - : base(stream, readerFactoryOptions, index) - { - } + : base(stream, readerFactoryOptions, index) { } } } diff --git a/src/SharpCompress/Common/Tar/Headers/EntryType.cs b/src/SharpCompress/Common/Tar/Headers/EntryType.cs index 06ba1f0d..feeaa6cc 100644 --- a/src/SharpCompress/Common/Tar/Headers/EntryType.cs +++ b/src/SharpCompress/Common/Tar/Headers/EntryType.cs @@ -16,4 +16,4 @@ VolumeHeader = (byte)'V', GlobalExtendedHeader = (byte)'g' } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs index 6dad0682..e9b38971 100644 --- a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs +++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs @@ -9,7 +9,15 @@ namespace SharpCompress.Common.Tar.Headers { internal sealed 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) { @@ -79,7 +87,11 @@ namespace SharpCompress.Common.Tar.Headers // var truncated = Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(bytes, 0, 100)); // // and then infinite recursion is occured in WriteLongFilenameHeader because truncated.Length is 102. - Name = ArchiveEncoding.Decode(ArchiveEncoding.Encode(Name), 0, 100 - ArchiveEncoding.GetEncoding().GetMaxByteCount(1)); + Name = ArchiveEncoding.Decode( + ArchiveEncoding.Encode(Name), + 0, + 100 - ArchiveEncoding.GetEncoding().GetMaxByteCount(1) + ); Write(output); } } @@ -126,7 +138,7 @@ namespace SharpCompress.Common.Tar.Headers Size = ReadSize(buffer); Mode = ReadAsciiInt64Base8(buffer, 100, 7); - if(EntryType == EntryType.Directory) + if (EntryType == EntryType.Directory) Mode |= 0b1_000_000_000; UserId = ReadAsciiInt64Base8(buffer, 108, 7); @@ -136,8 +148,7 @@ namespace SharpCompress.Common.Tar.Headers Magic = ArchiveEncoding.Decode(buffer, 257, 6).TrimNulls(); - if (!string.IsNullOrEmpty(Magic) - && "ustar".Equals(Magic)) + if (!string.IsNullOrEmpty(Magic) && "ustar".Equals(Magic)) { string namePrefix = ArchiveEncoding.Decode(buffer, 345, 157); namePrefix = namePrefix.TrimNulls(); @@ -146,8 +157,7 @@ namespace SharpCompress.Common.Tar.Headers Name = namePrefix + "/" + Name; } } - if (EntryType != EntryType.LongName - && Name.Length == 0) + if (EntryType != EntryType.LongName && Name.Length == 0) { return false; } @@ -261,10 +271,16 @@ namespace SharpCompress.Common.Tar.Headers return Convert.ToInt64(s); } - - private static readonly byte[] eightSpaces = { - (byte)' ', (byte)' ', (byte)' ', (byte)' ', - (byte)' ', (byte)' ', (byte)' ', (byte)' ' + private static readonly byte[] eightSpaces = + { + (byte)' ', + (byte)' ', + (byte)' ', + (byte)' ', + (byte)' ', + (byte)' ', + (byte)' ', + (byte)' ' }; internal static int RecalculateChecksum(byte[] buf) diff --git a/src/SharpCompress/Common/Tar/TarEntry.cs b/src/SharpCompress/Common/Tar/TarEntry.cs index 7de745c8..59434661 100644 --- a/src/SharpCompress/Common/Tar/TarEntry.cs +++ b/src/SharpCompress/Common/Tar/TarEntry.cs @@ -47,13 +47,17 @@ namespace SharpCompress.Common.Tar public long Mode => _filePart.Header.Mode; public long UserID => _filePart.Header.UserId; - + public long GroupId => _filePart.Header.GroupId; internal override IEnumerable Parts => _filePart.AsEnumerable(); - internal static IEnumerable GetEntries(StreamingMode mode, Stream stream, - CompressionType compressionType, ArchiveEncoding archiveEncoding) + internal static IEnumerable GetEntries( + StreamingMode mode, + Stream stream, + CompressionType compressionType, + ArchiveEncoding archiveEncoding + ) { foreach (TarHeader h in TarHeaderFactory.ReadHeader(mode, stream, archiveEncoding)) { @@ -71,4 +75,4 @@ namespace SharpCompress.Common.Tar } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Tar/TarFilePart.cs b/src/SharpCompress/Common/Tar/TarFilePart.cs index 2e11db3d..f71a41a8 100644 --- a/src/SharpCompress/Common/Tar/TarFilePart.cs +++ b/src/SharpCompress/Common/Tar/TarFilePart.cs @@ -8,8 +8,7 @@ namespace SharpCompress.Common.Tar { private readonly Stream _seekableStream; - internal TarFilePart(TarHeader header, Stream seekableStream) - : base(header.ArchiveEncoding) + internal TarFilePart(TarHeader header, Stream seekableStream) : base(header.ArchiveEncoding) { _seekableStream = seekableStream; Header = header; @@ -34,4 +33,4 @@ namespace SharpCompress.Common.Tar return null; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Tar/TarHeaderFactory.cs b/src/SharpCompress/Common/Tar/TarHeaderFactory.cs index eb4d7464..6a9e8327 100644 --- a/src/SharpCompress/Common/Tar/TarHeaderFactory.cs +++ b/src/SharpCompress/Common/Tar/TarHeaderFactory.cs @@ -7,7 +7,11 @@ namespace SharpCompress.Common.Tar { internal static class TarHeaderFactory { - internal static IEnumerable ReadHeader(StreamingMode mode, Stream stream, ArchiveEncoding archiveEncoding) + internal static IEnumerable ReadHeader( + StreamingMode mode, + Stream stream, + ArchiveEncoding archiveEncoding + ) { while (true) { @@ -24,6 +28,7 @@ namespace SharpCompress.Common.Tar switch (mode) { case StreamingMode.Seekable: + { header.DataStartPosition = reader.BaseStream.Position; @@ -32,14 +37,15 @@ namespace SharpCompress.Common.Tar } break; case StreamingMode.Streaming: + { header.PackedStream = new TarReadOnlySubStream(stream, header.Size); } break; default: - { - throw new InvalidFormatException("Invalid StreamingMode"); - } + { + throw new InvalidFormatException("Invalid StreamingMode"); + } } } catch @@ -60,4 +66,4 @@ namespace SharpCompress.Common.Tar return 512 - zeros + size; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs index f0782c6e..bea2858f 100644 --- a/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs +++ b/src/SharpCompress/Common/Tar/TarReadOnlySubStream.cs @@ -9,7 +9,8 @@ namespace SharpCompress.Common.Tar private bool _isDisposed; private long _amountRead; - public TarReadOnlySubStream(Stream stream, long bytesToRead) : base(stream, throwOnDispose: false) + public TarReadOnlySubStream(Stream stream, long bytesToRead) + : base(stream, throwOnDispose: false) { BytesLeftToRead = bytesToRead; } @@ -56,7 +57,11 @@ namespace SharpCompress.Common.Tar public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -86,7 +91,6 @@ namespace SharpCompress.Common.Tar ++_amountRead; } return value; - } public override long Seek(long offset, SeekOrigin origin) @@ -104,4 +108,4 @@ namespace SharpCompress.Common.Tar throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Tar/TarVolume.cs b/src/SharpCompress/Common/Tar/TarVolume.cs index 5b76c56f..4b914920 100644 --- a/src/SharpCompress/Common/Tar/TarVolume.cs +++ b/src/SharpCompress/Common/Tar/TarVolume.cs @@ -6,8 +6,6 @@ namespace SharpCompress.Common.Tar public class TarVolume : Volume { public TarVolume(Stream stream, ReaderOptions readerOptions, int index = 0) - : base(stream, readerOptions, index) - { - } + : base(stream, readerOptions, index) { } } } diff --git a/src/SharpCompress/Common/Volume.cs b/src/SharpCompress/Common/Volume.cs index 8e1446b9..ac716b67 100644 --- a/src/SharpCompress/Common/Volume.cs +++ b/src/SharpCompress/Common/Volume.cs @@ -32,7 +32,10 @@ namespace SharpCompress.Common public virtual int Index { get; internal set; } - public string FileName { get { return (_actualStream as FileStream)?.Name!; } } + public string FileName + { + get { return (_actualStream as FileStream)?.Name!; } + } /// /// RarArchive is part of a multi-part archive. diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs index db950602..42c8865c 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs @@ -4,10 +4,7 @@ namespace SharpCompress.Common.Zip.Headers { internal class DirectoryEndHeader : ZipHeader { - public DirectoryEndHeader() - : base(ZipHeaderType.DirectoryEnd) - { - } + public DirectoryEndHeader() : base(ZipHeaderType.DirectoryEnd) { } internal override void Read(BinaryReader reader) { @@ -37,8 +34,9 @@ namespace SharpCompress.Common.Zip.Headers public ushort TotalNumberOfEntries { get; private set; } - public bool IsZip64 => TotalNumberOfEntriesInDisk == ushort.MaxValue - || DirectorySize == uint.MaxValue - || DirectoryStartOffsetRelativeToDisk == uint.MaxValue; + public bool IsZip64 => + TotalNumberOfEntriesInDisk == ushort.MaxValue + || DirectorySize == uint.MaxValue + || DirectoryStartOffsetRelativeToDisk == uint.MaxValue; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs index 8b55dcd6..0a28c602 100644 --- a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs @@ -6,9 +6,7 @@ namespace SharpCompress.Common.Zip.Headers internal class DirectoryEntryHeader : ZipFileEntry { public DirectoryEntryHeader(ArchiveEncoding archiveEncoding) - : base(ZipHeaderType.DirectoryEntry, archiveEncoding) - { - } + : base(ZipHeaderType.DirectoryEntry, archiveEncoding) { } internal override void Read(BinaryReader reader) { @@ -54,16 +52,25 @@ namespace SharpCompress.Common.Zip.Headers LoadExtra(extra); - var unicodePathExtra = Extra.FirstOrDefault(u => u.Type == ExtraDataType.UnicodePathExtraField); + var unicodePathExtra = Extra.FirstOrDefault( + u => u.Type == ExtraDataType.UnicodePathExtraField + ); if (unicodePathExtra != null && ArchiveEncoding.Forced == null) { Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName; } - var zip64ExtraData = Extra.OfType().FirstOrDefault(); + var zip64ExtraData = Extra + .OfType() + .FirstOrDefault(); if (zip64ExtraData != null) { - zip64ExtraData.Process(UncompressedSize, CompressedSize, RelativeOffsetOfEntryHeader, DiskNumberStart); + zip64ExtraData.Process( + UncompressedSize, + CompressedSize, + RelativeOffsetOfEntryHeader, + DiskNumberStart + ); if (CompressedSize == uint.MaxValue) { @@ -96,4 +103,4 @@ namespace SharpCompress.Common.Zip.Headers public string? Comment { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs b/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs index 92aaaca7..09cf7f29 100644 --- a/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs +++ b/src/SharpCompress/Common/Zip/Headers/HeaderFlags.cs @@ -11,7 +11,8 @@ namespace SharpCompress.Common.Zip.Headers Bit2 = 4, UsePostDataDescriptor = 8, EnhancedDeflate = 16, - //Bit 11: Language encoding flag + + //Bit 11: Language encoding flag Efs = 2048 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs b/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs index 0a086ad7..6957f62f 100644 --- a/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs @@ -4,13 +4,8 @@ namespace SharpCompress.Common.Zip.Headers { internal class IgnoreHeader : ZipHeader { - public IgnoreHeader(ZipHeaderType type) - : base(type) - { - } + public IgnoreHeader(ZipHeaderType type) : base(type) { } - internal override void Read(BinaryReader reader) - { - } + internal override void Read(BinaryReader reader) { } } -} \ 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 422ca6f4..e3fc8071 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs @@ -6,9 +6,7 @@ namespace SharpCompress.Common.Zip.Headers internal class LocalEntryHeader : ZipFileEntry { public LocalEntryHeader(ArchiveEncoding archiveEncoding) - : base(ZipHeaderType.LocalEntry, archiveEncoding) - { - } + : base(ZipHeaderType.LocalEntry, archiveEncoding) { } internal override void Read(BinaryReader reader) { @@ -44,13 +42,17 @@ namespace SharpCompress.Common.Zip.Headers LoadExtra(extra); - var unicodePathExtra = Extra.FirstOrDefault(u => u.Type == ExtraDataType.UnicodePathExtraField); + var unicodePathExtra = Extra.FirstOrDefault( + u => u.Type == ExtraDataType.UnicodePathExtraField + ); if (unicodePathExtra != null && ArchiveEncoding.Forced == null) { Name = ((ExtraUnicodePathExtraField)unicodePathExtra).UnicodeName; } - var zip64ExtraData = Extra.OfType().FirstOrDefault(); + var zip64ExtraData = Extra + .OfType() + .FirstOrDefault(); if (zip64ExtraData != null) { zip64ExtraData.Process(UncompressedSize, CompressedSize, 0, 0); @@ -68,4 +70,4 @@ namespace SharpCompress.Common.Zip.Headers internal ushort Version { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs index efc7af3a..74d1b224 100644 --- a/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs +++ b/src/SharpCompress/Common/Zip/Headers/LocalEntryHeaderExtraFactory.cs @@ -33,9 +33,7 @@ namespace SharpCompress.Common.Zip.Headers internal sealed class ExtraUnicodePathExtraField : ExtraData { public ExtraUnicodePathExtraField(ExtraDataType type, ushort length, byte[] dataBytes) - : base(type, length, dataBytes) - { - } + : base(type, length, dataBytes) { } internal byte Version => DataBytes[0]; @@ -63,10 +61,11 @@ namespace SharpCompress.Common.Zip.Headers internal sealed class Zip64ExtendedInformationExtraField : ExtraData { - public Zip64ExtendedInformationExtraField(ExtraDataType type, ushort length, byte[] dataBytes) - : base(type, length, dataBytes) - { - } + public Zip64ExtendedInformationExtraField( + ExtraDataType type, + ushort length, + byte[] dataBytes + ) : base(type, length, dataBytes) { } // From the spec, values are only in the extradata if the standard // value is set to 0xFFFFFFFF (or 0xFFFF for the Disk Start Number). @@ -75,9 +74,15 @@ namespace SharpCompress.Common.Zip.Headers // - Compressed Size // - Relative Header Offset // - Disk Start Number - public void Process(long uncompressedFileSize, long compressedFileSize, long relativeHeaderOffset, ushort diskNumber) + public void Process( + long uncompressedFileSize, + long compressedFileSize, + long relativeHeaderOffset, + ushort diskNumber + ) { - var bytesRequired = ((uncompressedFileSize == uint.MaxValue) ? 8 : 0) + var bytesRequired = + ((uncompressedFileSize == uint.MaxValue) ? 8 : 0) + ((compressedFileSize == uint.MaxValue) ? 8 : 0) + ((relativeHeaderOffset == uint.MaxValue) ? 8 : 0) + ((diskNumber == ushort.MaxValue) ? 4 : 0); @@ -85,30 +90,40 @@ namespace SharpCompress.Common.Zip.Headers if (bytesRequired > DataBytes.Length) { - throw new ArchiveException("Zip64 extended information extra field is not large enough for the required information"); + throw new ArchiveException( + "Zip64 extended information extra field is not large enough for the required information" + ); } if (uncompressedFileSize == uint.MaxValue) { - UncompressedSize = BinaryPrimitives.ReadInt64LittleEndian(DataBytes.AsSpan(currentIndex)); + UncompressedSize = BinaryPrimitives.ReadInt64LittleEndian( + DataBytes.AsSpan(currentIndex) + ); currentIndex += 8; } if (compressedFileSize == uint.MaxValue) { - CompressedSize = BinaryPrimitives.ReadInt64LittleEndian(DataBytes.AsSpan(currentIndex)); + CompressedSize = BinaryPrimitives.ReadInt64LittleEndian( + DataBytes.AsSpan(currentIndex) + ); currentIndex += 8; } if (relativeHeaderOffset == uint.MaxValue) { - RelativeOffsetOfEntryHeader = BinaryPrimitives.ReadInt64LittleEndian(DataBytes.AsSpan(currentIndex)); + RelativeOffsetOfEntryHeader = BinaryPrimitives.ReadInt64LittleEndian( + DataBytes.AsSpan(currentIndex) + ); currentIndex += 8; } if (diskNumber == ushort.MaxValue) { - VolumeNumber = BinaryPrimitives.ReadUInt32LittleEndian(DataBytes.AsSpan(currentIndex)); + VolumeNumber = BinaryPrimitives.ReadUInt32LittleEndian( + DataBytes.AsSpan(currentIndex) + ); } } @@ -143,8 +158,10 @@ namespace SharpCompress.Common.Zip.Headers { return type switch { - ExtraDataType.UnicodePathExtraField => new ExtraUnicodePathExtraField(type, length, extraData), - ExtraDataType.Zip64ExtendedInformationExtraField => new Zip64ExtendedInformationExtraField(type, length, extraData), + ExtraDataType.UnicodePathExtraField + => new ExtraUnicodePathExtraField(type, length, extraData), + ExtraDataType.Zip64ExtendedInformationExtraField + => new Zip64ExtendedInformationExtraField(type, length, extraData), _ => new ExtraData(type, length, extraData) }; } diff --git a/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs b/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs index ee7ca0b8..7a20430c 100644 --- a/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs @@ -5,14 +5,11 @@ namespace SharpCompress.Common.Zip.Headers { internal class SplitHeader : ZipHeader { - public SplitHeader() - : base(ZipHeaderType.Split) - { - } + public SplitHeader() : base(ZipHeaderType.Split) { } internal override void Read(BinaryReader reader) { throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs index 0e0b72fb..fffbbabf 100644 --- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs @@ -4,10 +4,7 @@ namespace SharpCompress.Common.Zip.Headers { internal class Zip64DirectoryEndHeader : ZipHeader { - public Zip64DirectoryEndHeader() - : base(ZipHeaderType.Zip64DirectoryEnd) - { - } + public Zip64DirectoryEndHeader() : base(ZipHeaderType.Zip64DirectoryEnd) { } internal override void Read(BinaryReader reader) { @@ -20,7 +17,12 @@ namespace SharpCompress.Common.Zip.Headers TotalNumberOfEntries = (long)reader.ReadUInt64(); DirectorySize = (long)reader.ReadUInt64(); DirectoryStartOffsetRelativeToDisk = (long)reader.ReadUInt64(); - DataSector = reader.ReadBytes((int)(SizeOfDirectoryEndRecord - SIZE_OF_FIXED_HEADER_DATA_EXCEPT_SIGNATURE_AND_SIZE_FIELDS)); + DataSector = reader.ReadBytes( + (int)( + SizeOfDirectoryEndRecord + - SIZE_OF_FIXED_HEADER_DATA_EXCEPT_SIGNATURE_AND_SIZE_FIELDS + ) + ); } private const int SIZE_OF_FIXED_HEADER_DATA_EXCEPT_SIGNATURE_AND_SIZE_FIELDS = 44; @@ -45,4 +47,4 @@ namespace SharpCompress.Common.Zip.Headers public byte[]? DataSector { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs index 82a6562e..16724668 100644 --- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs @@ -4,10 +4,7 @@ namespace SharpCompress.Common.Zip.Headers { internal class Zip64DirectoryEndLocatorHeader : ZipHeader { - public Zip64DirectoryEndLocatorHeader() - : base(ZipHeaderType.Zip64DirectoryEndLocator) - { - } + public Zip64DirectoryEndLocatorHeader() : base(ZipHeaderType.Zip64DirectoryEndLocator) { } internal override void Read(BinaryReader reader) { @@ -22,4 +19,4 @@ namespace SharpCompress.Common.Zip.Headers public uint TotalNumberOfVolumes { get; private set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs index 5c72d54c..40d5c313 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs @@ -9,8 +9,7 @@ namespace SharpCompress.Common.Zip.Headers { internal abstract class ZipFileEntry : ZipHeader { - protected ZipFileEntry(ZipHeaderType type, ArchiveEncoding archiveEncoding) - : base(type) + protected ZipFileEntry(ZipHeaderType type, ArchiveEncoding archiveEncoding) : base(type) { Extra = new List(); ArchiveEncoding = archiveEncoding; @@ -26,9 +25,7 @@ namespace SharpCompress.Common.Zip.Headers } //.NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers - return CompressedSize == 0 - && UncompressedSize == 0 - && Name.EndsWith('\\'); + return CompressedSize == 0 && UncompressedSize == 0 && Name.EndsWith('\\'); } } @@ -62,7 +59,8 @@ namespace SharpCompress.Common.Zip.Headers var buffer = new byte[12]; archiveStream.ReadFully(buffer); - PkwareTraditionalEncryptionData encryptionData = PkwareTraditionalEncryptionData.ForRead(Password!, this, buffer); + PkwareTraditionalEncryptionData encryptionData = + PkwareTraditionalEncryptionData.ForRead(Password!, this, buffer); return encryptionData; } @@ -77,9 +75,10 @@ namespace SharpCompress.Common.Zip.Headers protected void LoadExtra(byte[] extra) { - for (int i = 0; i < extra.Length - 4;) + for (int i = 0; i < extra.Length - 4; ) { - ExtraDataType type = (ExtraDataType)BinaryPrimitives.ReadUInt16LittleEndian(extra.AsSpan(i)); + ExtraDataType type = (ExtraDataType) + BinaryPrimitives.ReadUInt16LittleEndian(extra.AsSpan(i)); if (!Enum.IsDefined(typeof(ExtraDataType), type)) { type = ExtraDataType.NotImplementedExtraData; diff --git a/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs b/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs index d62513da..43042630 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipHeader.cs @@ -16,4 +16,4 @@ namespace SharpCompress.Common.Zip.Headers internal bool HasData { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/Headers/ZipHeaderType.cs b/src/SharpCompress/Common/Zip/Headers/ZipHeaderType.cs index a4286ded..85f6c3b6 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipHeaderType.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipHeaderType.cs @@ -10,4 +10,4 @@ Zip64DirectoryEnd, Zip64DirectoryEndLocator } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs b/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs index bad5056d..71556292 100644 --- a/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/PkwareTraditionalCryptoStream.cs @@ -16,7 +16,11 @@ namespace SharpCompress.Common.Zip private readonly Stream _stream; private bool _isDisposed; - public PkwareTraditionalCryptoStream(Stream stream, PkwareTraditionalEncryptionData encryptor, CryptoMode mode) + public PkwareTraditionalCryptoStream( + Stream stream, + PkwareTraditionalEncryptionData encryptor, + CryptoMode mode + ) { this._encryptor = encryptor; this._stream = stream; @@ -31,7 +35,11 @@ namespace SharpCompress.Common.Zip public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -105,4 +113,4 @@ namespace SharpCompress.Common.Zip _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 4021f957..96a88e94 100644 --- a/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/PkwareTraditionalEncryptionData.cs @@ -25,8 +25,11 @@ namespace SharpCompress.Common.Zip } } - public static PkwareTraditionalEncryptionData ForRead(string password, ZipFileEntry header, - byte[] encryptionHeader) + public static PkwareTraditionalEncryptionData ForRead( + string password, + ZipFileEntry header, + byte[] encryptionHeader + ) { var encryptor = new PkwareTraditionalEncryptionData(password, header.ArchiveEncoding); byte[] plainTextHeader = encryptor.Decrypt(encryptionHeader, encryptionHeader.Length); @@ -48,8 +51,10 @@ namespace SharpCompress.Common.Zip { if (length > cipherText.Length) { - throw new ArgumentOutOfRangeException(nameof(length), - "Bad length during Decryption: the length parameter must be smaller than or equal to the size of the destination array."); + throw new ArgumentOutOfRangeException( + nameof(length), + "Bad length during Decryption: the length parameter must be smaller than or equal to the size of the destination array." + ); } var plainText = new byte[length]; @@ -71,8 +76,10 @@ namespace SharpCompress.Common.Zip if (length > plainText.Length) { - throw new ArgumentOutOfRangeException(nameof(length), - "Bad length during Encryption: The length parameter must be smaller than or equal to the size of the destination array."); + throw new ArgumentOutOfRangeException( + nameof(length), + "Bad length during Encryption: The length parameter must be smaller than or equal to the size of the destination array." + ); } var cipherText = new byte[length]; @@ -108,4 +115,4 @@ namespace SharpCompress.Common.Zip _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/SeekableZipFilePart.cs b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs index a2046190..02a40c38 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs @@ -10,8 +10,11 @@ namespace SharpCompress.Common.Zip private readonly SeekableZipHeaderFactory _headerFactory; private readonly DirectoryEntryHeader _directoryEntryHeader; - internal SeekableZipFilePart(SeekableZipHeaderFactory headerFactory, DirectoryEntryHeader header, Stream stream) - : base(header, stream) + internal SeekableZipFilePart( + SeekableZipHeaderFactory headerFactory, + DirectoryEntryHeader header, + Stream stream + ) : base(header, stream) { _headerFactory = headerFactory; _directoryEntryHeader = header; @@ -40,10 +43,12 @@ namespace SharpCompress.Common.Zip { BaseStream.Position = Header.DataStartPosition!.Value; - if ((Header.CompressedSize == 0) + if ( + (Header.CompressedSize == 0) && FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) && (_directoryEntryHeader?.HasData == true) - && (_directoryEntryHeader?.CompressedSize != 0)) + && (_directoryEntryHeader?.CompressedSize != 0) + ) { return new ReadOnlySubStream(BaseStream, _directoryEntryHeader!.CompressedSize); } @@ -51,4 +56,4 @@ namespace SharpCompress.Common.Zip return BaseStream; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs index 8f9fd879..ab730bf5 100644 --- a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs @@ -10,14 +10,13 @@ namespace SharpCompress.Common.Zip { private const int MINIMUM_EOCD_LENGTH = 22; private const int ZIP64_EOCD_LENGTH = 20; + // Comment may be within 64kb + structure 22 bytes private const int MAX_SEARCH_LENGTH_FOR_EOCD = 65557; private bool _zip64; internal SeekableZipHeaderFactory(string? password, ArchiveEncoding archiveEncoding) - : base(StreamingMode.Seekable, password, archiveEncoding) - { - } + : base(StreamingMode.Seekable, password, archiveEncoding) { } internal IEnumerable ReadSeekableHeader(Stream stream) { @@ -98,15 +97,21 @@ namespace SharpCompress.Common.Zip return true; } + private static void SeekBackToHeader(Stream stream, BinaryReader reader) { // Minimum EOCD length if (stream.Length < MINIMUM_EOCD_LENGTH) { - throw new ArchiveException("Could not find Zip file Directory at the end of the file. File may be corrupted."); + throw new ArchiveException( + "Could not find Zip file Directory at the end of the file. File may be corrupted." + ); } - int len = stream.Length < MAX_SEARCH_LENGTH_FOR_EOCD ? (int)stream.Length : MAX_SEARCH_LENGTH_FOR_EOCD; + int len = + stream.Length < MAX_SEARCH_LENGTH_FOR_EOCD + ? (int)stream.Length + : MAX_SEARCH_LENGTH_FOR_EOCD; // We search for marker in reverse to find the first occurance byte[] needle = { 0x06, 0x05, 0x4b, 0x50 }; @@ -132,7 +137,10 @@ namespace SharpCompress.Common.Zip throw new ArchiveException("Failed to locate the Zip Header"); } - internal LocalEntryHeader GetLocalHeader(Stream stream, DirectoryEntryHeader directoryEntryHeader) + internal LocalEntryHeader GetLocalHeader( + Stream stream, + DirectoryEntryHeader directoryEntryHeader + ) { stream.Seek(directoryEntryHeader.RelativeOffsetOfEntryHeader, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(stream); @@ -145,4 +153,4 @@ namespace SharpCompress.Common.Zip return localEntryHeader; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs index ee0c6be9..4dabc14d 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs @@ -9,10 +9,7 @@ namespace SharpCompress.Common.Zip { private Stream? _decompressionStream; - internal StreamingZipFilePart(ZipFileEntry header, Stream stream) - : base(header, stream) - { - } + internal StreamingZipFilePart(ZipFileEntry header, Stream stream) : base(header, stream) { } protected override Stream CreateBaseStream() { @@ -25,7 +22,10 @@ namespace SharpCompress.Common.Zip { return Stream.Null; } - _decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod); + _decompressionStream = CreateDecompressionStream( + GetCryptoStream(CreateBaseStream()), + Header.CompressionMethod + ); if (LeaveStreamOpen) { return NonDisposingStream.Create(_decompressionStream); @@ -43,7 +43,7 @@ namespace SharpCompress.Common.Zip { _decompressionStream ??= GetCompressedStream(); - if( Header.CompressionMethod != ZipCompressionMethod.None ) + if (Header.CompressionMethod != ZipCompressionMethod.None) { _decompressionStream.Skip(); @@ -60,7 +60,7 @@ namespace SharpCompress.Common.Zip // We would need to search for the magic word rewindableStream.Position -= 4; var pos = rewindableStream.Position; - while( Utility.Find(rewindableStream, new byte[] { 0x50,0x4b,0x07,0x08 } ) ) + while (Utility.Find(rewindableStream, new byte[] { 0x50, 0x4b, 0x07, 0x08 })) { // We should probably check CRC32 for positive matching as well var size = rewindableStream.Position - pos; @@ -73,7 +73,7 @@ namespace SharpCompress.Common.Zip long test_64bit = (long)uncompressed_size << 32 | (long)compressed_size; - if( test_64bit == size && test_64bit == uncompressed_64bit ) + if (test_64bit == size && test_64bit == uncompressed_64bit) { Header.CompressedSize = test_64bit; Header.UncompressedSize = uncompressed_64bit; @@ -81,7 +81,7 @@ namespace SharpCompress.Common.Zip break; } - if (compressed_size == size && compressed_size == uncompressed_size ) + if (compressed_size == size && compressed_size == uncompressed_size) { Header.CompressedSize = compressed_size; Header.UncompressedSize = uncompressed_size; diff --git a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs index 836fb039..620e3885 100644 --- a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs @@ -8,9 +8,7 @@ namespace SharpCompress.Common.Zip internal class StreamingZipHeaderFactory : ZipHeaderFactory { internal StreamingZipHeaderFactory(string? password, ArchiveEncoding archiveEncoding) - : base(StreamingMode.Streaming, password, archiveEncoding) - { - } + : base(StreamingMode.Streaming, password, archiveEncoding) { } internal IEnumerable ReadStreamHeader(Stream stream) { @@ -29,10 +27,19 @@ namespace SharpCompress.Common.Zip ZipHeader? header; BinaryReader reader = new BinaryReader(rewindableStream); uint headerBytes = 0; - if (_lastEntryHeader != null && - (FlagUtility.HasFlag(_lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor) || _lastEntryHeader.IsZip64)) + if ( + _lastEntryHeader != null + && ( + FlagUtility.HasFlag( + _lastEntryHeader.Flags, + HeaderFlags.UsePostDataDescriptor + ) || _lastEntryHeader.IsZip64 + ) + ) { - reader = ((StreamingZipFilePart)_lastEntryHeader.Part).FixStreamedFileLocation(ref rewindableStream); + reader = ((StreamingZipFilePart)_lastEntryHeader.Part).FixStreamedFileLocation( + ref rewindableStream + ); long? pos = rewindableStream.CanSeek ? (long?)rewindableStream.Position : null; uint crc = reader.ReadUInt32(); if (crc == POST_DATA_DESCRIPTOR) @@ -50,9 +57,10 @@ namespace SharpCompress.Common.Zip bool test_header = !(headerBytes == 0x04034b50 || headerBytes == 0x02014b50); long test_64bit = (long)uncompressed_size << 32 | (long)compressed_size; - if ( test_64bit == _lastEntryHeader.CompressedSize && test_header ) + if (test_64bit == _lastEntryHeader.CompressedSize && test_header) { - _lastEntryHeader.UncompressedSize = (long)reader.ReadUInt32() << 32 | (long)headerBytes; + _lastEntryHeader.UncompressedSize = + (long)reader.ReadUInt32() << 32 | (long)headerBytes; headerBytes = reader.ReadUInt32(); } else diff --git a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs index ea8aea3f..00345a47 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs @@ -18,7 +18,11 @@ namespace SharpCompress.Common.Zip private long _totalBytesLeftToRead; private bool _isDisposed; - internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length) + internal WinzipAesCryptoStream( + Stream stream, + WinzipAesEncryptionData winzipAesEncryptionData, + long length + ) { this._stream = stream; _totalBytesLeftToRead = length; @@ -113,9 +117,8 @@ namespace SharpCompress.Common.Zip } int bytesRemaining = last - offset; - int bytesToRead = (bytesRemaining > BLOCK_SIZE_IN_BYTES) - ? BLOCK_SIZE_IN_BYTES - : bytesRemaining; + int bytesToRead = + (bytesRemaining > BLOCK_SIZE_IN_BYTES) ? BLOCK_SIZE_IN_BYTES : bytesRemaining; // update the counter BinaryPrimitives.WriteInt32LittleEndian(_counter, _nonce++); @@ -123,25 +126,24 @@ namespace SharpCompress.Common.Zip // Determine if this is the final block if ((bytesToRead == bytesRemaining) && (_totalBytesLeftToRead == 0)) { - _counterOut = _transform.TransformFinalBlock(_counter, - 0, - BLOCK_SIZE_IN_BYTES); + _counterOut = _transform.TransformFinalBlock(_counter, 0, BLOCK_SIZE_IN_BYTES); _isFinalBlock = true; } else { - _transform.TransformBlock(_counter, - 0, // offset - BLOCK_SIZE_IN_BYTES, - _counterOut, - 0); // offset + _transform.TransformBlock( + _counter, + 0, // offset + BLOCK_SIZE_IN_BYTES, + _counterOut, + 0 + ); // offset } XorInPlace(buffer, offset, bytesToRead); return bytesToRead; } - private void XorInPlace(byte[] buffer, int offset, int count) { for (int i = 0; i < count; i++) @@ -162,7 +164,6 @@ namespace SharpCompress.Common.Zip } } - public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); diff --git a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs index 81c78503..cd5314c4 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs @@ -17,8 +17,12 @@ namespace SharpCompress.Common.Zip private byte[] _generatedVerifyValue; - internal WinzipAesEncryptionData(WinzipAesKeySize keySize, byte[] salt, byte[] passwordVerifyValue, - string password) + internal WinzipAesEncryptionData( + WinzipAesKeySize keySize, + byte[] salt, + byte[] passwordVerifyValue, + string password + ) { this._keySize = keySize; this._salt = salt; @@ -33,10 +37,7 @@ namespace SharpCompress.Common.Zip private int KeySizeInBytes { - get - { - return KeyLengthInBytes(_keySize); - } + get { return KeyLengthInBytes(_keySize); } } internal static int KeyLengthInBytes(WinzipAesKeySize keySize) @@ -52,11 +53,16 @@ namespace SharpCompress.Common.Zip private void Initialize() { - #if NET7_0 - var rfc2898 = new Rfc2898DeriveBytes(_password, _salt, RFC2898_ITERATIONS, HashAlgorithmName.SHA1); - #else +#if NET7_0 + var rfc2898 = new Rfc2898DeriveBytes( + _password, + _salt, + RFC2898_ITERATIONS, + HashAlgorithmName.SHA1 + ); +#else var rfc2898 = new Rfc2898DeriveBytes(_password, _salt, RFC2898_ITERATIONS); - #endif +#endif KeyBytes = rfc2898.GetBytes(KeySizeInBytes); // 16 or 24 or 32 ??? IvBytes = rfc2898.GetBytes(KeySizeInBytes); diff --git a/src/SharpCompress/Common/Zip/WinzipAesKeySize.cs b/src/SharpCompress/Common/Zip/WinzipAesKeySize.cs index 4a39f46d..07602338 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesKeySize.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesKeySize.cs @@ -6,4 +6,4 @@ KeySize192 = 2, KeySize256 = 3 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs b/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs index bf7df040..87135269 100644 --- a/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs +++ b/src/SharpCompress/Common/Zip/ZipCompressionMethod.cs @@ -10,4 +10,4 @@ PPMd = 98, WinzipAes = 0x63 //http://www.winzip.com/aes_info.htm } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/ZipEntry.cs b/src/SharpCompress/Common/Zip/ZipEntry.cs index d82335b5..f77f397d 100644 --- a/src/SharpCompress/Common/Zip/ZipEntry.cs +++ b/src/SharpCompress/Common/Zip/ZipEntry.cs @@ -15,8 +15,10 @@ namespace SharpCompress.Common.Zip if (filePart != null) { this._filePart = filePart; - LastModifiedTime = Utility.DosDateToDateTime(filePart.Header.LastModifiedDate, - filePart.Header.LastModifiedTime); + LastModifiedTime = Utility.DosDateToDateTime( + filePart.Header.LastModifiedDate, + filePart.Header.LastModifiedTime + ); } } @@ -27,33 +29,33 @@ namespace SharpCompress.Common.Zip switch (_filePart.Header.CompressionMethod) { case ZipCompressionMethod.BZip2: - { - return CompressionType.BZip2; - } + { + return CompressionType.BZip2; + } case ZipCompressionMethod.Deflate: - { - return CompressionType.Deflate; - } + { + return CompressionType.Deflate; + } case ZipCompressionMethod.Deflate64: - { - return CompressionType.Deflate64; - } + { + return CompressionType.Deflate64; + } case ZipCompressionMethod.LZMA: - { - return CompressionType.LZMA; - } + { + return CompressionType.LZMA; + } case ZipCompressionMethod.PPMd: - { - return CompressionType.PPMd; - } + { + return CompressionType.PPMd; + } case ZipCompressionMethod.None: - { - return CompressionType.None; - } + { + return CompressionType.None; + } default: - { - return CompressionType.Unknown; - } + { + return CompressionType.Unknown; + } } } } @@ -76,7 +78,8 @@ 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; @@ -84,4 +87,4 @@ namespace SharpCompress.Common.Zip internal override IEnumerable Parts => _filePart.AsEnumerable(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index 5fd6c4ac..c87ac3f1 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -15,8 +15,7 @@ namespace SharpCompress.Common.Zip { internal abstract class ZipFilePart : FilePart { - internal ZipFilePart(ZipFileEntry header, Stream stream) - : base(header.ArchiveEncoding) + internal ZipFilePart(ZipFileEntry header, Stream stream) : base(header.ArchiveEncoding) { Header = header; header.Part = this; @@ -34,7 +33,10 @@ namespace SharpCompress.Common.Zip { return Stream.Null; } - Stream decompressionStream = CreateDecompressionStream(GetCryptoStream(CreateBaseStream()), Header.CompressionMethod); + Stream decompressionStream = CreateDecompressionStream( + GetCryptoStream(CreateBaseStream()), + Header.CompressionMethod + ); if (LeaveStreamOpen) { return NonDisposingStream.Create(decompressionStream); @@ -53,79 +55,99 @@ namespace SharpCompress.Common.Zip protected abstract Stream CreateBaseStream(); - protected bool LeaveStreamOpen => FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) || Header.IsZip64; + protected bool LeaveStreamOpen => + FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) || Header.IsZip64; protected Stream CreateDecompressionStream(Stream stream, ZipCompressionMethod method) { switch (method) { case ZipCompressionMethod.None: - { - return stream; - } + { + return stream; + } case ZipCompressionMethod.Deflate: - { - return new DeflateStream(stream, CompressionMode.Decompress); - } + { + return new DeflateStream(stream, CompressionMode.Decompress); + } case ZipCompressionMethod.Deflate64: - { - return new Deflate64Stream(stream, CompressionMode.Decompress); - } + { + return new Deflate64Stream(stream, CompressionMode.Decompress); + } case ZipCompressionMethod.BZip2: - { - return new BZip2Stream(stream, CompressionMode.Decompress, false); - } + { + return new BZip2Stream(stream, CompressionMode.Decompress, false); + } case ZipCompressionMethod.LZMA: + { + if (FlagUtility.HasFlag(Header.Flags, HeaderFlags.Encrypted)) { - if (FlagUtility.HasFlag(Header.Flags, HeaderFlags.Encrypted)) - { - throw new NotSupportedException("LZMA with pkware encryption."); - } - var reader = new BinaryReader(stream); - reader.ReadUInt16(); //LZMA version - var props = new byte[reader.ReadUInt16()]; - reader.Read(props, 0, props.Length); - return new LzmaStream(props, stream, - Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1, - FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1) - ? -1 - : (long)Header.UncompressedSize); + throw new NotSupportedException("LZMA with pkware encryption."); } + var reader = new BinaryReader(stream); + reader.ReadUInt16(); //LZMA version + var props = new byte[reader.ReadUInt16()]; + reader.Read(props, 0, props.Length); + return new LzmaStream( + props, + stream, + Header.CompressedSize > 0 ? Header.CompressedSize - 4 - props.Length : -1, + FlagUtility.HasFlag(Header.Flags, HeaderFlags.Bit1) + ? -1 + : (long)Header.UncompressedSize + ); + } case ZipCompressionMethod.PPMd: - { - Span props = stackalloc byte[2]; - stream.ReadFully(props); - return new PpmdStream(new PpmdProperties(props), stream, false); - } + { + Span props = stackalloc byte[2]; + stream.ReadFully(props); + return new PpmdStream(new PpmdProperties(props), stream, false); + } case ZipCompressionMethod.WinzipAes: + { + ExtraData? data = Header.Extra.SingleOrDefault( + x => x.Type == ExtraDataType.WinZipAes + ); + if (data is null) { - ExtraData? data = Header.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); - if (data is null) - { - throw new InvalidFormatException("No Winzip AES extra data found."); - } - if (data.Length != 7) - { - throw new InvalidFormatException("Winzip data length is not 7."); - } - ushort compressedMethod = BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes); - - if (compressedMethod != 0x01 && compressedMethod != 0x02) - { - throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata"); - } - - ushort vendorId = BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(2)); - if (vendorId != 0x4541) - { - throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata"); - } - return CreateDecompressionStream(stream, (ZipCompressionMethod)BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5))); + throw new InvalidFormatException("No Winzip AES extra data found."); } + if (data.Length != 7) + { + throw new InvalidFormatException("Winzip data length is not 7."); + } + ushort compressedMethod = BinaryPrimitives.ReadUInt16LittleEndian( + data.DataBytes + ); + + if (compressedMethod != 0x01 && compressedMethod != 0x02) + { + throw new InvalidFormatException( + "Unexpected vendor version number for WinZip AES metadata" + ); + } + + ushort vendorId = BinaryPrimitives.ReadUInt16LittleEndian( + data.DataBytes.AsSpan(2) + ); + if (vendorId != 0x4541) + { + throw new InvalidFormatException( + "Unexpected vendor ID for WinZip AES metadata" + ); + } + return CreateDecompressionStream( + stream, + (ZipCompressionMethod) + BinaryPrimitives.ReadUInt16LittleEndian(data.DataBytes.AsSpan(5)) + ); + } default: - { - throw new NotSupportedException("CompressionMethod: " + Header.CompressionMethod); - } + { + throw new NotSupportedException( + "CompressionMethod: " + Header.CompressionMethod + ); + } } } @@ -138,9 +160,12 @@ namespace SharpCompress.Common.Zip throw new NotSupportedException("Cannot encrypt file with unknown size at start."); } - if ((Header.CompressedSize == 0 - && FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor)) - || Header.IsZip64) + if ( + ( + Header.CompressedSize == 0 + && FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor) + ) || Header.IsZip64 + ) { plainStream = NonDisposingStream.Create(plainStream); //make sure AES doesn't close } @@ -159,24 +184,31 @@ namespace SharpCompress.Common.Zip case ZipCompressionMethod.BZip2: case ZipCompressionMethod.LZMA: case ZipCompressionMethod.PPMd: - { - return new PkwareTraditionalCryptoStream(plainStream, Header.ComposeEncryptionData(plainStream), CryptoMode.Decrypt); - } + { + return new PkwareTraditionalCryptoStream( + plainStream, + Header.ComposeEncryptionData(plainStream), + CryptoMode.Decrypt + ); + } case ZipCompressionMethod.WinzipAes: + { + if (Header.WinzipAesEncryptionData != null) { - if (Header.WinzipAesEncryptionData != null) - { - return new WinzipAesCryptoStream(plainStream, Header.WinzipAesEncryptionData, Header.CompressedSize - 10); - } - return plainStream; + return new WinzipAesCryptoStream( + plainStream, + Header.WinzipAesEncryptionData, + Header.CompressedSize - 10 + ); } + return plainStream; + } default: - { - throw new InvalidOperationException("Header.CompressionMethod is invalid"); - } - + { + throw new InvalidOperationException("Header.CompressionMethod is invalid"); + } } } return plainStream; diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs index fac558d2..bc490c7e 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -23,7 +23,11 @@ namespace SharpCompress.Common.Zip private readonly StreamingMode _mode; private readonly ArchiveEncoding _archiveEncoding; - protected ZipHeaderFactory(StreamingMode mode, string? password, ArchiveEncoding archiveEncoding) + protected ZipHeaderFactory( + StreamingMode mode, + string? password, + ArchiveEncoding archiveEncoding + ) { this._mode = mode; this._password = password; @@ -35,58 +39,67 @@ namespace SharpCompress.Common.Zip switch (headerBytes) { case ENTRY_HEADER_BYTES: - { - var entryHeader = new LocalEntryHeader(_archiveEncoding); - entryHeader.Read(reader); - LoadHeader(entryHeader, reader.BaseStream); + { + var entryHeader = new LocalEntryHeader(_archiveEncoding); + entryHeader.Read(reader); + LoadHeader(entryHeader, reader.BaseStream); - _lastEntryHeader = entryHeader; - return entryHeader; - } + _lastEntryHeader = entryHeader; + return entryHeader; + } case DIRECTORY_START_HEADER_BYTES: - { - var entry = new DirectoryEntryHeader(_archiveEncoding); - entry.Read(reader); - return entry; - } + { + 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(); - } - else - { - reader.ReadBytes(zip64 ? 20 : 12); - } - return null; + _lastEntryHeader.Crc = reader.ReadUInt32(); + _lastEntryHeader.CompressedSize = zip64 + ? (long)reader.ReadUInt64() + : reader.ReadUInt32(); + _lastEntryHeader.UncompressedSize = zip64 + ? (long)reader.ReadUInt64() + : reader.ReadUInt32(); } + else + { + reader.ReadBytes(zip64 ? 20 : 12); + } + return null; + } case DIGITAL_SIGNATURE: return null; case DIRECTORY_END_HEADER_BYTES: - { - var entry = new DirectoryEndHeader(); - entry.Read(reader); - return entry; - } + { + var entry = new DirectoryEndHeader(); + entry.Read(reader); + return entry; + } case SPLIT_ARCHIVE_HEADER_BYTES: - { - return new SplitHeader(); - } + { + return new SplitHeader(); + } case ZIP64_END_OF_CENTRAL_DIRECTORY: - { - var entry = new Zip64DirectoryEndHeader(); - entry.Read(reader); - return entry; - } + { + var entry = new Zip64DirectoryEndHeader(); + entry.Read(reader); + return entry; + } case ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR: - { - var entry = new Zip64DirectoryEndLocatorHeader(); - entry.Read(reader); - return entry; - } + { + var entry = new Zip64DirectoryEndLocatorHeader(); + entry.Read(reader); + return entry; + } default: return null; } @@ -114,10 +127,15 @@ namespace SharpCompress.Common.Zip { if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.Encrypted)) { - if (!entryHeader.IsDirectory && entryHeader.CompressedSize == 0 && - FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) + if ( + !entryHeader.IsDirectory + && entryHeader.CompressedSize == 0 + && FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor) + ) { - throw new NotSupportedException("SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner."); + 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 is null) @@ -129,7 +147,9 @@ namespace SharpCompress.Common.Zip if (entryHeader.CompressionMethod == ZipCompressionMethod.WinzipAes) { - ExtraData? data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); + ExtraData? data = entryHeader.Extra.SingleOrDefault( + x => x.Type == ExtraDataType.WinZipAes + ); if (data != null) { var keySize = (WinzipAesKeySize)data.DataBytes[4]; @@ -138,8 +158,12 @@ namespace SharpCompress.Common.Zip var passwordVerifyValue = new byte[2]; stream.Read(salt, 0, salt.Length); stream.Read(passwordVerifyValue, 0, 2); - entryHeader.WinzipAesEncryptionData = - new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue, _password); + entryHeader.WinzipAesEncryptionData = new WinzipAesEncryptionData( + keySize, + salt, + passwordVerifyValue, + _password + ); entryHeader.CompressedSize -= (uint)(salt.Length + 2); } @@ -160,25 +184,25 @@ namespace SharpCompress.Common.Zip switch (_mode) { case StreamingMode.Seekable: - { - entryHeader.DataStartPosition = stream.Position; - stream.Position += entryHeader.CompressedSize; - break; - } + { + entryHeader.DataStartPosition = stream.Position; + stream.Position += entryHeader.CompressedSize; + break; + } case StreamingMode.Streaming: - { - entryHeader.PackedStream = stream; - break; - } + { + entryHeader.PackedStream = stream; + break; + } default: - { - throw new InvalidFormatException("Invalid StreamingMode"); - } + { + throw new InvalidFormatException("Invalid StreamingMode"); + } } //} } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Common/Zip/ZipVolume.cs b/src/SharpCompress/Common/Zip/ZipVolume.cs index 856a5836..f8843305 100644 --- a/src/SharpCompress/Common/Zip/ZipVolume.cs +++ b/src/SharpCompress/Common/Zip/ZipVolume.cs @@ -6,9 +6,7 @@ namespace SharpCompress.Common.Zip public class ZipVolume : Volume { public ZipVolume(Stream stream, ReaderOptions readerOptions, int index = 0) - : base(stream, readerOptions, index) - { - } + : base(stream, readerOptions, index) { } public string? Comment { get; internal set; } } diff --git a/src/SharpCompress/Compressors/ADC/ADCStream.cs b/src/SharpCompress/Compressors/ADC/ADCStream.cs index 8d973a98..02337d8f 100644 --- a/src/SharpCompress/Compressors/ADC/ADCStream.cs +++ b/src/SharpCompress/Compressors/ADC/ADCStream.cs @@ -66,7 +66,10 @@ namespace SharpCompress.Compressors.ADC /// /// Stream that contains the compressed data /// Must be set to because compression is not implemented - public ADCStream(Stream stream, CompressionMode compressionMode = CompressionMode.Decompress) + public ADCStream( + Stream stream, + CompressionMode compressionMode = CompressionMode.Decompress + ) { if (compressionMode == CompressionMode.Compress) { @@ -84,12 +87,14 @@ namespace SharpCompress.Compressors.ADC public override long Length => throw new NotSupportedException(); - public override long Position { get => _position; set => throw new NotSupportedException(); } - - public override void Flush() + public override long Position { + get => _position; + set => throw new NotSupportedException(); } + public override void Flush() { } + protected override void Dispose(bool disposing) { if (_isDisposed) @@ -173,4 +178,4 @@ namespace SharpCompress.Compressors.ADC throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/BZip2/BZip2Constants.cs b/src/SharpCompress/Compressors/BZip2/BZip2Constants.cs index ed506844..6644c278 100644 --- a/src/SharpCompress/Compressors/BZip2/BZip2Constants.cs +++ b/src/SharpCompress/Compressors/BZip2/BZip2Constants.cs @@ -44,58 +44,518 @@ namespace SharpCompress.Compressors.BZip2 public static int[] rNums = { - 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, - 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, - 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, - 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, - 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, - 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, - 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, - 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, - 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, - 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, - 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, - 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, - 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, - 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, - 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, - 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, - 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, - 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, - 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, - 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, - 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, - 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, - 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, - 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, - 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, - 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, - 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, - 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, - 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, - 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, - 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, - 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, - 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, - 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, - 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, - 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, - 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, - 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, - 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, - 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, - 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, - 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, - 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, - 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, - 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, - 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, - 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, - 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, - 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, - 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, - 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, - 936, 638 + 619, + 720, + 127, + 481, + 931, + 816, + 813, + 233, + 566, + 247, + 985, + 724, + 205, + 454, + 863, + 491, + 741, + 242, + 949, + 214, + 733, + 859, + 335, + 708, + 621, + 574, + 73, + 654, + 730, + 472, + 419, + 436, + 278, + 496, + 867, + 210, + 399, + 680, + 480, + 51, + 878, + 465, + 811, + 169, + 869, + 675, + 611, + 697, + 867, + 561, + 862, + 687, + 507, + 283, + 482, + 129, + 807, + 591, + 733, + 623, + 150, + 238, + 59, + 379, + 684, + 877, + 625, + 169, + 643, + 105, + 170, + 607, + 520, + 932, + 727, + 476, + 693, + 425, + 174, + 647, + 73, + 122, + 335, + 530, + 442, + 853, + 695, + 249, + 445, + 515, + 909, + 545, + 703, + 919, + 874, + 474, + 882, + 500, + 594, + 612, + 641, + 801, + 220, + 162, + 819, + 984, + 589, + 513, + 495, + 799, + 161, + 604, + 958, + 533, + 221, + 400, + 386, + 867, + 600, + 782, + 382, + 596, + 414, + 171, + 516, + 375, + 682, + 485, + 911, + 276, + 98, + 553, + 163, + 354, + 666, + 933, + 424, + 341, + 533, + 870, + 227, + 730, + 475, + 186, + 263, + 647, + 537, + 686, + 600, + 224, + 469, + 68, + 770, + 919, + 190, + 373, + 294, + 822, + 808, + 206, + 184, + 943, + 795, + 384, + 383, + 461, + 404, + 758, + 839, + 887, + 715, + 67, + 618, + 276, + 204, + 918, + 873, + 777, + 604, + 560, + 951, + 160, + 578, + 722, + 79, + 804, + 96, + 409, + 713, + 940, + 652, + 934, + 970, + 447, + 318, + 353, + 859, + 672, + 112, + 785, + 645, + 863, + 803, + 350, + 139, + 93, + 354, + 99, + 820, + 908, + 609, + 772, + 154, + 274, + 580, + 184, + 79, + 626, + 630, + 742, + 653, + 282, + 762, + 623, + 680, + 81, + 927, + 626, + 789, + 125, + 411, + 521, + 938, + 300, + 821, + 78, + 343, + 175, + 128, + 250, + 170, + 774, + 972, + 275, + 999, + 639, + 495, + 78, + 352, + 126, + 857, + 956, + 358, + 619, + 580, + 124, + 737, + 594, + 701, + 612, + 669, + 112, + 134, + 694, + 363, + 992, + 809, + 743, + 168, + 974, + 944, + 375, + 748, + 52, + 600, + 747, + 642, + 182, + 862, + 81, + 344, + 805, + 988, + 739, + 511, + 655, + 814, + 334, + 249, + 515, + 897, + 955, + 664, + 981, + 649, + 113, + 974, + 459, + 893, + 228, + 433, + 837, + 553, + 268, + 926, + 240, + 102, + 654, + 459, + 51, + 686, + 754, + 806, + 760, + 493, + 403, + 415, + 394, + 687, + 700, + 946, + 670, + 656, + 610, + 738, + 392, + 760, + 799, + 887, + 653, + 978, + 321, + 576, + 617, + 626, + 502, + 894, + 679, + 243, + 440, + 680, + 879, + 194, + 572, + 640, + 724, + 926, + 56, + 204, + 700, + 707, + 151, + 457, + 449, + 797, + 195, + 791, + 558, + 945, + 679, + 297, + 59, + 87, + 824, + 713, + 663, + 412, + 693, + 342, + 606, + 134, + 108, + 571, + 364, + 631, + 212, + 174, + 643, + 304, + 329, + 343, + 97, + 430, + 751, + 497, + 314, + 983, + 374, + 822, + 928, + 140, + 206, + 73, + 263, + 980, + 736, + 876, + 478, + 430, + 305, + 170, + 514, + 364, + 692, + 829, + 82, + 855, + 953, + 676, + 246, + 369, + 970, + 294, + 750, + 807, + 827, + 150, + 790, + 288, + 923, + 804, + 378, + 215, + 828, + 592, + 281, + 565, + 555, + 710, + 82, + 896, + 831, + 547, + 261, + 524, + 462, + 293, + 465, + 502, + 56, + 661, + 821, + 976, + 991, + 658, + 869, + 905, + 758, + 745, + 193, + 768, + 550, + 608, + 933, + 378, + 286, + 215, + 979, + 792, + 961, + 61, + 688, + 793, + 644, + 986, + 403, + 106, + 366, + 905, + 644, + 372, + 567, + 466, + 434, + 645, + 210, + 389, + 550, + 919, + 135, + 780, + 773, + 635, + 389, + 707, + 100, + 626, + 958, + 165, + 504, + 920, + 176, + 193, + 713, + 857, + 265, + 203, + 50, + 668, + 108, + 645, + 990, + 626, + 197, + 510, + 357, + 358, + 850, + 858, + 364, + 936, + 638 }; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs index a65ca51f..ea54e7e9 100644 --- a/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs +++ b/src/SharpCompress/Compressors/BZip2/BZip2Stream.cs @@ -14,8 +14,11 @@ namespace SharpCompress.Compressors.BZip2 /// The stream to read from /// Compression Mode /// Decompress Concatenated - public BZip2Stream(Stream stream, CompressionMode compressionMode, - bool decompressConcatenated) + public BZip2Stream( + Stream stream, + CompressionMode compressionMode, + bool decompressConcatenated + ) { Mode = compressionMode; if (Mode == CompressionMode.Compress) @@ -61,7 +64,11 @@ namespace SharpCompress.Compressors.BZip2 public override long Length => stream.Length; - public override long Position { get => stream.Position; set => stream.Position = value; } + public override long Position + { + get => stream.Position; + set => stream.Position = value; + } public override int Read(byte[] buffer, int offset, int count) { @@ -94,7 +101,6 @@ namespace SharpCompress.Compressors.BZip2 { stream.Write(buffer); } - #endif public override void Write(byte[] buffer, int offset, int count) diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs index 62c928ab..1b77ed84 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs @@ -116,9 +116,18 @@ namespace SharpCompress.Compressors.BZip2 */ private readonly int[] unzftab = new int[256]; - private readonly int[][] limit = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); - private readonly int[][] basev = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); - private readonly int[][] perm = InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); + private readonly int[][] limit = InitIntArray( + BZip2Constants.N_GROUPS, + BZip2Constants.MAX_ALPHA_SIZE + ); + private readonly int[][] basev = InitIntArray( + BZip2Constants.N_GROUPS, + BZip2Constants.MAX_ALPHA_SIZE + ); + private readonly int[][] perm = InitIntArray( + BZip2Constants.N_GROUPS, + BZip2Constants.MAX_ALPHA_SIZE + ); private readonly int[] minLens = new int[BZip2Constants.N_GROUPS]; private Stream bsStream; @@ -137,12 +146,18 @@ namespace SharpCompress.Compressors.BZip2 private int currentState = START_BLOCK_STATE; - private int storedBlockCRC, storedCombinedCRC; - private int computedBlockCRC, computedCombinedCRC; + private int storedBlockCRC, + storedCombinedCRC; + private int computedBlockCRC, + computedCombinedCRC; private readonly bool decompressConcatenated; - private int i2, count, chPrev, ch2; - private int i, tPos; + private int i2, + count, + chPrev, + ch2; + private int i, + tPos; private int rNToGo; private int rTPos; private int j2; @@ -256,8 +271,12 @@ namespace SharpCompress.Compressors.BZip2 private void InitBlock() { - char magic1, magic2, magic3, magic4; - char magic5, magic6; + char magic1, + magic2, + magic3, + magic4; + char magic5, + magic6; while (true) { @@ -267,8 +286,14 @@ namespace SharpCompress.Compressors.BZip2 magic4 = BsGetUChar(); magic5 = BsGetUChar(); magic6 = BsGetUChar(); - if (magic1 != 0x17 || magic2 != 0x72 || magic3 != 0x45 - || magic4 != 0x38 || magic5 != 0x50 || magic6 != 0x90) + if ( + magic1 != 0x17 + || magic2 != 0x72 + || magic3 != 0x45 + || magic4 != 0x38 + || magic5 != 0x50 + || magic6 != 0x90 + ) { break; } @@ -279,8 +304,14 @@ namespace SharpCompress.Compressors.BZip2 } } - if (magic1 != 0x31 || magic2 != 0x41 || magic3 != 0x59 - || magic4 != 0x26 || magic5 != 0x53 || magic6 != 0x59) + if ( + magic1 != 0x31 + || magic2 != 0x41 + || magic3 != 0x59 + || magic4 != 0x26 + || magic5 != 0x53 + || magic6 != 0x59 + ) { BadBlockHeader(); streamEnd = true; @@ -314,8 +345,8 @@ namespace SharpCompress.Compressors.BZip2 CrcError(); } - computedCombinedCRC = (computedCombinedCRC << 1) - | (int)(((uint)computedCombinedCRC) >> 31); + computedCombinedCRC = + (computedCombinedCRC << 1) | (int)(((uint)computedCombinedCRC) >> 31); computedCombinedCRC ^= computedBlockCRC; } @@ -421,11 +452,20 @@ namespace SharpCompress.Compressors.BZip2 return BsGetint(); } - private void HbCreateDecodeTables(int[] limit, int[] basev, - int[] perm, char[] length, - int minLen, int maxLen, int alphaSize) + private void HbCreateDecodeTables( + int[] limit, + int[] basev, + int[] perm, + char[] length, + int minLen, + int maxLen, + int alphaSize + ) { - int pp, i, j, vec; + int pp, + i, + j, + vec; pp = 0; for (i = minLen; i <= maxLen; i++) @@ -475,8 +515,14 @@ namespace SharpCompress.Compressors.BZip2 private void RecvDecodingTables() { char[][] len = InitCharArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); - int i, j, t, nGroups, nSelectors, alphaSize; - int minLen, maxLen; + int i, + j, + t, + nGroups, + nSelectors, + alphaSize; + int minLen, + maxLen; bool[] inUse16 = new bool[16]; /* Receive the mapping table */ @@ -530,7 +576,8 @@ namespace SharpCompress.Compressors.BZip2 /* Undo the MTF values for the selectors. */ { char[] pos = new char[BZip2Constants.N_GROUPS]; - char tmp, v; + char tmp, + v; for (v = '\0'; v < nGroups; v++) { pos[v] = v; @@ -587,8 +634,15 @@ namespace SharpCompress.Compressors.BZip2 minLen = len[t][i]; } } - HbCreateDecodeTables(limit[t], basev[t], perm[t], len[t], minLen, - maxLen, alphaSize); + HbCreateDecodeTables( + limit[t], + basev[t], + perm[t], + len[t], + minLen, + maxLen, + alphaSize + ); minLens[t] = minLen; } } @@ -596,8 +650,13 @@ namespace SharpCompress.Compressors.BZip2 private void GetAndMoveToFrontDecode() { char[] yy = new char[256]; - int i, j, nextSym, limitLast; - int EOB, groupNo, groupPos; + int i, + j, + nextSym, + limitLast; + int EOB, + groupNo, + groupPos; limitLast = BZip2Constants.baseBlockSize * blockSize100k; origPtr = BsGetIntVS(24); @@ -626,7 +685,10 @@ namespace SharpCompress.Compressors.BZip2 last = -1; { - int zt, zn, zvec, zj; + int zt, + zn, + zvec, + zj; if (groupPos == 0) { groupNo++; @@ -694,7 +756,10 @@ namespace SharpCompress.Compressors.BZip2 } N = N * 2; { - int zt, zn, zvec, zj; + int zt, + zn, + zvec, + zj; if (groupPos == 0) { groupNo++; @@ -737,8 +802,7 @@ namespace SharpCompress.Compressors.BZip2 } nextSym = perm[zt][zvec - basev[zt][zn]]; } - } - while (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB); + } while (nextSym == BZip2Constants.RUNA || nextSym == BZip2Constants.RUNB); s++; ch = seqToUnseq[yy[0]]; @@ -791,7 +855,10 @@ namespace SharpCompress.Compressors.BZip2 yy[0] = tmp; { - int zt, zn, zvec, zj; + int zt, + zn, + zvec, + zj; if (groupPos == 0) { groupNo++; @@ -1028,8 +1095,7 @@ namespace SharpCompress.Compressors.BZip2 private void SetDecompressStructureSizes(int newSize100k) { - if (!(0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k - && blockSize100k <= 9)) + if (!(0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k && blockSize100k <= 9)) { // throw new IOException("Invalid block size"); } @@ -1046,9 +1112,7 @@ namespace SharpCompress.Compressors.BZip2 tt = new int[n]; } - public override void Flush() - { - } + public override void Flush() { } public override int Read(byte[] buffer, int offset, int count) { @@ -1071,17 +1135,11 @@ namespace SharpCompress.Compressors.BZip2 return 0; } - public override void SetLength(long value) - { - } + public override void SetLength(long value) { } - public override void Write(byte[] buffer, int offset, int count) - { - } + public override void Write(byte[] buffer, int offset, int count) { } - public override void WriteByte(byte value) - { - } + public override void WriteByte(byte value) { } public override bool CanRead => true; @@ -1091,6 +1149,10 @@ namespace SharpCompress.Compressors.BZip2 public override long Length => 0; - public override long Position { get { return 0; } set { } } + public override long Position + { + get { return 0; } + set { } + } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs index b86695bd..2e0f8005 100644 --- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs +++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs @@ -79,19 +79,24 @@ namespace SharpCompress.Compressors.BZip2 } } - private static void HbMakeCodeLengths(char[] len, int[] freq, - int alphaSize, int maxLen) + private static void HbMakeCodeLengths(char[] len, int[] freq, int alphaSize, int maxLen) { /* Nodes and heap entries run from 1. Entry 0 for both the heap and nodes is a sentinel. */ - int nNodes, nHeap, n1, n2, i, j, k; + int nNodes, + nHeap, + n1, + n2, + i, + j, + k; bool tooLong; Span heap = stackalloc int[BZip2Constants.MAX_ALPHA_SIZE + 2]; // 1040 bytes - Span weight = stackalloc int[BZip2Constants.MAX_ALPHA_SIZE * 2]; // 1040 bytes - Span parent = stackalloc int[BZip2Constants.MAX_ALPHA_SIZE * 2]; // 1040 bytes + Span weight = stackalloc int[BZip2Constants.MAX_ALPHA_SIZE * 2]; // 1040 bytes + Span parent = stackalloc int[BZip2Constants.MAX_ALPHA_SIZE * 2]; // 1040 bytes for (i = 0; i < alphaSize; i++) { @@ -113,7 +118,8 @@ namespace SharpCompress.Compressors.BZip2 nHeap++; heap[nHeap] = i; { - int zz, tmp; + int zz, + tmp; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) @@ -135,7 +141,9 @@ namespace SharpCompress.Compressors.BZip2 heap[1] = heap[nHeap]; nHeap--; { - int zz = 0, yy = 0, tmp = 0; + int zz = 0, + yy = 0, + tmp = 0; zz = 1; tmp = heap[zz]; while (true) @@ -145,8 +153,7 @@ namespace SharpCompress.Compressors.BZip2 { break; } - if (yy < nHeap - && weight[heap[yy + 1]] < weight[heap[yy]]) + if (yy < nHeap && weight[heap[yy + 1]] < weight[heap[yy]]) { yy++; } @@ -163,7 +170,9 @@ namespace SharpCompress.Compressors.BZip2 heap[1] = heap[nHeap]; nHeap--; { - int zz = 0, yy = 0, tmp = 0; + int zz = 0, + yy = 0, + tmp = 0; zz = 1; tmp = heap[zz]; while (true) @@ -173,8 +182,7 @@ namespace SharpCompress.Compressors.BZip2 { break; } - if (yy < nHeap - && weight[heap[yy + 1]] < weight[heap[yy]]) + if (yy < nHeap && weight[heap[yy + 1]] < weight[heap[yy]]) { yy++; } @@ -190,18 +198,24 @@ namespace SharpCompress.Compressors.BZip2 nNodes++; parent[n1] = parent[n2] = nNodes; - weight[nNodes] = (int)((uint)((weight[n1] & 0xffffff00) - + (weight[n2] & 0xffffff00)) - | (uint)(1 + (((weight[n1] & 0x000000ff) > - (weight[n2] & 0x000000ff)) - ? (weight[n1] & 0x000000ff) - : (weight[n2] & 0x000000ff)))); + weight[nNodes] = (int)( + (uint)((weight[n1] & 0xffffff00) + (weight[n2] & 0xffffff00)) + | (uint)( + 1 + + ( + ((weight[n1] & 0x000000ff) > (weight[n2] & 0x000000ff)) + ? (weight[n1] & 0x000000ff) + : (weight[n2] & 0x000000ff) + ) + ) + ); parent[nNodes] = -1; nHeap++; heap[nHeap] = nNodes; { - int zz = 0, tmp = 0; + int zz = 0, + tmp = 0; zz = nHeap; tmp = heap[zz]; while (weight[tmp] < weight[heap[zz >> 1]]) @@ -305,10 +319,7 @@ namespace SharpCompress.Compressors.BZip2 private int currentChar = -1; private int runLength; - public CBZip2OutputStream(Stream inStream) - : this(inStream, 9) - { - } + public CBZip2OutputStream(Stream inStream) : this(inStream, 9) { } public CBZip2OutputStream(Stream inStream, int inBlockSize) { @@ -467,7 +478,8 @@ namespace SharpCompress.Compressors.BZip2 bsStream.Flush(); } - private int blockCRC, combinedCRC; + private int blockCRC, + combinedCRC; private void Initialize() { @@ -570,10 +582,11 @@ namespace SharpCompress.Compressors.BZip2 BsFinishedWithStream(); } - private void HbAssignCodes(int[] code, char[] length, int minLen, - int maxLen, int alphaSize) + private void HbAssignCodes(int[] code, char[] length, int minLen, int maxLen, int alphaSize) { - int n, vec, i; + int n, + vec, + i; vec = 0; for (n = minLen; n <= maxLen; n++) @@ -645,10 +658,26 @@ namespace SharpCompress.Compressors.BZip2 private void SendMTFValues() { - char[][] len = CBZip2InputStream.InitCharArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); + char[][] len = CBZip2InputStream.InitCharArray( + BZip2Constants.N_GROUPS, + BZip2Constants.MAX_ALPHA_SIZE + ); - int v, t, i, j, gs, ge, totc, bt, bc, iter; - int nSelectors = 0, alphaSize, minLen, maxLen, selCtr; + int v, + t, + i, + j, + gs, + ge, + totc, + bt, + bc, + iter; + int nSelectors = 0, + alphaSize, + minLen, + maxLen, + selCtr; int nGroups; //, nBytes; alphaSize = nInUse + 2; @@ -689,7 +718,10 @@ namespace SharpCompress.Compressors.BZip2 /* Generate an initial set of coding tables */ { - int nPart, remF, tFreq, aFreq; + int nPart, + remF, + tFreq, + aFreq; nPart = nGroups; remF = nMTF; @@ -705,8 +737,7 @@ namespace SharpCompress.Compressors.BZip2 aFreq += mtfFreq[ge]; } - if (ge > gs && nPart != nGroups && nPart != 1 - && ((nGroups - nPart) % 2 == 1)) + if (ge > gs && nPart != nGroups && nPart != 1 && ((nGroups - nPart) % 2 == 1)) { aFreq -= mtfFreq[ge]; ge--; @@ -730,7 +761,10 @@ namespace SharpCompress.Compressors.BZip2 } } - int[][] rfreq = CBZip2InputStream.InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); + int[][] rfreq = CBZip2InputStream.InitIntArray( + BZip2Constants.N_GROUPS, + BZip2Constants.MAX_ALPHA_SIZE + ); int[] fave = new int[BZip2Constants.N_GROUPS]; short[] cost = new short[BZip2Constants.N_GROUPS]; /* @@ -778,7 +812,12 @@ namespace SharpCompress.Compressors.BZip2 if (nGroups == 6) { - short cost0, cost1, cost2, cost3, cost4, cost5; + short cost0, + cost1, + cost2, + cost3, + cost4, + cost5; cost0 = cost1 = cost2 = cost3 = cost4 = cost5 = 0; for (i = gs; i <= ge; i++) { @@ -865,7 +904,9 @@ namespace SharpCompress.Compressors.BZip2 /* Compute MTF values for the selectors. */ { char[] pos = new char[BZip2Constants.N_GROUPS]; - char ll_i, tmp2, tmp; + char ll_i, + tmp2, + tmp; for (i = 0; i < nGroups; i++) { pos[i] = (char)i; @@ -887,7 +928,10 @@ namespace SharpCompress.Compressors.BZip2 } } - int[][] code = CBZip2InputStream.InitIntArray(BZip2Constants.N_GROUPS, BZip2Constants.MAX_ALPHA_SIZE); + int[][] code = CBZip2InputStream.InitIntArray( + BZip2Constants.N_GROUPS, + BZip2Constants.MAX_ALPHA_SIZE + ); /* Assign actual codes for the tables. */ for (t = 0; t < nGroups; t++) @@ -1016,8 +1060,7 @@ namespace SharpCompress.Compressors.BZip2 } for (i = gs; i <= ge; i++) { - BsW(len[selector[selCtr]][szptr[i]], - code[selector[selCtr]][szptr[i]]); + BsW(len[selector[selCtr]][szptr[i]], code[selector[selCtr]][szptr[i]]); } gs = ge + 1; @@ -1040,7 +1083,11 @@ namespace SharpCompress.Compressors.BZip2 private void SimpleSort(int lo, int hi, int d) { - int i, j, h, bigN, hp; + int i, + j, + h, + bigN, + hp; int v; bigN = hi - lo + 1; @@ -1173,8 +1220,17 @@ namespace SharpCompress.Compressors.BZip2 private void QSort3(int loSt, int hiSt, int dSt) { - int unLo, unHi, ltLo, gtHi, med, n, m; - int sp, lo, hi, d; + int unLo, + unHi, + ltLo, + gtHi, + med, + n, + m; + int sp, + lo, + hi, + d; StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; for (int count = 0; count < QSORT_STACK_SIZE; count++) { @@ -1210,9 +1266,11 @@ namespace SharpCompress.Compressors.BZip2 continue; } - med = Med3(block[zptr[lo] + d + 1], - block[zptr[hi] + d + 1], - block[zptr[(lo + hi) >> 1] + d + 1]); + med = Med3( + block[zptr[lo] + d + 1], + block[zptr[hi] + d + 1], + block[zptr[(lo + hi) >> 1] + d + 1] + ); unLo = ltLo = lo; unHi = gtHi = hi; @@ -1314,11 +1372,15 @@ namespace SharpCompress.Compressors.BZip2 private void MainSort() { - int i, j, ss, sb; + int i, + j, + ss, + sb; Span runningOrder = stackalloc int[256]; Span copy = stackalloc int[256]; bool[] bigDone = new bool[256]; - int c1, c2; + int c1, + c2; int numQSorted; /* @@ -1410,8 +1472,7 @@ namespace SharpCompress.Compressors.BZip2 do { h = 3 * h + 1; - } - while (h <= 256); + } while (h <= 256); do { h = h / 3; @@ -1419,9 +1480,12 @@ namespace SharpCompress.Compressors.BZip2 { vv = runningOrder[i]; j = i; - while ((ftab[((runningOrder[j - h]) + 1) << 8] - - ftab[(runningOrder[j - h]) << 8]) > - (ftab[((vv) + 1) << 8] - ftab[(vv) << 8])) + while ( + ( + ftab[((runningOrder[j - h]) + 1) << 8] + - ftab[(runningOrder[j - h]) << 8] + ) > (ftab[((vv) + 1) << 8] - ftab[(vv) << 8]) + ) { runningOrder[j] = runningOrder[j - h]; j = j - h; @@ -1432,8 +1496,7 @@ namespace SharpCompress.Compressors.BZip2 } runningOrder[j] = vv; } - } - while (h != 1); + } while (h != 1); } /* @@ -1520,9 +1583,7 @@ namespace SharpCompress.Compressors.BZip2 copy[j] = ftab[(j << 8) + ss] & CLEARMASK; } - for (j = ftab[ss << 8] & CLEARMASK; - j < (ftab[(ss + 1) << 8] & CLEARMASK); - j++) + for (j = ftab[ss << 8] & CLEARMASK; j < (ftab[(ss + 1) << 8] & CLEARMASK); j++) { c1 = block[zptr[j]]; if (!bigDone[c1]) @@ -1611,8 +1672,10 @@ namespace SharpCompress.Compressors.BZip2 private bool FullGtU(int i1, int i2) { int k; - char c1, c2; - int s1, s2; + char c1, + c2; + int s1, + s2; c1 = block[i1 + 1]; c2 = block[i2 + 1]; @@ -1747,8 +1810,7 @@ namespace SharpCompress.Compressors.BZip2 k -= 4; workDone++; - } - while (k >= 0); + } while (k >= 0); return false; } @@ -1762,9 +1824,20 @@ namespace SharpCompress.Compressors.BZip2 private readonly int[] incs = { - 1, 4, 13, 40, 121, 364, 1093, 3280, - 9841, 29524, 88573, 265720, - 797161, 2391484 + 1, + 4, + 13, + 40, + 121, + 364, + 1093, + 3280, + 9841, + 29524, + 88573, + 265720, + 797161, + 2391484 }; private void AllocateCompressStructures() @@ -1799,7 +1872,8 @@ namespace SharpCompress.Compressors.BZip2 private void GenerateMTFValues() { char[] yy = new char[256]; - int i, j; + int i, + j; char tmp; char tmp2; int zPend; @@ -1927,9 +2001,7 @@ namespace SharpCompress.Compressors.BZip2 return 0; } - public override void SetLength(long value) - { - } + public override void SetLength(long value) { } public override void Write(byte[] buffer, int offset, int count) { @@ -1947,6 +2019,10 @@ namespace SharpCompress.Compressors.BZip2 public override long Length => 0; - public override long Position { get { return 0; } set { } } + public override long Position + { + get { return 0; } + set { } + } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/BZip2/CRC.cs b/src/SharpCompress/Compressors/BZip2/CRC.cs index 7ac42130..d9b268cb 100644 --- a/src/SharpCompress/Compressors/BZip2/CRC.cs +++ b/src/SharpCompress/Compressors/BZip2/CRC.cs @@ -33,133 +33,261 @@ namespace SharpCompress.Compressors.BZip2 { public static int[] crc32Table = { - 0x00000000, 0x04c11db7, 0x09823b6e, + 0x00000000, + 0x04c11db7, + 0x09823b6e, 0x0d4326d9, - 0x130476dc, 0x17c56b6b, 0x1a864db2, + 0x130476dc, + 0x17c56b6b, + 0x1a864db2, 0x1e475005, - 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, + 0x2608edb8, + 0x22c9f00f, + 0x2f8ad6d6, 0x2b4bcb61, - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, + 0x350c9b64, + 0x31cd86d3, + 0x3c8ea00a, 0x384fbdbd, - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, + 0x4c11db70, + 0x48d0c6c7, + 0x4593e01e, 0x4152fda9, - 0x5f15adac, 0x5bd4b01b, 0x569796c2, + 0x5f15adac, + 0x5bd4b01b, + 0x569796c2, 0x52568b75, - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, + 0x6a1936c8, + 0x6ed82b7f, + 0x639b0da6, 0x675a1011, - 0x791d4014, 0x7ddc5da3, 0x709f7b7a, + 0x791d4014, + 0x7ddc5da3, + 0x709f7b7a, 0x745e66cd, - unchecked((int)0x9823b6e0), unchecked((int)0x9ce2ab57), unchecked((int)0x91a18d8e), + unchecked((int)0x9823b6e0), + unchecked((int)0x9ce2ab57), + unchecked((int)0x91a18d8e), unchecked((int)0x95609039), - unchecked((int)0x8b27c03c), unchecked((int)0x8fe6dd8b), unchecked((int)0x82a5fb52), + unchecked((int)0x8b27c03c), + unchecked((int)0x8fe6dd8b), + unchecked((int)0x82a5fb52), unchecked((int)0x8664e6e5), - unchecked((int)0xbe2b5b58), unchecked((int)0xbaea46ef), unchecked((int)0xb7a96036), + unchecked((int)0xbe2b5b58), + unchecked((int)0xbaea46ef), + unchecked((int)0xb7a96036), unchecked((int)0xb3687d81), - unchecked((int)0xad2f2d84), unchecked((int)0xa9ee3033), unchecked((int)0xa4ad16ea), + unchecked((int)0xad2f2d84), + unchecked((int)0xa9ee3033), + unchecked((int)0xa4ad16ea), unchecked((int)0xa06c0b5d), - unchecked((int)0xd4326d90), unchecked((int)0xd0f37027), unchecked((int)0xddb056fe), + unchecked((int)0xd4326d90), + unchecked((int)0xd0f37027), + unchecked((int)0xddb056fe), unchecked((int)0xd9714b49), - unchecked((int)0xc7361b4c), unchecked((int)0xc3f706fb), unchecked((int)0xceb42022), + unchecked((int)0xc7361b4c), + unchecked((int)0xc3f706fb), + unchecked((int)0xceb42022), unchecked((int)0xca753d95), - unchecked((int)0xf23a8028), unchecked((int)0xf6fb9d9f), unchecked((int)0xfbb8bb46), + unchecked((int)0xf23a8028), + unchecked((int)0xf6fb9d9f), + unchecked((int)0xfbb8bb46), unchecked((int)0xff79a6f1), - unchecked((int)0xe13ef6f4), unchecked((int)0xe5ffeb43), unchecked((int)0xe8bccd9a), + unchecked((int)0xe13ef6f4), + unchecked((int)0xe5ffeb43), + unchecked((int)0xe8bccd9a), unchecked((int)0xec7dd02d), - 0x34867077, 0x30476dc0, 0x3d044b19, + 0x34867077, + 0x30476dc0, + 0x3d044b19, 0x39c556ae, - 0x278206ab, 0x23431b1c, 0x2e003dc5, + 0x278206ab, + 0x23431b1c, + 0x2e003dc5, 0x2ac12072, - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, + 0x128e9dcf, + 0x164f8078, + 0x1b0ca6a1, 0x1fcdbb16, - 0x018aeb13, 0x054bf6a4, 0x0808d07d, + 0x018aeb13, + 0x054bf6a4, + 0x0808d07d, 0x0cc9cdca, - 0x7897ab07, 0x7c56b6b0, 0x71159069, + 0x7897ab07, + 0x7c56b6b0, + 0x71159069, 0x75d48dde, - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, + 0x6b93dddb, + 0x6f52c06c, + 0x6211e6b5, 0x66d0fb02, - 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, + 0x5e9f46bf, + 0x5a5e5b08, + 0x571d7dd1, 0x53dc6066, - 0x4d9b3063, 0x495a2dd4, 0x44190b0d, + 0x4d9b3063, + 0x495a2dd4, + 0x44190b0d, 0x40d816ba, - unchecked((int)0xaca5c697), unchecked((int)0xa864db20), unchecked((int)0xa527fdf9), + unchecked((int)0xaca5c697), + unchecked((int)0xa864db20), + unchecked((int)0xa527fdf9), unchecked((int)0xa1e6e04e), - unchecked((int)0xbfa1b04b), unchecked((int)0xbb60adfc), unchecked((int)0xb6238b25), + unchecked((int)0xbfa1b04b), + unchecked((int)0xbb60adfc), + unchecked((int)0xb6238b25), unchecked((int)0xb2e29692), - unchecked((int)0x8aad2b2f), unchecked((int)0x8e6c3698), unchecked((int)0x832f1041), + unchecked((int)0x8aad2b2f), + unchecked((int)0x8e6c3698), + unchecked((int)0x832f1041), unchecked((int)0x87ee0df6), - unchecked((int)0x99a95df3), unchecked((int)0x9d684044), unchecked((int)0x902b669d), + unchecked((int)0x99a95df3), + unchecked((int)0x9d684044), + unchecked((int)0x902b669d), unchecked((int)0x94ea7b2a), - unchecked((int)0xe0b41de7), unchecked((int)0xe4750050), unchecked((int)0xe9362689), + unchecked((int)0xe0b41de7), + unchecked((int)0xe4750050), + unchecked((int)0xe9362689), unchecked((int)0xedf73b3e), - unchecked((int)0xf3b06b3b), unchecked((int)0xf771768c), unchecked((int)0xfa325055), + unchecked((int)0xf3b06b3b), + unchecked((int)0xf771768c), + unchecked((int)0xfa325055), unchecked((int)0xfef34de2), - unchecked((int)0xc6bcf05f), unchecked((int)0xc27dede8), unchecked((int)0xcf3ecb31), + unchecked((int)0xc6bcf05f), + unchecked((int)0xc27dede8), + unchecked((int)0xcf3ecb31), unchecked((int)0xcbffd686), - unchecked((int)0xd5b88683), unchecked((int)0xd1799b34), unchecked((int)0xdc3abded), + unchecked((int)0xd5b88683), + unchecked((int)0xd1799b34), + unchecked((int)0xdc3abded), unchecked((int)0xd8fba05a), - 0x690ce0ee, 0x6dcdfd59, 0x608edb80, + 0x690ce0ee, + 0x6dcdfd59, + 0x608edb80, 0x644fc637, - 0x7a089632, 0x7ec98b85, 0x738aad5c, + 0x7a089632, + 0x7ec98b85, + 0x738aad5c, 0x774bb0eb, - 0x4f040d56, 0x4bc510e1, 0x46863638, + 0x4f040d56, + 0x4bc510e1, + 0x46863638, 0x42472b8f, - 0x5c007b8a, 0x58c1663d, 0x558240e4, + 0x5c007b8a, + 0x58c1663d, + 0x558240e4, 0x51435d53, - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, + 0x251d3b9e, + 0x21dc2629, + 0x2c9f00f0, 0x285e1d47, - 0x36194d42, 0x32d850f5, 0x3f9b762c, + 0x36194d42, + 0x32d850f5, + 0x3f9b762c, 0x3b5a6b9b, - 0x0315d626, 0x07d4cb91, 0x0a97ed48, + 0x0315d626, + 0x07d4cb91, + 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, + 0x1011a0fa, + 0x14d0bd4d, + 0x19939b94, 0x1d528623, - unchecked((int)0xf12f560e), unchecked((int)0xf5ee4bb9), unchecked((int)0xf8ad6d60), + unchecked((int)0xf12f560e), + unchecked((int)0xf5ee4bb9), + unchecked((int)0xf8ad6d60), unchecked((int)0xfc6c70d7), - unchecked((int)0xe22b20d2), unchecked((int)0xe6ea3d65), unchecked((int)0xeba91bbc), + unchecked((int)0xe22b20d2), + unchecked((int)0xe6ea3d65), + unchecked((int)0xeba91bbc), unchecked((int)0xef68060b), - unchecked((int)0xd727bbb6), unchecked((int)0xd3e6a601), unchecked((int)0xdea580d8), + unchecked((int)0xd727bbb6), + unchecked((int)0xd3e6a601), + unchecked((int)0xdea580d8), unchecked((int)0xda649d6f), - unchecked((int)0xc423cd6a), unchecked((int)0xc0e2d0dd), unchecked((int)0xcda1f604), + unchecked((int)0xc423cd6a), + unchecked((int)0xc0e2d0dd), + unchecked((int)0xcda1f604), unchecked((int)0xc960ebb3), - unchecked((int)0xbd3e8d7e), unchecked((int)0xb9ff90c9), unchecked((int)0xb4bcb610), + unchecked((int)0xbd3e8d7e), + unchecked((int)0xb9ff90c9), + unchecked((int)0xb4bcb610), unchecked((int)0xb07daba7), - unchecked((int)0xae3afba2), unchecked((int)0xaafbe615), unchecked((int)0xa7b8c0cc), + unchecked((int)0xae3afba2), + unchecked((int)0xaafbe615), + unchecked((int)0xa7b8c0cc), unchecked((int)0xa379dd7b), - unchecked((int)0x9b3660c6), unchecked((int)0x9ff77d71), unchecked((int)0x92b45ba8), + unchecked((int)0x9b3660c6), + unchecked((int)0x9ff77d71), + unchecked((int)0x92b45ba8), unchecked((int)0x9675461f), - unchecked((int)0x8832161a), unchecked((int)0x8cf30bad), unchecked((int)0x81b02d74), + unchecked((int)0x8832161a), + unchecked((int)0x8cf30bad), + unchecked((int)0x81b02d74), unchecked((int)0x857130c3), - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, + 0x5d8a9099, + 0x594b8d2e, + 0x5408abf7, 0x50c9b640, - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, + 0x4e8ee645, + 0x4a4ffbf2, + 0x470cdd2b, 0x43cdc09c, - 0x7b827d21, 0x7f436096, 0x7200464f, + 0x7b827d21, + 0x7f436096, + 0x7200464f, 0x76c15bf8, - 0x68860bfd, 0x6c47164a, 0x61043093, + 0x68860bfd, + 0x6c47164a, + 0x61043093, 0x65c52d24, - 0x119b4be9, 0x155a565e, 0x18197087, + 0x119b4be9, + 0x155a565e, + 0x18197087, 0x1cd86d30, - 0x029f3d35, 0x065e2082, 0x0b1d065b, + 0x029f3d35, + 0x065e2082, + 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, + 0x3793a651, + 0x3352bbe6, + 0x3e119d3f, 0x3ad08088, - 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, + 0x2497d08d, + 0x2056cd3a, + 0x2d15ebe3, 0x29d4f654, - unchecked((int)0xc5a92679), unchecked((int)0xc1683bce), unchecked((int)0xcc2b1d17), + unchecked((int)0xc5a92679), + unchecked((int)0xc1683bce), + unchecked((int)0xcc2b1d17), unchecked((int)0xc8ea00a0), - unchecked((int)0xd6ad50a5), unchecked((int)0xd26c4d12), unchecked((int)0xdf2f6bcb), + unchecked((int)0xd6ad50a5), + unchecked((int)0xd26c4d12), + unchecked((int)0xdf2f6bcb), unchecked((int)0xdbee767c), - unchecked((int)0xe3a1cbc1), unchecked((int)0xe760d676), unchecked((int)0xea23f0af), + unchecked((int)0xe3a1cbc1), + unchecked((int)0xe760d676), + unchecked((int)0xea23f0af), unchecked((int)0xeee2ed18), - unchecked((int)0xf0a5bd1d), unchecked((int)0xf464a0aa), unchecked((int)0xf9278673), + unchecked((int)0xf0a5bd1d), + unchecked((int)0xf464a0aa), + unchecked((int)0xf9278673), unchecked((int)0xfde69bc4), - unchecked((int)0x89b8fd09), unchecked((int)0x8d79e0be), unchecked((int)0x803ac667), + unchecked((int)0x89b8fd09), + unchecked((int)0x8d79e0be), + unchecked((int)0x803ac667), unchecked((int)0x84fbdbd0), - unchecked((int)0x9abc8bd5), unchecked((int)0x9e7d9662), unchecked((int)0x933eb0bb), + unchecked((int)0x9abc8bd5), + unchecked((int)0x9e7d9662), + unchecked((int)0x933eb0bb), unchecked((int)0x97ffad0c), - unchecked((int)0xafb010b1), unchecked((int)0xab710d06), unchecked((int)0xa6322bdf), + unchecked((int)0xafb010b1), + unchecked((int)0xab710d06), + unchecked((int)0xa6322bdf), unchecked((int)0xa2f33668), - unchecked((int)0xbcb4666d), unchecked((int)0xb8757bda), unchecked((int)0xb5365d03), + unchecked((int)0xbcb4666d), + unchecked((int)0xb8757bda), + unchecked((int)0xb5365d03), unchecked((int)0xb1f740b4) }; @@ -200,4 +328,4 @@ namespace SharpCompress.Compressors.BZip2 internal int globalCrc; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/CompressionMode.cs b/src/SharpCompress/Compressors/CompressionMode.cs index 0d288bc5..a886c441 100644 --- a/src/SharpCompress/Compressors/CompressionMode.cs +++ b/src/SharpCompress/Compressors/CompressionMode.cs @@ -5,4 +5,4 @@ Compress = 0, Decompress = 1 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/CRC32.cs b/src/SharpCompress/Compressors/Deflate/CRC32.cs index ac73e843..c1f3a0e2 100644 --- a/src/SharpCompress/Compressors/Deflate/CRC32.cs +++ b/src/SharpCompress/Compressors/Deflate/CRC32.cs @@ -60,7 +60,8 @@ namespace SharpCompress.Compressors.Deflate // Often the polynomial is shown reversed as 0x04C11DB7. // For more details, see http://en.wikipedia.org/wiki/Cyclic_redundancy_check UInt32 dwPolynomial = 0xEDB88320; - UInt32 i, j; + UInt32 i, + j; crc32Table = new UInt32[256]; @@ -118,7 +119,6 @@ namespace SharpCompress.Compressors.Deflate { throw new ZlibException("The input stream must not be null."); } - unchecked { //UInt32 crc32Result; @@ -182,8 +182,9 @@ namespace SharpCompress.Compressors.Deflate for (int i = 0; i < count; i++) { int x = offset + i; - runningCrc32Result = ((runningCrc32Result) >> 8) ^ - crc32Table[(block[x]) ^ ((runningCrc32Result) & 0x000000FF)]; + runningCrc32Result = + ((runningCrc32Result) >> 8) + ^ crc32Table[(block[x]) ^ ((runningCrc32Result) & 0x000000FF)]; } TotalBytesRead += count; } @@ -279,8 +280,7 @@ namespace SharpCompress.Compressors.Deflate crc1 = gf2_matrix_times(odd, crc1); } len2 >>= 1; - } - while (len2 != 0); + } while (len2 != 0); crc1 ^= crc2; diff --git a/src/SharpCompress/Compressors/Deflate/DeflateManager.cs b/src/SharpCompress/Compressors/Deflate/DeflateManager.cs index 0abc4564..e6dd441d 100644 --- a/src/SharpCompress/Compressors/Deflate/DeflateManager.cs +++ b/src/SharpCompress/Compressors/Deflate/DeflateManager.cs @@ -3,52 +3,52 @@ // Deflate.cs // ------------------------------------------------------------------ // -// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. +// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. // All rights reserved. // // This code module is part of DotNetZip, a zipfile class library. // // ------------------------------------------------------------------ // -// This code is licensed under the Microsoft Public License. +// This code is licensed under the Microsoft Public License. // See the file License.txt for the license details. // More info on: http://dotnetzip.codeplex.com // // ------------------------------------------------------------------ // -// last saved (in emacs): +// last saved (in emacs): // Time-stamp: <2009-October-28 13:44:59> // // ------------------------------------------------------------------ // // This module defines logic for handling the Deflate or compression. // -// This code is based on multiple sources: +// This code is based on multiple sources: // - the original zlib v1.2.3 source, which is Copyright (C) 1995-2005 Jean-loup Gailly. -// - the original jzlib, which is Copyright (c) 2000-2003 ymnk, JCraft,Inc. +// - the original jzlib, which is Copyright (c) 2000-2003 ymnk, JCraft,Inc. // -// However, this code is significantly different from both. +// However, this code is significantly different from both. // The object model is not the same, and many of the behaviors are different. // -// In keeping with the license for these other works, the copyrights for +// In keeping with the license for these other works, the copyrights for // jzlib and zlib are here. // // ----------------------------------------------------------------------- // Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the distribution. -// +// // 3. The names of the authors may not be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, @@ -59,7 +59,7 @@ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // ----------------------------------------------------------------------- // // This program is based on zlib-1.1.3; credit to authors @@ -79,15 +79,70 @@ namespace SharpCompress.Compressors.Deflate // extra bits for each length code internal static readonly int[] 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 + 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 }; // extra bits for each distance code internal static readonly int[] 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, + 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 }; internal enum BlockState @@ -131,7 +186,13 @@ namespace SharpCompress.Compressors.Deflate internal DeflateFlavor Flavor; - private Config(int goodLength, int maxLazy, int niceLength, int maxChainLength, DeflateFlavor flavor) + private Config( + int goodLength, + int maxLazy, + int niceLength, + int maxChainLength, + DeflateFlavor flavor + ) { GoodLength = goodLength; MaxLazy = maxLazy; @@ -148,18 +209,18 @@ namespace SharpCompress.Compressors.Deflate static Config() { Table = new[] - { - new Config(0, 0, 0, 0, DeflateFlavor.Store), - new Config(4, 4, 8, 4, DeflateFlavor.Fast), - new Config(4, 5, 16, 8, DeflateFlavor.Fast), - new Config(4, 6, 32, 32, DeflateFlavor.Fast), - new Config(4, 4, 16, 16, DeflateFlavor.Slow), - new Config(8, 16, 32, 32, DeflateFlavor.Slow), - new Config(8, 16, 128, 128, DeflateFlavor.Slow), - new Config(8, 32, 128, 256, DeflateFlavor.Slow), - new Config(32, 128, 258, 1024, DeflateFlavor.Slow), - new Config(32, 258, 258, 4096, DeflateFlavor.Slow) - }; + { + new Config(0, 0, 0, 0, DeflateFlavor.Store), + new Config(4, 4, 8, 4, DeflateFlavor.Fast), + new Config(4, 5, 16, 8, DeflateFlavor.Fast), + new Config(4, 6, 32, 32, DeflateFlavor.Fast), + new Config(4, 4, 16, 16, DeflateFlavor.Slow), + new Config(8, 16, 32, 32, DeflateFlavor.Slow), + new Config(8, 16, 128, 128, DeflateFlavor.Slow), + new Config(8, 32, 128, 256, DeflateFlavor.Slow), + new Config(32, 128, 258, 1024, DeflateFlavor.Slow), + new Config(32, 258, 258, 4096, DeflateFlavor.Slow) + }; } private static readonly Config[] Table; @@ -231,7 +292,7 @@ namespace SharpCompress.Compressors.Deflate // and move to the first half later to keep a dictionary of at least wSize // bytes. With this organization, matches are limited to a distance of // wSize-MAX_MATCH bytes, but this ensures that IO is always - // performed with a length multiple of the block size. + // performed with a length multiple of the block size. // // To do: use the user input buffer as sliding window. @@ -306,7 +367,7 @@ namespace SharpCompress.Compressors.Deflate // Depth of each subtree used as tie breaker for trees of equal frequency private readonly sbyte[] depth = new sbyte[2 * InternalConstants.L_CODES + 1]; - private int _lengthOffset; // index for literals or lengths + private int _lengthOffset; // index for literals or lengths // Size of match buffer for literals/lengths. There are 4 reasons for // limiting lit_bufsize to 64K: @@ -605,8 +666,7 @@ namespace SharpCompress.Compressors.Deflate do { send_code(curlen, bl_tree); - } - while (--count != 0); + } while (--count != 0); } else if (curlen != 0) { @@ -656,11 +716,12 @@ namespace SharpCompress.Compressors.Deflate pendingCount += len; } -#if NOTNEEDED +#if NOTNEEDED private void put_byte(byte c) { pending[pendingCount++] = c; } + internal void put_short(int b) { unchecked @@ -669,6 +730,7 @@ namespace SharpCompress.Compressors.Deflate pending[pendingCount++] = (byte)(b >> 8); } } + internal void putShortMSB(int b) { unchecked @@ -776,8 +838,9 @@ namespace SharpCompress.Compressors.Deflate int dcode; for (dcode = 0; dcode < InternalConstants.D_CODES; dcode++) { - out_length = - (int)(out_length + dyn_dtree[dcode * 2] * (5L + ExtraDistanceBits[dcode])); + out_length = (int)( + out_length + dyn_dtree[dcode * 2] * (5L + ExtraDistanceBits[dcode]) + ); } out_length >>= 3; if ((matches < (last_lit / 2)) && out_length < in_length / 2) @@ -808,8 +871,7 @@ namespace SharpCompress.Compressors.Deflate do { int ix = _distanceOffset + lx * 2; - distance = ((pending[ix] << 8) & 0xff00) | - (pending[ix + 1] & 0xff); + distance = ((pending[ix] << 8) & 0xff00) | (pending[ix + 1] & 0xff); lc = (pending[_lengthOffset + lx]) & 0xff; lx++; @@ -819,7 +881,7 @@ namespace SharpCompress.Compressors.Deflate } else { - // literal or match pair + // literal or match pair // Here, lc is the match length - MIN_MATCH code = Tree.LengthCode[lc]; @@ -848,8 +910,7 @@ namespace SharpCompress.Compressors.Deflate } // Check that the overlay between pending and d_buf+l_buf is ok: - } - while (lx < last_lit); + } while (lx < last_lit); } send_code(END_BLOCK, ltree); @@ -1037,7 +1098,8 @@ namespace SharpCompress.Compressors.Deflate // trees or store, and output the encoded block to the zip file. internal void _tr_flush_block(int buf, int stored_len, bool eof) { - int opt_lenb, static_lenb; // opt_len and static_len in bytes + int opt_lenb, + static_lenb; // opt_len and static_len in bytes int max_blindex = 0; // index of last bit length code of non zero freq // Build the Huffman trees unless a stored block is forced @@ -1088,12 +1150,19 @@ namespace SharpCompress.Compressors.Deflate else if (static_lenb == opt_lenb) { send_bits((STATIC_TREES << 1) + (eof ? 1 : 0), 3); - send_compressed_block(StaticTree.lengthAndLiteralsTreeCodes, StaticTree.distTreeCodes); + send_compressed_block( + StaticTree.lengthAndLiteralsTreeCodes, + StaticTree.distTreeCodes + ); } else { send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3); - send_all_trees(treeLiterals.max_code + 1, treeDistances.max_code + 1, max_blindex + 1); + send_all_trees( + treeLiterals.max_code + 1, + treeDistances.max_code + 1, + max_blindex + 1 + ); send_compressed_block(dyn_ltree, dyn_dtree); } @@ -1118,7 +1187,8 @@ namespace SharpCompress.Compressors.Deflate // option -- not supported here). private void _fillWindow() { - int n, m; + int n, + m; int p; int more; // Amount of free space at the end of the window. @@ -1159,8 +1229,7 @@ namespace SharpCompress.Compressors.Deflate { m = (head[--p] & 0xffff); head[p] = (short)((m >= w_size) ? (m - w_size) : 0); - } - while (--n != 0); + } while (--n != 0); n = w_size; p = n; @@ -1171,8 +1240,7 @@ namespace SharpCompress.Compressors.Deflate // If n is not on any hash chain, prev[n] is garbage but // its value will never be used. - } - while (--n != 0); + } while (--n != 0); more += w_size; } @@ -1204,8 +1272,7 @@ namespace SharpCompress.Compressors.Deflate // If the whole input has less than MIN_MATCH bytes, ins_h is garbage, // but this is not important since only literal bytes will be emitted. - } - while (lookahead < MIN_LOOKAHEAD && _codec.AvailableBytesIn != 0); + } while (lookahead < MIN_LOOKAHEAD && _codec.AvailableBytesIn != 0); } // Compress as much as possible from the input stream, return the current @@ -1242,7 +1309,9 @@ namespace SharpCompress.Compressors.Deflate // dictionary, and set hash_head to the head of the hash chain: if (lookahead >= MIN_MATCH) { - ins_h = (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; + ins_h = + (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) + & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; hash_head = (head[ins_h] & 0xffff); @@ -1282,7 +1351,11 @@ namespace SharpCompress.Compressors.Deflate { strstart++; - ins_h = ((ins_h << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; + ins_h = + ( + (ins_h << hash_shift) + ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff) + ) & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; hash_head = (head[ins_h] & 0xffff); @@ -1291,8 +1364,7 @@ namespace SharpCompress.Compressors.Deflate // strstart never exceeds WSIZE-MAX_MATCH, so there are // always MIN_MATCH bytes ahead. - } - while (--match_length != 0); + } while (--match_length != 0); strstart++; } else @@ -1301,7 +1373,8 @@ namespace SharpCompress.Compressors.Deflate match_length = 0; ins_h = window[strstart] & 0xff; - ins_h = (((ins_h) << hash_shift) ^ (window[strstart + 1] & 0xff)) & hash_mask; + ins_h = + (((ins_h) << hash_shift) ^ (window[strstart + 1] & 0xff)) & hash_mask; // If lookahead < MIN_MATCH, ins_h is garbage, but it does not // matter since it will be recomputed at next deflate call. @@ -1373,7 +1446,9 @@ namespace SharpCompress.Compressors.Deflate if (lookahead >= MIN_MATCH) { - ins_h = (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; + ins_h = + (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) + & hash_mask; // prev[strstart&w_mask]=hash_head=head[ins_h]; hash_head = (head[ins_h] & 0xffff); @@ -1386,8 +1461,11 @@ namespace SharpCompress.Compressors.Deflate prev_match = match_start; match_length = MIN_MATCH - 1; - if (hash_head != 0 && prev_length < config.MaxLazy && - ((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD) + if ( + hash_head != 0 + && prev_length < config.MaxLazy + && ((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD + ) { // To simplify the code, we prevent matches with the string // of window index 0 (in particular we have to avoid a match @@ -1400,8 +1478,13 @@ namespace SharpCompress.Compressors.Deflate // longest_match() sets match_start - if (match_length <= 5 && (compressionStrategy == CompressionStrategy.Filtered || - (match_length == MIN_MATCH && strstart - match_start > 4096))) + if ( + match_length <= 5 + && ( + compressionStrategy == CompressionStrategy.Filtered + || (match_length == MIN_MATCH && strstart - match_start > 4096) + ) + ) { // If prev_match is also MIN_MATCH, match_start is garbage // but we will ignore the current match anyway. @@ -1431,16 +1514,18 @@ namespace SharpCompress.Compressors.Deflate { if (++strstart <= max_insert) { - ins_h = (((ins_h) << hash_shift) ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff)) & - hash_mask; + ins_h = + ( + ((ins_h) << hash_shift) + ^ (window[(strstart) + (MIN_MATCH - 1)] & 0xff) + ) & hash_mask; //prev[strstart&w_mask]=hash_head=head[ins_h]; hash_head = (head[ins_h] & 0xffff); prev[strstart & w_mask] = head[ins_h]; head[ins_h] = unchecked((short)strstart); } - } - while (--prev_length != 0); + } while (--prev_length != 0); match_available = 0; match_length = MIN_MATCH - 1; strstart++; @@ -1510,7 +1595,8 @@ namespace SharpCompress.Compressors.Deflate int match; // matched string int len; // length of current match int best_len = prev_length; // best match length so far - int limit = strstart > (w_size - MIN_LOOKAHEAD) ? strstart - (w_size - MIN_LOOKAHEAD) : 0; + int limit = + strstart > (w_size - MIN_LOOKAHEAD) ? strstart - (w_size - MIN_LOOKAHEAD) : 0; int niceLength = config.NiceLength; @@ -1545,10 +1631,12 @@ namespace SharpCompress.Compressors.Deflate // Skip to next match if the match length cannot increase // or if the match length is less than 2: - if (window[match + best_len] != scan_end || - window[match + best_len - 1] != scan_end1 || - window[match] != window[scan] || - window[++match] != window[scan + 1]) + if ( + window[match + best_len] != scan_end + || window[match + best_len - 1] != scan_end1 + || window[match] != window[scan] + || window[++match] != window[scan + 1] + ) { continue; } @@ -1563,17 +1651,17 @@ namespace SharpCompress.Compressors.Deflate // We check for insufficient lookahead only every 8th comparison; // the 256th check will be made at strstart+258. - do - { - } - while (window[++scan] == window[++match] && - window[++scan] == window[++match] && - window[++scan] == window[++match] && - window[++scan] == window[++match] && - window[++scan] == window[++match] && - window[++scan] == window[++match] && - window[++scan] == window[++match] && - window[++scan] == window[++match] && scan < strend); + do { } while ( + window[++scan] == window[++match] + && window[++scan] == window[++match] + && window[++scan] == window[++match] + && window[++scan] == window[++match] + && window[++scan] == window[++match] + && window[++scan] == window[++match] + && window[++scan] == window[++match] + && window[++scan] == window[++match] + && scan < strend + ); len = MAX_MATCH - (strend - scan); scan = strend - MAX_MATCH; @@ -1589,8 +1677,9 @@ namespace SharpCompress.Compressors.Deflate scan_end1 = window[scan + best_len - 1]; scan_end = window[scan + best_len]; } - } - while ((cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length != 0); + } while ( + (cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length != 0 + ); if (best_len <= lookahead) { @@ -1613,14 +1702,23 @@ namespace SharpCompress.Compressors.Deflate return Initialize(codec, level, bits, MEM_LEVEL_DEFAULT, CompressionStrategy.Default); } - internal int Initialize(ZlibCodec codec, CompressionLevel level, int bits, - CompressionStrategy compressionStrategy) + internal int Initialize( + ZlibCodec codec, + CompressionLevel level, + int bits, + CompressionStrategy compressionStrategy + ) { return Initialize(codec, level, bits, MEM_LEVEL_DEFAULT, compressionStrategy); } - internal int Initialize(ZlibCodec codec, CompressionLevel level, int windowBits, int memLevel, - CompressionStrategy strategy) + internal int Initialize( + ZlibCodec codec, + CompressionLevel level, + int windowBits, + int memLevel, + CompressionStrategy strategy + ) { _codec = codec; _codec.Message = null; @@ -1633,7 +1731,9 @@ namespace SharpCompress.Compressors.Deflate if (memLevel < 1 || memLevel > MEM_LEVEL_MAX) { - throw new ZlibException(String.Format("memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX)); + throw new ZlibException( + String.Format("memLevel must be in the range 1.. {0}", MEM_LEVEL_MAX) + ); } _codec.dstate = this; @@ -1655,7 +1755,7 @@ namespace SharpCompress.Compressors.Deflate lit_bufsize = 1 << (memLevel + 6); // Use a single array as the buffer for data pending compression, - // the output distance codes, and the output length codes (aka tree). + // the output distance codes, and the output length codes (aka tree). // orig comment: This works just fine since the average // output size for (length,distance) codes is <= 24 bits. pending = new byte[lit_bufsize * 4]; @@ -1664,7 +1764,7 @@ namespace SharpCompress.Compressors.Deflate // So, for memLevel 8, the length of the pending buffer is 65536. 64k. // The first 16k are pending bytes. - // The middle slice, of 32k, is used for distance codes. + // The middle slice, of 32k, is used for distance codes. // The final 16k are length codes. compressionLevel = level; @@ -1749,7 +1849,7 @@ namespace SharpCompress.Compressors.Deflate SetDeflater(); } - // no need to flush with change in strategy? Really? + // no need to flush with change in strategy? Really? compressionStrategy = strategy; return result; @@ -1789,7 +1889,8 @@ namespace SharpCompress.Compressors.Deflate for (int n = 0; n <= length - MIN_MATCH; n++) { - ins_h = (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; + ins_h = + (((ins_h) << hash_shift) ^ (window[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask; prev[n & w_mask] = head[ins_h]; head[ins_h] = (short)n; } @@ -1800,18 +1901,24 @@ namespace SharpCompress.Compressors.Deflate { int old_flush; - if (_codec.OutputBuffer is null || - (_codec.InputBuffer is null && _codec.AvailableBytesIn != 0) || - (status == FINISH_STATE && flush != FlushType.Finish)) + if ( + _codec.OutputBuffer is null + || (_codec.InputBuffer is null && _codec.AvailableBytesIn != 0) + || (status == FINISH_STATE && flush != FlushType.Finish) + ) { - _codec.Message = _ErrorMessage[ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_STREAM_ERROR)]; + _codec.Message = _ErrorMessage[ + ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_STREAM_ERROR) + ]; throw new ZlibException(String.Format("Something is fishy. [{0}]", _codec.Message)); //return ZlibConstants.Z_STREAM_ERROR; } if (_codec.AvailableBytesOut == 0) { - _codec.Message = _ErrorMessage[ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR)]; + _codec.Message = _ErrorMessage[ + ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR) + ]; throw new ZlibException("OutputBuffer is full (AvailableBytesOut == 0)"); //return ZlibConstants.Z_BUF_ERROR; @@ -1838,7 +1945,6 @@ namespace SharpCompress.Compressors.Deflate header += 31 - (header % 31); status = BUSY_STATE; - //putShortMSB(header); unchecked { @@ -1880,9 +1986,9 @@ namespace SharpCompress.Compressors.Deflate // flushes. For repeated and useless calls with Z_FINISH, we keep // returning Z_STREAM_END instead of Z_BUFF_ERROR. } - else if (_codec.AvailableBytesIn == 0 && - (int)flush <= old_flush && - flush != FlushType.Finish) + else if ( + _codec.AvailableBytesIn == 0 && (int)flush <= old_flush && flush != FlushType.Finish + ) { // workitem 8557 // Not sure why this needs to be an error. @@ -1899,12 +2005,18 @@ namespace SharpCompress.Compressors.Deflate // User must not provide more input after the first FINISH: if (status == FINISH_STATE && _codec.AvailableBytesIn != 0) { - _codec.Message = _ErrorMessage[ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR)]; + _codec.Message = _ErrorMessage[ + ZlibConstants.Z_NEED_DICT - (ZlibConstants.Z_BUF_ERROR) + ]; throw new ZlibException("status == FINISH_STATE && _codec.AvailableBytesIn != 0"); } // Start a new block or continue the current one. - if (_codec.AvailableBytesIn != 0 || lookahead != 0 || (flush != FlushType.None && status != FINISH_STATE)) + if ( + _codec.AvailableBytesIn != 0 + || lookahead != 0 + || (flush != FlushType.None && status != FINISH_STATE) + ) { BlockState bstate = DeflateFunction(flush); @@ -1988,4 +2100,4 @@ namespace SharpCompress.Compressors.Deflate return pendingCount != 0 ? ZlibConstants.Z_OK : ZlibConstants.Z_STREAM_END; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/DeflateStream.cs b/src/SharpCompress/Compressors/Deflate/DeflateStream.cs index e3b18f6a..c34b8282 100644 --- a/src/SharpCompress/Compressors/Deflate/DeflateStream.cs +++ b/src/SharpCompress/Compressors/Deflate/DeflateStream.cs @@ -35,11 +35,20 @@ namespace SharpCompress.Compressors.Deflate private readonly ZlibBaseStream _baseStream; private bool _disposed; - public DeflateStream(Stream stream, CompressionMode mode, - CompressionLevel level = CompressionLevel.Default, - Encoding? forceEncoding = null) + public DeflateStream( + Stream stream, + CompressionMode mode, + CompressionLevel level = CompressionLevel.Default, + Encoding? forceEncoding = null + ) { - _baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.DEFLATE, forceEncoding); + _baseStream = new ZlibBaseStream( + stream, + mode, + level, + ZlibStreamFlavor.DEFLATE, + forceEncoding + ); } #region Zlib properties @@ -95,8 +104,12 @@ namespace SharpCompress.Compressors.Deflate if (value < ZlibConstants.WorkingBufferSizeMin) { throw new ZlibException( - String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value, - ZlibConstants.WorkingBufferSizeMin)); + String.Format( + "Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", + value, + ZlibConstants.WorkingBufferSizeMin + ) + ); } _baseStream._bufferSize = value; } @@ -360,7 +373,11 @@ namespace SharpCompress.Compressors.Deflate #endregion - public MemoryStream InputBuffer => new MemoryStream(_baseStream._z.InputBuffer, _baseStream._z.NextIn, - _baseStream._z.AvailableBytesIn); + public MemoryStream InputBuffer => + new MemoryStream( + _baseStream._z.InputBuffer, + _baseStream._z.NextIn, + _baseStream._z.AvailableBytesIn + ); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/FlushType.cs b/src/SharpCompress/Compressors/Deflate/FlushType.cs index 9a3cc774..1cb4eb06 100644 --- a/src/SharpCompress/Compressors/Deflate/FlushType.cs +++ b/src/SharpCompress/Compressors/Deflate/FlushType.cs @@ -1,7 +1,7 @@ namespace SharpCompress.Compressors.Deflate { /// - /// Describes how to flush the current deflate operation. + /// Describes how to flush the current deflate operation. /// /// /// The different FlushType values are useful when using a Deflate in a streaming application. @@ -14,7 +14,7 @@ /// Closes the current block, but doesn't flush it to /// the output. Used internally only in hypothetical /// scenarios. This was supposed to be removed by Zlib, but it is - /// still in use in some edge cases. + /// still in use in some edge cases. /// Partial, @@ -41,4 +41,4 @@ /// Signals the end of the compression/decompression stream. Finish } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/GZipStream.cs b/src/SharpCompress/Compressors/Deflate/GZipStream.cs index ffc4759d..572f677e 100644 --- a/src/SharpCompress/Compressors/Deflate/GZipStream.cs +++ b/src/SharpCompress/Compressors/Deflate/GZipStream.cs @@ -35,7 +35,15 @@ namespace SharpCompress.Compressors.Deflate { public class GZipStream : Stream { - internal static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + internal static readonly DateTime UNIX_EPOCH = new DateTime( + 1970, + 1, + 1, + 0, + 0, + 0, + DateTimeKind.Utc + ); private string? _comment; private string? _fileName; @@ -49,16 +57,17 @@ namespace SharpCompress.Compressors.Deflate private readonly Encoding _encoding; public GZipStream(Stream stream, CompressionMode mode) - : this(stream, mode, CompressionLevel.Default, Encoding.UTF8) - { - } + : this(stream, mode, CompressionLevel.Default, Encoding.UTF8) { } public GZipStream(Stream stream, CompressionMode mode, CompressionLevel level) - : this(stream, mode, level, Encoding.UTF8) - { - } + : this(stream, mode, level, Encoding.UTF8) { } - public GZipStream(Stream stream, CompressionMode mode, CompressionLevel level, Encoding encoding) + public GZipStream( + Stream stream, + CompressionMode mode, + CompressionLevel level, + Encoding encoding + ) { BaseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.GZIP, encoding); _encoding = encoding; @@ -95,8 +104,12 @@ namespace SharpCompress.Compressors.Deflate if (value < ZlibConstants.WorkingBufferSizeMin) { throw new ZlibException( - String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value, - ZlibConstants.WorkingBufferSizeMin)); + String.Format( + "Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", + value, + ZlibConstants.WorkingBufferSizeMin + ) + ); } BaseStream._bufferSize = value; } @@ -184,7 +197,6 @@ namespace SharpCompress.Compressors.Deflate } return 0; } - set => throw new NotSupportedException(); } @@ -358,7 +370,6 @@ namespace SharpCompress.Compressors.Deflate } } - public DateTime? LastModified { get => _lastModified; @@ -407,10 +418,8 @@ namespace SharpCompress.Compressors.Deflate private int EmitHeader() { - byte[]? commentBytes = (Comment is null) ? null - : _encoding.GetBytes(Comment); - byte[]? filenameBytes = (FileName is null) ? null - : _encoding.GetBytes(FileName); + byte[]? commentBytes = (Comment is null) ? null : _encoding.GetBytes(Comment); + byte[]? filenameBytes = (FileName is null) ? null : _encoding.GetBytes(FileName); int cbLength = commentBytes?.Length + 1 ?? 0; int fnLength = filenameBytes?.Length + 1 ?? 0; diff --git a/src/SharpCompress/Compressors/Deflate/InfTree.cs b/src/SharpCompress/Compressors/Deflate/InfTree.cs index ccbc37bc..9d8e4fe6 100644 --- a/src/SharpCompress/Compressors/Deflate/InfTree.cs +++ b/src/SharpCompress/Compressors/Deflate/InfTree.cs @@ -1,45 +1,45 @@ // Inftree.cs // ------------------------------------------------------------------ // -// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. +// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. // All rights reserved. // // This code module is part of DotNetZip, a zipfile class library. // // ------------------------------------------------------------------ // -// This code is licensed under the Microsoft Public License. +// This code is licensed under the Microsoft Public License. // See the file License.txt for the license details. // More info on: http://dotnetzip.codeplex.com // // ------------------------------------------------------------------ // -// last saved (in emacs): +// last saved (in emacs): // Time-stamp: <2009-October-28 12:43:54> // // ------------------------------------------------------------------ // // This module defines classes used in decompression. This code is derived -// from the jzlib implementation of zlib. In keeping with the license for jzlib, +// from the jzlib implementation of zlib. In keeping with the license for jzlib, // the copyright to that code is below. // // ------------------------------------------------------------------ -// +// // Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the distribution. -// +// // 3. The names of the authors may not be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, @@ -50,7 +50,7 @@ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // ----------------------------------------------------------------------- // // This program is based on zlib-1.1.3; credit to authors @@ -86,135 +86,1750 @@ namespace SharpCompress.Compressors.Deflate //UPGRADE_NOTE: Final was removed from the declaration of 'fixed_tl'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal static readonly int[] fixed_tl = { - 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, - 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, - 160, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, - 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, - 208, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 176, 0, 8, 8, 0, 8, - 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, - 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13, 0, - 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, - 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, - 8, 124, 0, 8, 60, 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0 - , 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, - 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50 - , 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2 - , 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8, 26 - , 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, - 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, - 74, 0, 9, 244, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, - 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8 - , 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 236, 80, - 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, - 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0 - , 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, - 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, - 194, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, - 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, - 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210, 81, 7, 17, 0, - 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, - 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0 - , 8, 117, 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, - 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, - 0, 8, 93, 0, 8, 29, 0, 9, 154, 84, 7, 83, 0, 8, 125, 0, 8, 61, - 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, - 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83, - 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, - 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, - 131, 0, 8, 67, 0, 9, 230, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, - 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, - 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, - 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, - 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0 - , 9, 174, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0 - , 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, - 0, 9, 222, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 190, 0, 8, 15 - , 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, - 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 193, 80, - 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8 - , 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, - 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0 - , 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, - 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116 - , 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, - 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8, - 92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, - 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8 - , 140, 0, 8, 76, 0, 9, 249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, - 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, - 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0 - , 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, - 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42 - , 0, 9, 181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, - 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, - 54, 0, 9, 205, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 173, 0, 8 - , 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, - 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 221, 82, - 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, - 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8 - , 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 195, - 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, - 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 147, - 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, - 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, - 243, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8 - , 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, - 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 235, 80, 7, 8, 0, - 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, - 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0 - , 8, 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, - 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, - 11, 0, 8, 99, 0, 8, 35, 0, 9, 167, 0, 8, 3, 0, 8, 131, 0, 8, - 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, - 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8, 107, 0, 8 - , 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, - 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, - 8, 55, 0, 9, 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0 - , 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, - 8, 31, 0, 9, 159, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 223, - 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143 - , 0, 8, 79, 0, 9, 255 + 96, + 7, + 256, + 0, + 8, + 80, + 0, + 8, + 16, + 84, + 8, + 115, + 82, + 7, + 31, + 0, + 8, + 112, + 0, + 8, + 48, + 0, + 9, + 192, + 80, + 7, + 10, + 0, + 8, + 96, + 0, + 8, + 32, + 0, + 9, + 160, + 0, + 8, + 0, + 0, + 8, + 128, + 0, + 8, + 64, + 0, + 9, + 224, + 80, + 7, + 6, + 0, + 8, + 88, + 0, + 8, + 24, + 0, + 9, + 144, + 83, + 7, + 59, + 0, + 8, + 120, + 0, + 8, + 56, + 0, + 9, + 208, + 81, + 7, + 17, + 0, + 8, + 104, + 0, + 8, + 40, + 0, + 9, + 176, + 0, + 8, + 8, + 0, + 8, + 136, + 0, + 8, + 72, + 0, + 9, + 240, + 80, + 7, + 4, + 0, + 8, + 84, + 0, + 8, + 20, + 85, + 8, + 227, + 83, + 7, + 43, + 0, + 8, + 116, + 0, + 8, + 52, + 0, + 9, + 200, + 81, + 7, + 13, + 0, + 8, + 100, + 0, + 8, + 36, + 0, + 9, + 168, + 0, + 8, + 4, + 0, + 8, + 132, + 0, + 8, + 68, + 0, + 9, + 232, + 80, + 7, + 8, + 0, + 8, + 92, + 0, + 8, + 28, + 0, + 9, + 152, + 84, + 7, + 83, + 0, + 8, + 124, + 0, + 8, + 60, + 0, + 9, + 216, + 82, + 7, + 23, + 0, + 8, + 108, + 0, + 8, + 44, + 0, + 9, + 184, + 0, + 8, + 12, + 0, + 8, + 140, + 0, + 8, + 76, + 0, + 9, + 248, + 80, + 7, + 3, + 0, + 8, + 82, + 0, + 8, + 18, + 85, + 8, + 163, + 83, + 7, + 35, + 0, + 8, + 114, + 0, + 8, + 50, + 0, + 9, + 196, + 81, + 7, + 11, + 0, + 8, + 98, + 0, + 8, + 34, + 0, + 9, + 164, + 0, + 8, + 2, + 0, + 8, + 130, + 0, + 8, + 66, + 0, + 9, + 228, + 80, + 7, + 7, + 0, + 8, + 90, + 0, + 8, + 26, + 0, + 9, + 148, + 84, + 7, + 67, + 0, + 8, + 122, + 0, + 8, + 58, + 0, + 9, + 212, + 82, + 7, + 19, + 0, + 8, + 106, + 0, + 8, + 42, + 0, + 9, + 180, + 0, + 8, + 10, + 0, + 8, + 138, + 0, + 8, + 74, + 0, + 9, + 244, + 80, + 7, + 5, + 0, + 8, + 86, + 0, + 8, + 22, + 192, + 8, + 0, + 83, + 7, + 51, + 0, + 8, + 118, + 0, + 8, + 54, + 0, + 9, + 204, + 81, + 7, + 15, + 0, + 8, + 102, + 0, + 8, + 38, + 0, + 9, + 172, + 0, + 8, + 6, + 0, + 8, + 134, + 0, + 8, + 70, + 0, + 9, + 236, + 80, + 7, + 9, + 0, + 8, + 94, + 0, + 8, + 30, + 0, + 9, + 156, + 84, + 7, + 99, + 0, + 8, + 126, + 0, + 8, + 62, + 0, + 9, + 220, + 82, + 7, + 27, + 0, + 8, + 110, + 0, + 8, + 46, + 0, + 9, + 188, + 0, + 8, + 14, + 0, + 8, + 142, + 0, + 8, + 78, + 0, + 9, + 252, + 96, + 7, + 256, + 0, + 8, + 81, + 0, + 8, + 17, + 85, + 8, + 131, + 82, + 7, + 31, + 0, + 8, + 113, + 0, + 8, + 49, + 0, + 9, + 194, + 80, + 7, + 10, + 0, + 8, + 97, + 0, + 8, + 33, + 0, + 9, + 162, + 0, + 8, + 1, + 0, + 8, + 129, + 0, + 8, + 65, + 0, + 9, + 226, + 80, + 7, + 6, + 0, + 8, + 89, + 0, + 8, + 25, + 0, + 9, + 146, + 83, + 7, + 59, + 0, + 8, + 121, + 0, + 8, + 57, + 0, + 9, + 210, + 81, + 7, + 17, + 0, + 8, + 105, + 0, + 8, + 41, + 0, + 9, + 178, + 0, + 8, + 9, + 0, + 8, + 137, + 0, + 8, + 73, + 0, + 9, + 242, + 80, + 7, + 4, + 0, + 8, + 85, + 0, + 8, + 21, + 80, + 8, + 258, + 83, + 7, + 43, + 0, + 8, + 117, + 0, + 8, + 53, + 0, + 9, + 202, + 81, + 7, + 13, + 0, + 8, + 101, + 0, + 8, + 37, + 0, + 9, + 170, + 0, + 8, + 5, + 0, + 8, + 133, + 0, + 8, + 69, + 0, + 9, + 234, + 80, + 7, + 8, + 0, + 8, + 93, + 0, + 8, + 29, + 0, + 9, + 154, + 84, + 7, + 83, + 0, + 8, + 125, + 0, + 8, + 61, + 0, + 9, + 218, + 82, + 7, + 23, + 0, + 8, + 109, + 0, + 8, + 45, + 0, + 9, + 186, + 0, + 8, + 13, + 0, + 8, + 141, + 0, + 8, + 77, + 0, + 9, + 250, + 80, + 7, + 3, + 0, + 8, + 83, + 0, + 8, + 19, + 85, + 8, + 195, + 83, + 7, + 35, + 0, + 8, + 115, + 0, + 8, + 51, + 0, + 9, + 198, + 81, + 7, + 11, + 0, + 8, + 99, + 0, + 8, + 35, + 0, + 9, + 166, + 0, + 8, + 3, + 0, + 8, + 131, + 0, + 8, + 67, + 0, + 9, + 230, + 80, + 7, + 7, + 0, + 8, + 91, + 0, + 8, + 27, + 0, + 9, + 150, + 84, + 7, + 67, + 0, + 8, + 123, + 0, + 8, + 59, + 0, + 9, + 214, + 82, + 7, + 19, + 0, + 8, + 107, + 0, + 8, + 43, + 0, + 9, + 182, + 0, + 8, + 11, + 0, + 8, + 139, + 0, + 8, + 75, + 0, + 9, + 246, + 80, + 7, + 5, + 0, + 8, + 87, + 0, + 8, + 23, + 192, + 8, + 0, + 83, + 7, + 51, + 0, + 8, + 119, + 0, + 8, + 55, + 0, + 9, + 206, + 81, + 7, + 15, + 0, + 8, + 103, + 0, + 8, + 39, + 0, + 9, + 174, + 0, + 8, + 7, + 0, + 8, + 135, + 0, + 8, + 71, + 0, + 9, + 238, + 80, + 7, + 9, + 0, + 8, + 95, + 0, + 8, + 31, + 0, + 9, + 158, + 84, + 7, + 99, + 0, + 8, + 127, + 0, + 8, + 63, + 0, + 9, + 222, + 82, + 7, + 27, + 0, + 8, + 111, + 0, + 8, + 47, + 0, + 9, + 190, + 0, + 8, + 15, + 0, + 8, + 143, + 0, + 8, + 79, + 0, + 9, + 254, + 96, + 7, + 256, + 0, + 8, + 80, + 0, + 8, + 16, + 84, + 8, + 115, + 82, + 7, + 31, + 0, + 8, + 112, + 0, + 8, + 48, + 0, + 9, + 193, + 80, + 7, + 10, + 0, + 8, + 96, + 0, + 8, + 32, + 0, + 9, + 161, + 0, + 8, + 0, + 0, + 8, + 128, + 0, + 8, + 64, + 0, + 9, + 225, + 80, + 7, + 6, + 0, + 8, + 88, + 0, + 8, + 24, + 0, + 9, + 145, + 83, + 7, + 59, + 0, + 8, + 120, + 0, + 8, + 56, + 0, + 9, + 209, + 81, + 7, + 17, + 0, + 8, + 104, + 0, + 8, + 40, + 0, + 9, + 177, + 0, + 8, + 8, + 0, + 8, + 136, + 0, + 8, + 72, + 0, + 9, + 241, + 80, + 7, + 4, + 0, + 8, + 84, + 0, + 8, + 20, + 85, + 8, + 227, + 83, + 7, + 43, + 0, + 8, + 116, + 0, + 8, + 52, + 0, + 9, + 201, + 81, + 7, + 13, + 0, + 8, + 100, + 0, + 8, + 36, + 0, + 9, + 169, + 0, + 8, + 4, + 0, + 8, + 132, + 0, + 8, + 68, + 0, + 9, + 233, + 80, + 7, + 8, + 0, + 8, + 92, + 0, + 8, + 28, + 0, + 9, + 153, + 84, + 7, + 83, + 0, + 8, + 124, + 0, + 8, + 60, + 0, + 9, + 217, + 82, + 7, + 23, + 0, + 8, + 108, + 0, + 8, + 44, + 0, + 9, + 185, + 0, + 8, + 12, + 0, + 8, + 140, + 0, + 8, + 76, + 0, + 9, + 249, + 80, + 7, + 3, + 0, + 8, + 82, + 0, + 8, + 18, + 85, + 8, + 163, + 83, + 7, + 35, + 0, + 8, + 114, + 0, + 8, + 50, + 0, + 9, + 197, + 81, + 7, + 11, + 0, + 8, + 98, + 0, + 8, + 34, + 0, + 9, + 165, + 0, + 8, + 2, + 0, + 8, + 130, + 0, + 8, + 66, + 0, + 9, + 229, + 80, + 7, + 7, + 0, + 8, + 90, + 0, + 8, + 26, + 0, + 9, + 149, + 84, + 7, + 67, + 0, + 8, + 122, + 0, + 8, + 58, + 0, + 9, + 213, + 82, + 7, + 19, + 0, + 8, + 106, + 0, + 8, + 42, + 0, + 9, + 181, + 0, + 8, + 10, + 0, + 8, + 138, + 0, + 8, + 74, + 0, + 9, + 245, + 80, + 7, + 5, + 0, + 8, + 86, + 0, + 8, + 22, + 192, + 8, + 0, + 83, + 7, + 51, + 0, + 8, + 118, + 0, + 8, + 54, + 0, + 9, + 205, + 81, + 7, + 15, + 0, + 8, + 102, + 0, + 8, + 38, + 0, + 9, + 173, + 0, + 8, + 6, + 0, + 8, + 134, + 0, + 8, + 70, + 0, + 9, + 237, + 80, + 7, + 9, + 0, + 8, + 94, + 0, + 8, + 30, + 0, + 9, + 157, + 84, + 7, + 99, + 0, + 8, + 126, + 0, + 8, + 62, + 0, + 9, + 221, + 82, + 7, + 27, + 0, + 8, + 110, + 0, + 8, + 46, + 0, + 9, + 189, + 0, + 8, + 14, + 0, + 8, + 142, + 0, + 8, + 78, + 0, + 9, + 253, + 96, + 7, + 256, + 0, + 8, + 81, + 0, + 8, + 17, + 85, + 8, + 131, + 82, + 7, + 31, + 0, + 8, + 113, + 0, + 8, + 49, + 0, + 9, + 195, + 80, + 7, + 10, + 0, + 8, + 97, + 0, + 8, + 33, + 0, + 9, + 163, + 0, + 8, + 1, + 0, + 8, + 129, + 0, + 8, + 65, + 0, + 9, + 227, + 80, + 7, + 6, + 0, + 8, + 89, + 0, + 8, + 25, + 0, + 9, + 147, + 83, + 7, + 59, + 0, + 8, + 121, + 0, + 8, + 57, + 0, + 9, + 211, + 81, + 7, + 17, + 0, + 8, + 105, + 0, + 8, + 41, + 0, + 9, + 179, + 0, + 8, + 9, + 0, + 8, + 137, + 0, + 8, + 73, + 0, + 9, + 243, + 80, + 7, + 4, + 0, + 8, + 85, + 0, + 8, + 21, + 80, + 8, + 258, + 83, + 7, + 43, + 0, + 8, + 117, + 0, + 8, + 53, + 0, + 9, + 203, + 81, + 7, + 13, + 0, + 8, + 101, + 0, + 8, + 37, + 0, + 9, + 171, + 0, + 8, + 5, + 0, + 8, + 133, + 0, + 8, + 69, + 0, + 9, + 235, + 80, + 7, + 8, + 0, + 8, + 93, + 0, + 8, + 29, + 0, + 9, + 155, + 84, + 7, + 83, + 0, + 8, + 125, + 0, + 8, + 61, + 0, + 9, + 219, + 82, + 7, + 23, + 0, + 8, + 109, + 0, + 8, + 45, + 0, + 9, + 187, + 0, + 8, + 13, + 0, + 8, + 141, + 0, + 8, + 77, + 0, + 9, + 251, + 80, + 7, + 3, + 0, + 8, + 83, + 0, + 8, + 19, + 85, + 8, + 195, + 83, + 7, + 35, + 0, + 8, + 115, + 0, + 8, + 51, + 0, + 9, + 199, + 81, + 7, + 11, + 0, + 8, + 99, + 0, + 8, + 35, + 0, + 9, + 167, + 0, + 8, + 3, + 0, + 8, + 131, + 0, + 8, + 67, + 0, + 9, + 231, + 80, + 7, + 7, + 0, + 8, + 91, + 0, + 8, + 27, + 0, + 9, + 151, + 84, + 7, + 67, + 0, + 8, + 123, + 0, + 8, + 59, + 0, + 9, + 215, + 82, + 7, + 19, + 0, + 8, + 107, + 0, + 8, + 43, + 0, + 9, + 183, + 0, + 8, + 11, + 0, + 8, + 139, + 0, + 8, + 75, + 0, + 9, + 247, + 80, + 7, + 5, + 0, + 8, + 87, + 0, + 8, + 23, + 192, + 8, + 0, + 83, + 7, + 51, + 0, + 8, + 119, + 0, + 8, + 55, + 0, + 9, + 207, + 81, + 7, + 15, + 0, + 8, + 103, + 0, + 8, + 39, + 0, + 9, + 175, + 0, + 8, + 7, + 0, + 8, + 135, + 0, + 8, + 71, + 0, + 9, + 239, + 80, + 7, + 9, + 0, + 8, + 95, + 0, + 8, + 31, + 0, + 9, + 159, + 84, + 7, + 99, + 0, + 8, + 127, + 0, + 8, + 63, + 0, + 9, + 223, + 82, + 7, + 27, + 0, + 8, + 111, + 0, + 8, + 47, + 0, + 9, + 191, + 0, + 8, + 15, + 0, + 8, + 143, + 0, + 8, + 79, + 0, + 9, + 255 }; //UPGRADE_NOTE: Final was removed from the declaration of 'fixed_td'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal static readonly int[] fixed_td = { - 80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, - 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33 - , - 92, 5, 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, - 80 - , 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, - 1537 - , 85, 5, 97, 93, 5, 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92 - , 5 - , 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577 + 80, + 5, + 1, + 87, + 5, + 257, + 83, + 5, + 17, + 91, + 5, + 4097, + 81, + 5, + 5, + 89, + 5, + 1025, + 85, + 5, + 65, + 93, + 5, + 16385, + 80, + 5, + 3, + 88, + 5, + 513, + 84, + 5, + 33, + 92, + 5, + 8193, + 82, + 5, + 9, + 90, + 5, + 2049, + 86, + 5, + 129, + 192, + 5, + 24577, + 80, + 5, + 2, + 87, + 5, + 385, + 83, + 5, + 25, + 91, + 5, + 6145, + 81, + 5, + 7, + 89, + 5, + 1537, + 85, + 5, + 97, + 93, + 5, + 24577, + 80, + 5, + 4, + 88, + 5, + 769, + 84, + 5, + 49, + 92, + 5, + 12289, + 82, + 5, + 13, + 90, + 5, + 3073, + 86, + 5, + 193, + 192, + 5, + 24577 }; // Tables for deflate from PKZIP's appnote.txt. //UPGRADE_NOTE: Final was removed from the declaration of 'cplens'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal static readonly int[] cplens = { - 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, 258, 0, 0 + 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, + 258, + 0, + 0 }; // see note #13 above about 258 //UPGRADE_NOTE: Final was removed from the declaration of 'cplext'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal static readonly int[] cplext = { - 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, 112, 112 + 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, + 112, + 112 }; //UPGRADE_NOTE: Final was removed from the declaration of 'cpdist'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal static readonly int[] cpdist = { - 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, + 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 }; @@ -222,9 +1837,36 @@ namespace SharpCompress.Compressors.Deflate //UPGRADE_NOTE: Final was removed from the declaration of 'cpdext'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal static readonly int[] cpdext = { - 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, + 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 }; // If BMAX needs to be larger than 16, then h and x[] should be uLong. @@ -232,11 +1874,22 @@ namespace SharpCompress.Compressors.Deflate internal int[] hn; // hufts used in space internal int[] r; // table entry for structure assignment internal int[] u; // table stack - internal int[] v; // work area for huft_build + internal int[] v; // work area for huft_build internal int[] x; // bit offsets, then code stack - private int huft_build(int[] b, int bindex, int n, int s, int[] d, int[] e, int[] t, int[] m, int[] hp, int[] hn, - int[] v) + private int huft_build( + int[] b, + int bindex, + int n, + int s, + int[] d, + int[] e, + int[] t, + int[] m, + int[] hp, + int[] hn, + int[] v + ) { // Given a list of code lengths and a maximum table size, make a set of // tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR @@ -269,8 +1922,7 @@ namespace SharpCompress.Compressors.Deflate c[b[bindex + p]]++; p++; i--; // assume all entries <= BMAX - } - while (i != 0); + } while (i != 0); if (c[0] == n) { @@ -344,8 +1996,7 @@ namespace SharpCompress.Compressors.Deflate v[x[j]++] = i; } p++; - } - while (++i < n); + } while (++i < n); n = x[g]; // set n to length of v // Generate the Huffman codes and for each, make the table entries @@ -484,8 +2135,17 @@ namespace SharpCompress.Compressors.Deflate return result; } - internal int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, - ZlibCodec z) + internal int inflate_trees_dynamic( + int nl, + int nd, + int[] c, + int[] bl, + int[] bd, + int[] tl, + int[] td, + int[] hp, + ZlibCodec z + ) { int result; @@ -533,7 +2193,13 @@ namespace SharpCompress.Compressors.Deflate return Z_OK; } - internal static int inflate_trees_fixed(int[] bl, int[] bd, int[][] tl, int[][] td, ZlibCodec z) + internal static int inflate_trees_fixed( + int[] bl, + int[] bd, + int[][] tl, + int[][] td, + ZlibCodec z + ) { bl[0] = fixed_bl; bd[0] = fixed_bd; @@ -575,4 +2241,4 @@ namespace SharpCompress.Compressors.Deflate } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/Inflate.cs b/src/SharpCompress/Compressors/Deflate/Inflate.cs index a0672f28..dcab54e2 100644 --- a/src/SharpCompress/Compressors/Deflate/Inflate.cs +++ b/src/SharpCompress/Compressors/Deflate/Inflate.cs @@ -74,7 +74,28 @@ namespace SharpCompress.Compressors.Deflate private const int MANY = 1440; // Table for deflate from PKZIP's appnote.txt. - internal static readonly int[] border = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + internal static readonly int[] border = + { + 16, + 17, + 18, + 0, + 8, + 7, + 9, + 6, + 10, + 5, + 11, + 4, + 12, + 3, + 13, + 2, + 14, + 1, + 15 + }; internal ZlibCodec _codec; // pointer back to this zlib stream internal int[] bb = new int[1]; // bit length tree depth @@ -261,9 +282,10 @@ namespace SharpCompress.Compressors.Deflate } left = (b & 0xffff); b = k = 0; // dump bits - mode = left != 0 - ? InflateBlockMode.STORED - : (last != 0 ? InflateBlockMode.DRY : InflateBlockMode.TYPE); + mode = + left != 0 + ? InflateBlockMode.STORED + : (last != 0 ? InflateBlockMode.DRY : InflateBlockMode.TYPE); break; case InflateBlockMode.STORED: @@ -461,7 +483,9 @@ namespace SharpCompress.Compressors.Deflate break; } - int i, j, c; + int i, + j, + c; t = bb[0]; @@ -487,8 +511,12 @@ namespace SharpCompress.Compressors.Deflate k += 8; } - t = hufts[(tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 1]; - c = hufts[(tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 2]; + t = hufts[ + (tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 1 + ]; + c = hufts[ + (tb[0] + (b & InternalInflateConstants.InflateMask[t])) * 3 + 2 + ]; if (c < 16) { @@ -534,7 +562,10 @@ namespace SharpCompress.Compressors.Deflate i = index; t = table; - if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) + if ( + i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) + || (c == 16 && i < 1) + ) { blens = null; mode = InflateBlockMode.BAD; @@ -554,13 +585,13 @@ namespace SharpCompress.Compressors.Deflate do { blens[i++] = c; - } - while (--j != 0); + } while (--j != 0); index = i; } } tb[0] = -1; + { var bl = new[] { 9 }; // must be <= 9 for lookahead assumptions var bd = new[] { 6 }; // must be <= 9 for lookahead assumptions @@ -568,8 +599,17 @@ namespace SharpCompress.Compressors.Deflate var td = new int[1]; t = table; - t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl, bd, tl, - td, hufts, _codec); + t = inftree.inflate_trees_dynamic( + 257 + (t & 0x1f), + 1 + ((t >> 5) & 0x1f), + blens, + bl, + bd, + tl, + td, + hufts, + _codec + ); if (t != ZlibConstants.Z_OK) { @@ -741,7 +781,10 @@ namespace SharpCompress.Compressors.Deflate // update check information if (checkfn != null) { - _codec._adler32 = check = Adler32.Calculate(check, window.AsSpan(readAt, nBytes)); + _codec._adler32 = check = Adler32.Calculate( + check, + window.AsSpan(readAt, nBytes) + ); } // copy as far as end of window @@ -793,10 +836,23 @@ namespace SharpCompress.Compressors.Deflate // And'ing with mask[n] masks the lower n bits internal static readonly int[] InflateMask = { - 0x00000000, 0x00000001, 0x00000003, 0x00000007, - 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, - 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, - 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff + 0x00000000, + 0x00000001, + 0x00000003, + 0x00000007, + 0x0000000f, + 0x0000001f, + 0x0000003f, + 0x0000007f, + 0x000000ff, + 0x000001ff, + 0x000003ff, + 0x000007ff, + 0x00000fff, + 0x00001fff, + 0x00003fff, + 0x00007fff, + 0x0000ffff }; } @@ -883,7 +939,16 @@ namespace SharpCompress.Compressors.Deflate z.TotalBytesIn += p - z.NextIn; z.NextIn = p; blocks.writeAt = q; - r = InflateFast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, blocks, z); + r = InflateFast( + lbits, + dbits, + ltree, + ltree_index, + dtree, + dtree_index, + blocks, + z + ); p = z.NextIn; n = z.AvailableBytesIn; @@ -917,7 +982,9 @@ namespace SharpCompress.Compressors.Deflate else { // Handling missing trailing bit(s) - var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k])) * 3; + var tmp_tindex = + (tree_index + (b & InternalInflateConstants.InflateMask[k])) + * 3; if (k >= tree[tmp_tindex + 1]) { break; @@ -1030,7 +1097,9 @@ namespace SharpCompress.Compressors.Deflate else { // Handling missing trailing bit(s) - var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k])) * 3; + var tmp_tindex = + (tree_index + (b & InternalInflateConstants.InflateMask[k])) + * 3; if (k >= tree[tmp_tindex + 1]) { break; @@ -1140,7 +1209,10 @@ namespace SharpCompress.Compressors.Deflate if (q == blocks.end && blocks.readAt != 0) { q = 0; - m = q < blocks.readAt ? blocks.readAt - q - 1 : blocks.end - q; + m = + q < blocks.readAt + ? blocks.readAt - q - 1 + : blocks.end - q; } if (m == 0) @@ -1276,8 +1348,16 @@ namespace SharpCompress.Compressors.Deflate // at least ten. The ten bytes are six bytes for the longest length/ // distance pair plus four bytes for overloading the bit buffer. - internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, - ZlibCodec z) + internal int InflateFast( + int bl, + int bd, + int[] tl, + int tl_index, + int[] td, + int td_index, + InflateBlocks s, + ZlibCodec z + ) { int t; // temporary pointer int[] tp; // temporary pointer @@ -1380,7 +1460,9 @@ namespace SharpCompress.Compressors.Deflate k += 8; } - d = tp[tp_index_t_3 + 2] + (b & InternalInflateConstants.InflateMask[e]); + d = + tp[tp_index_t_3 + 2] + + (b & InternalInflateConstants.InflateMask[e]); b >>= e; k -= e; @@ -1413,8 +1495,7 @@ namespace SharpCompress.Compressors.Deflate do { r += s.end; // force pointer in window - } - while (r < 0); // covers invalid distances + } while (r < 0); // covers invalid distances e = s.end - r; if (c > e) { @@ -1425,8 +1506,7 @@ namespace SharpCompress.Compressors.Deflate do { s.window[q++] = s.window[r++]; - } - while (--e != 0); + } while (--e != 0); } else { @@ -1445,8 +1525,7 @@ namespace SharpCompress.Compressors.Deflate do { s.window[q++] = s.window[r++]; - } - while (--c != 0); + } while (--c != 0); } else { @@ -1483,8 +1562,7 @@ namespace SharpCompress.Compressors.Deflate return ZlibConstants.Z_DATA_ERROR; } - } - while (true); + } while (true); break; } @@ -1538,10 +1616,8 @@ namespace SharpCompress.Compressors.Deflate return ZlibConstants.Z_DATA_ERROR; } - } - while (true); - } - while (m >= 258 && n >= 10); + } while (true); + } while (m >= 258 && n >= 10); // not enough input or output--restore pointers and return c = z.AvailableBytesIn - n; @@ -1588,9 +1664,7 @@ namespace SharpCompress.Compressors.Deflate internal int wbits; // log2(window size) (8..15, defaults to 15) - public InflateManager() - { - } + public InflateManager() { } public InflateManager(bool expectRfc1950HeaderBytes) { @@ -1642,9 +1716,7 @@ namespace SharpCompress.Compressors.Deflate } wbits = w; - blocks = new InflateBlocks(codec, - HandleRfc1950HeaderBytes ? this : null, - 1 << w); + blocks = new InflateBlocks(codec, HandleRfc1950HeaderBytes ? this : null, 1 << w); // reset state Reset(); @@ -1683,14 +1755,20 @@ namespace SharpCompress.Compressors.Deflate if (((method = _codec.InputBuffer[_codec.NextIn++]) & 0xf) != Z_DEFLATED) { mode = InflateManagerMode.BAD; - _codec.Message = String.Format("unknown compression method (0x{0:X2})", method); + _codec.Message = String.Format( + "unknown compression method (0x{0:X2})", + method + ); marker = 5; // can't try inflateSync break; } if ((method >> 4) + 8 > wbits) { mode = InflateManagerMode.BAD; - _codec.Message = String.Format("invalid window size ({0})", (method >> 4) + 8); + _codec.Message = String.Format( + "invalid window size ({0})", + (method >> 4) + 8 + ); marker = 5; // can't try inflateSync break; } @@ -1715,9 +1793,10 @@ namespace SharpCompress.Compressors.Deflate break; } - mode = ((b & PRESET_DICT) == 0) - ? InflateManagerMode.BLOCKS - : InflateManagerMode.DICT4; + mode = + ((b & PRESET_DICT) == 0) + ? InflateManagerMode.BLOCKS + : InflateManagerMode.DICT4; break; case InflateManagerMode.DICT4: @@ -1728,7 +1807,9 @@ namespace SharpCompress.Compressors.Deflate r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; - expectedCheck = (uint)((_codec.InputBuffer[_codec.NextIn++] << 24) & 0xff000000); + expectedCheck = (uint)( + (_codec.InputBuffer[_codec.NextIn++] << 24) & 0xff000000 + ); mode = InflateManagerMode.DICT3; break; @@ -1740,7 +1821,9 @@ namespace SharpCompress.Compressors.Deflate r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; - expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 16) & 0x00ff0000); + expectedCheck += (uint)( + (_codec.InputBuffer[_codec.NextIn++] << 16) & 0x00ff0000 + ); mode = InflateManagerMode.DICT2; break; @@ -1753,7 +1836,9 @@ namespace SharpCompress.Compressors.Deflate r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; - expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 8) & 0x0000ff00); + expectedCheck += (uint)( + (_codec.InputBuffer[_codec.NextIn++] << 8) & 0x0000ff00 + ); mode = InflateManagerMode.DICT1; break; @@ -1813,7 +1898,9 @@ namespace SharpCompress.Compressors.Deflate r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; - expectedCheck = (uint)((_codec.InputBuffer[_codec.NextIn++] << 24) & 0xff000000); + expectedCheck = (uint)( + (_codec.InputBuffer[_codec.NextIn++] << 24) & 0xff000000 + ); mode = InflateManagerMode.CHECK3; break; @@ -1825,7 +1912,9 @@ namespace SharpCompress.Compressors.Deflate r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; - expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 16) & 0x00ff0000); + expectedCheck += (uint)( + (_codec.InputBuffer[_codec.NextIn++] << 16) & 0x00ff0000 + ); mode = InflateManagerMode.CHECK2; break; @@ -1837,7 +1926,9 @@ namespace SharpCompress.Compressors.Deflate r = f; _codec.AvailableBytesIn--; _codec.TotalBytesIn++; - expectedCheck += (uint)((_codec.InputBuffer[_codec.NextIn++] << 8) & 0x0000ff00); + expectedCheck += (uint)( + (_codec.InputBuffer[_codec.NextIn++] << 8) & 0x0000ff00 + ); mode = InflateManagerMode.CHECK1; break; @@ -1903,7 +1994,8 @@ namespace SharpCompress.Compressors.Deflate int n; // number of bytes to look at int p; // pointer to bytes int m; // number of marker bytes found in a row - long r, w; // temporaries to save total_in and total_out + long r, + w; // temporaries to save total_in and total_out // set up if (mode != InflateManagerMode.BAD) @@ -1990,4 +2082,4 @@ namespace SharpCompress.Compressors.Deflate #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/Tree.cs b/src/SharpCompress/Compressors/Deflate/Tree.cs index 54c1620e..3804679d 100644 --- a/src/SharpCompress/Compressors/Deflate/Tree.cs +++ b/src/SharpCompress/Compressors/Deflate/Tree.cs @@ -3,20 +3,20 @@ // Tree.cs // ------------------------------------------------------------------ // -// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. +// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. // All rights reserved. // // This code module is part of DotNetZip, a zipfile class library. // // ------------------------------------------------------------------ // -// This code is licensed under the Microsoft Public License. +// This code is licensed under the Microsoft Public License. // See the file License.txt for the license details. // More info on: http://dotnetzip.codeplex.com // // ------------------------------------------------------------------ // -// last saved (in emacs): +// last saved (in emacs): // Time-stamp: <2009-October-28 13:29:50> // // ------------------------------------------------------------------ @@ -27,22 +27,22 @@ // code is below. // // ------------------------------------------------------------------ -// +// // Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the distribution. -// +// // 3. The names of the authors may not be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, @@ -53,7 +53,7 @@ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // ----------------------------------------------------------------------- // // This program is based on zlib-1.1.3; credit to authors @@ -77,9 +77,25 @@ namespace SharpCompress.Compressors.Deflate internal static readonly sbyte[] bl_order = { - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, + 16, + 17, + 18, + 0, + 8, + 7, + 9, + 6, + 10, + 5, + 11, + 4, + 12, + 3, + 13, + 2, 14, - 1, 15 + 1, + 15 }; // The lengths of the bit length codes are sent in order of decreasing @@ -91,117 +107,845 @@ namespace SharpCompress.Compressors.Deflate private static readonly sbyte[] _dist_code = { - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, - 0, 0, 16, 17, 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, - 21, 21, - 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, - 23, 23, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, - 24, 24, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, - 27, 27, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, - 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, - 28, 28, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29 + 0, + 1, + 2, + 3, + 4, + 4, + 5, + 5, + 6, + 6, + 6, + 6, + 7, + 7, + 7, + 7, + 8, + 8, + 8, + 8, + 8, + 8, + 8, + 8, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 10, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 11, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 12, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 13, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 15, + 0, + 0, + 16, + 17, + 18, + 18, + 19, + 19, + 20, + 20, + 20, + 20, + 21, + 21, + 21, + 21, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 28, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29, + 29 }; internal static readonly sbyte[] LengthCode = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, 15 - , 15, 15, - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17 - , 17, 17, - 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19 - , 19, 19, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 - , 20, 20, - 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21 - , 21, 21, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22 - , 22, 22, - 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23 - , 23, 23, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 - , 24, 24, - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 - , 24, 24, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25 - , 25, 25, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25 - , 25, 25, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26 - , 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26 - , 26, 26, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27 - , 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27 - , 27, 28 + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 8, + 9, + 9, + 10, + 10, + 11, + 11, + 12, + 12, + 12, + 12, + 13, + 13, + 13, + 13, + 14, + 14, + 14, + 14, + 15, + 15, + 15, + 15, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 17, + 17, + 17, + 17, + 17, + 17, + 17, + 17, + 18, + 18, + 18, + 18, + 18, + 18, + 18, + 18, + 19, + 19, + 19, + 19, + 19, + 19, + 19, + 19, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 20, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 21, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 25, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 26, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 27, + 28 }; internal static readonly int[] LengthBase = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, - 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0 + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 10, + 12, + 14, + 16, + 20, + 24, + 28, + 32, + 40, + 48, + 56, + 64, + 80, + 96, + 112, + 128, + 160, + 192, + 224, + 0 }; internal static readonly int[] DistanceBase = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, + 0, + 1, + 2, + 3, + 4, + 6, + 8, + 12, + 16, + 24, + 32, + 48, + 64, + 96, + 128, 192, - 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144 - , 8192, 12288, 16384, 24576 + 256, + 384, + 512, + 768, + 1024, + 1536, + 2048, + 3072, + 4096, + 6144, + 8192, + 12288, + 16384, + 24576 }; internal short[] dyn_tree; // the dynamic tree @@ -211,14 +955,14 @@ namespace SharpCompress.Compressors.Deflate /// /// Map from a distance to a distance code. /// - /// + /// /// No side effects. _dist_code[256] and _dist_code[257] are never used. /// internal static int DistanceCode(int dist) { return (dist < 256) - ? _dist_code[dist] - : _dist_code[256 + SharedUtils.URShift(dist, 7)]; + ? _dist_code[dist] + : _dist_code[256 + SharedUtils.URShift(dist, 7)]; } // Compute the optimal bit lengths for a tree and update the total bit length @@ -237,7 +981,8 @@ namespace SharpCompress.Compressors.Deflate int base_Renamed = staticTree.extraBase; int max_length = staticTree.maxLength; int h; // heap index - int n, m; // iterate over the tree elements + int n, + m; // iterate over the tree elements int bits; // bit length int xbits; // extra bits short f; // frequency @@ -304,8 +1049,7 @@ namespace SharpCompress.Compressors.Deflate // The brother of the overflow item also moves one step up, // but this does not affect bl_count[max_length] overflow -= 2; - } - while (overflow > 0); + } while (overflow > 0); for (bits = max_length; bits != 0; bits--) { @@ -319,7 +1063,9 @@ namespace SharpCompress.Compressors.Deflate } if (tree[m * 2 + 1] != bits) { - s.opt_len = (int)(s.opt_len + (bits - (long)tree[m * 2 + 1]) * tree[m * 2]); + s.opt_len = (int)( + s.opt_len + (bits - (long)tree[m * 2 + 1]) * tree[m * 2] + ); tree[m * 2 + 1] = (short)bits; } n--; @@ -338,7 +1084,8 @@ namespace SharpCompress.Compressors.Deflate short[] tree = dyn_tree; short[] stree = staticTree.treeCodes; int elems = staticTree.elems; - int n, m; // iterate over heap elements + int n, + m; // iterate over heap elements int max_code = -1; // largest code with non zero frequency int node; // new node being created @@ -411,8 +1158,7 @@ namespace SharpCompress.Compressors.Deflate // and insert the new node in the heap s.heap[1] = node++; s.pqdownheap(tree, 1); - } - while (s.heap_len >= 2); + } while (s.heap_len >= 2); s.heap[--s.heap_max] = s.heap[1]; @@ -478,12 +1224,11 @@ namespace SharpCompress.Compressors.Deflate res |= code & 1; code >>= 1; //SharedUtils.URShift(code, 1); res <<= 1; - } - while (--len > 0); + } while (--len > 0); return res >> 1; } } #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/Zlib.cs b/src/SharpCompress/Compressors/Deflate/Zlib.cs index 036d65f5..b8cab22c 100644 --- a/src/SharpCompress/Compressors/Deflate/Zlib.cs +++ b/src/SharpCompress/Compressors/Deflate/Zlib.cs @@ -183,18 +183,13 @@ namespace SharpCompress.Compressors.Deflate /// The ZlibException class captures exception information generated /// by the Zlib library. /// - public ZlibException() - { - } + public ZlibException() { } /// /// This ctor collects a message attached to the exception. /// /// - public ZlibException(String s) - : base(s) - { - } + public ZlibException(String s) : base(s) { } } internal class SharedUtils @@ -212,15 +207,15 @@ namespace SharpCompress.Compressors.Deflate #if NOT -/// -/// Performs an unsigned bitwise right shift with the specified number -/// -/// Number to operate on -/// Ammount of bits to shift -/// The resulting number from the shift operation + /// + /// Performs an unsigned bitwise right shift with the specified number + /// + /// Number to operate on + /// Ammount of bits to shift + /// The resulting number from the shift operation public static long URShift(long number, int bits) { - return (long) ((UInt64)number >> bits); + return (long)((UInt64)number >> bits); } #endif @@ -239,7 +234,12 @@ namespace SharpCompress.Compressors.Deflate /// count depending on the data available in the source TextReader. Returns -1 /// if the end of the stream is reached. /// - public static Int32 ReadInput(TextReader sourceTextReader, byte[] target, int start, int count) + public static Int32 ReadInput( + TextReader sourceTextReader, + byte[] target, + int start, + int count + ) { // Returns 0 bytes if not enough space in target if (target.Length == 0) @@ -291,90 +291,671 @@ namespace SharpCompress.Compressors.Deflate { internal static readonly short[] lengthAndLiteralsTreeCodes = { - 12, 8, 140, 8, 76, 8, 204, 8, 44, 8, 172, - 8, 108, 8, 236, 8, - 28, 8, 156, 8, 92, 8, 220, 8, 60, 8, 188, - 8, 124, 8, 252, 8, - 2, 8, 130, 8, 66, 8, 194, 8, 34, 8, 162, 8 - , 98, 8, 226, 8, - 18, 8, 146, 8, 82, 8, 210, 8, 50, 8, 178, - 8, 114, 8, 242, 8, - 10, 8, 138, 8, 74, 8, 202, 8, 42, 8, 170, - 8, 106, 8, 234, 8, - 26, 8, 154, 8, 90, 8, 218, 8, 58, 8, 186, - 8, 122, 8, 250, 8, - 6, 8, 134, 8, 70, 8, 198, 8, 38, 8, 166, 8 - , 102, 8, 230, 8, - 22, 8, 150, 8, 86, 8, 214, 8, 54, 8, 182, - 8, 118, 8, 246, 8, - 14, 8, 142, 8, 78, 8, 206, 8, 46, 8, 174, - 8, 110, 8, 238, 8, - 30, 8, 158, 8, 94, 8, 222, 8, 62, 8, 190, - 8, 126, 8, 254, 8, - 1, 8, 129, 8, 65, 8, 193, 8, 33, 8, 161, 8 - , 97, 8, 225, 8, - 17, 8, 145, 8, 81, 8, 209, 8, 49, 8, 177, - 8, 113, 8, 241, 8, - 9, 8, 137, 8, 73, 8, 201, 8, 41, 8, 169, 8 - , 105, 8, 233, 8, - 25, 8, 153, 8, 89, 8, 217, 8, 57, 8, 185, - 8, 121, 8, 249, 8, - 5, 8, 133, 8, 69, 8, 197, 8, 37, 8, 165, 8 - , 101, 8, 229, 8, - 21, 8, 149, 8, 85, 8, 213, 8, 53, 8, 181, - 8, 117, 8, 245, 8, - 13, 8, 141, 8, 77, 8, 205, 8, 45, 8, 173, - 8, 109, 8, 237, 8, - 29, 8, 157, 8, 93, 8, 221, 8, 61, 8, 189, - 8, 125, 8, 253, 8, - 19, 9, 275, 9, 147, 9, 403, 9, 83, 9, 339, - 9, 211, 9, 467, 9, - 51, 9, 307, 9, 179, 9, 435, 9, 115, 9, 371 - , 9, 243, 9, 499, 9, - 11, 9, 267, 9, 139, 9, 395, 9, 75, 9, 331, - 9, 203, 9, 459, 9, - 43, 9, 299, 9, 171, 9, 427, 9, 107, 9, 363 - , 9, 235, 9, 491, 9, - 27, 9, 283, 9, 155, 9, 411, 9, 91, 9, 347, - 9, 219, 9, 475, 9, - 59, 9, 315, 9, 187, 9, 443, 9, 123, 9, 379 - , 9, 251, 9, 507, 9, - 7, 9, 263, 9, 135, 9, 391, 9, 71, 9, 327, - 9, 199, 9, 455, 9, - 39, 9, 295, 9, 167, 9, 423, 9, 103, 9, 359 - , 9, 231, 9, 487, 9, - 23, 9, 279, 9, 151, 9, 407, 9, 87, 9, 343, - 9, 215, 9, 471, 9, - 55, 9, 311, 9, 183, 9, 439, 9, 119, 9, 375 - , 9, 247, 9, 503, 9, - 15, 9, 271, 9, 143, 9, 399, 9, 79, 9, 335, - 9, 207, 9, 463, 9, - 47, 9, 303, 9, 175, 9, 431, 9, 111, 9, 367 - , 9, 239, 9, 495, 9, - 31, 9, 287, 9, 159, 9, 415, 9, 95, 9, 351, - 9, 223, 9, 479, 9, - 63, 9, 319, 9, 191, 9, 447, 9, 127, 9, 383 - , 9, 255, 9, 511, 9, - 0, 7, 64, 7, 32, 7, 96, 7, 16, 7, 80, 7, - 48, 7, 112, 7, - 8, 7, 72, 7, 40, 7, 104, 7, 24, 7, 88, 7, - 56, 7, 120, 7, - 4, 7, 68, 7, 36, 7, 100, 7, 20, 7, 84, 7, - 52, 7, 116, 7, - 3, 8, 131, 8, 67, 8, 195, 8, 35, 8, 163, 8 - , 99, 8, 227, 8 + 12, + 8, + 140, + 8, + 76, + 8, + 204, + 8, + 44, + 8, + 172, + 8, + 108, + 8, + 236, + 8, + 28, + 8, + 156, + 8, + 92, + 8, + 220, + 8, + 60, + 8, + 188, + 8, + 124, + 8, + 252, + 8, + 2, + 8, + 130, + 8, + 66, + 8, + 194, + 8, + 34, + 8, + 162, + 8, + 98, + 8, + 226, + 8, + 18, + 8, + 146, + 8, + 82, + 8, + 210, + 8, + 50, + 8, + 178, + 8, + 114, + 8, + 242, + 8, + 10, + 8, + 138, + 8, + 74, + 8, + 202, + 8, + 42, + 8, + 170, + 8, + 106, + 8, + 234, + 8, + 26, + 8, + 154, + 8, + 90, + 8, + 218, + 8, + 58, + 8, + 186, + 8, + 122, + 8, + 250, + 8, + 6, + 8, + 134, + 8, + 70, + 8, + 198, + 8, + 38, + 8, + 166, + 8, + 102, + 8, + 230, + 8, + 22, + 8, + 150, + 8, + 86, + 8, + 214, + 8, + 54, + 8, + 182, + 8, + 118, + 8, + 246, + 8, + 14, + 8, + 142, + 8, + 78, + 8, + 206, + 8, + 46, + 8, + 174, + 8, + 110, + 8, + 238, + 8, + 30, + 8, + 158, + 8, + 94, + 8, + 222, + 8, + 62, + 8, + 190, + 8, + 126, + 8, + 254, + 8, + 1, + 8, + 129, + 8, + 65, + 8, + 193, + 8, + 33, + 8, + 161, + 8, + 97, + 8, + 225, + 8, + 17, + 8, + 145, + 8, + 81, + 8, + 209, + 8, + 49, + 8, + 177, + 8, + 113, + 8, + 241, + 8, + 9, + 8, + 137, + 8, + 73, + 8, + 201, + 8, + 41, + 8, + 169, + 8, + 105, + 8, + 233, + 8, + 25, + 8, + 153, + 8, + 89, + 8, + 217, + 8, + 57, + 8, + 185, + 8, + 121, + 8, + 249, + 8, + 5, + 8, + 133, + 8, + 69, + 8, + 197, + 8, + 37, + 8, + 165, + 8, + 101, + 8, + 229, + 8, + 21, + 8, + 149, + 8, + 85, + 8, + 213, + 8, + 53, + 8, + 181, + 8, + 117, + 8, + 245, + 8, + 13, + 8, + 141, + 8, + 77, + 8, + 205, + 8, + 45, + 8, + 173, + 8, + 109, + 8, + 237, + 8, + 29, + 8, + 157, + 8, + 93, + 8, + 221, + 8, + 61, + 8, + 189, + 8, + 125, + 8, + 253, + 8, + 19, + 9, + 275, + 9, + 147, + 9, + 403, + 9, + 83, + 9, + 339, + 9, + 211, + 9, + 467, + 9, + 51, + 9, + 307, + 9, + 179, + 9, + 435, + 9, + 115, + 9, + 371, + 9, + 243, + 9, + 499, + 9, + 11, + 9, + 267, + 9, + 139, + 9, + 395, + 9, + 75, + 9, + 331, + 9, + 203, + 9, + 459, + 9, + 43, + 9, + 299, + 9, + 171, + 9, + 427, + 9, + 107, + 9, + 363, + 9, + 235, + 9, + 491, + 9, + 27, + 9, + 283, + 9, + 155, + 9, + 411, + 9, + 91, + 9, + 347, + 9, + 219, + 9, + 475, + 9, + 59, + 9, + 315, + 9, + 187, + 9, + 443, + 9, + 123, + 9, + 379, + 9, + 251, + 9, + 507, + 9, + 7, + 9, + 263, + 9, + 135, + 9, + 391, + 9, + 71, + 9, + 327, + 9, + 199, + 9, + 455, + 9, + 39, + 9, + 295, + 9, + 167, + 9, + 423, + 9, + 103, + 9, + 359, + 9, + 231, + 9, + 487, + 9, + 23, + 9, + 279, + 9, + 151, + 9, + 407, + 9, + 87, + 9, + 343, + 9, + 215, + 9, + 471, + 9, + 55, + 9, + 311, + 9, + 183, + 9, + 439, + 9, + 119, + 9, + 375, + 9, + 247, + 9, + 503, + 9, + 15, + 9, + 271, + 9, + 143, + 9, + 399, + 9, + 79, + 9, + 335, + 9, + 207, + 9, + 463, + 9, + 47, + 9, + 303, + 9, + 175, + 9, + 431, + 9, + 111, + 9, + 367, + 9, + 239, + 9, + 495, + 9, + 31, + 9, + 287, + 9, + 159, + 9, + 415, + 9, + 95, + 9, + 351, + 9, + 223, + 9, + 479, + 9, + 63, + 9, + 319, + 9, + 191, + 9, + 447, + 9, + 127, + 9, + 383, + 9, + 255, + 9, + 511, + 9, + 0, + 7, + 64, + 7, + 32, + 7, + 96, + 7, + 16, + 7, + 80, + 7, + 48, + 7, + 112, + 7, + 8, + 7, + 72, + 7, + 40, + 7, + 104, + 7, + 24, + 7, + 88, + 7, + 56, + 7, + 120, + 7, + 4, + 7, + 68, + 7, + 36, + 7, + 100, + 7, + 20, + 7, + 84, + 7, + 52, + 7, + 116, + 7, + 3, + 8, + 131, + 8, + 67, + 8, + 195, + 8, + 35, + 8, + 163, + 8, + 99, + 8, + 227, + 8 }; internal static readonly short[] distTreeCodes = { - 0, 5, 16, 5, 8, 5, 24, 5, 4, 5, 20, 5, 12, 5, 28, 5, - 2, 5, 18, 5, 10, 5, 26, 5, 6, 5, 22, 5, 14, 5, 30, 5, - 1, 5, 17, 5, 9, 5, 25, 5, 5, 5, 21, 5, 13, 5, 29, 5, - 3, 5, 19, 5, 11, 5, 27, 5, 7, 5, 23, 5 + 0, + 5, + 16, + 5, + 8, + 5, + 24, + 5, + 4, + 5, + 20, + 5, + 12, + 5, + 28, + 5, + 2, + 5, + 18, + 5, + 10, + 5, + 26, + 5, + 6, + 5, + 22, + 5, + 14, + 5, + 30, + 5, + 1, + 5, + 17, + 5, + 9, + 5, + 25, + 5, + 5, + 5, + 21, + 5, + 13, + 5, + 29, + 5, + 3, + 5, + 19, + 5, + 11, + 5, + 27, + 5, + 7, + 5, + 23, + 5 }; // extra bits for each bit length code - internal static readonly int[] extra_blbits = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; + internal static readonly int[] extra_blbits = + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 3, + 7 + }; internal static readonly StaticTree Literals; internal static readonly StaticTree Distances; @@ -386,7 +967,13 @@ namespace SharpCompress.Compressors.Deflate internal int elems; // max number of elements in the tree internal int maxLength; // max bit length for the codes - private StaticTree(short[]? treeCodes, int[]? extraBits, int extraBase, int elems, int maxLength) + private StaticTree( + short[]? treeCodes, + int[]? extraBits, + int extraBase, + int elems, + int maxLength + ) { this.treeCodes = treeCodes; this.extraBits = extraBits; @@ -397,12 +984,27 @@ namespace SharpCompress.Compressors.Deflate static StaticTree() { - Literals = new StaticTree(lengthAndLiteralsTreeCodes, DeflateManager.ExtraLengthBits, - InternalConstants.LITERALS + 1, InternalConstants.L_CODES, - InternalConstants.MAX_BITS); - Distances = new StaticTree(distTreeCodes, DeflateManager.ExtraDistanceBits, 0, InternalConstants.D_CODES, - InternalConstants.MAX_BITS); - BitLengths = new StaticTree(null, extra_blbits, 0, InternalConstants.BL_CODES, InternalConstants.MAX_BL_BITS); + Literals = new StaticTree( + lengthAndLiteralsTreeCodes, + DeflateManager.ExtraLengthBits, + InternalConstants.LITERALS + 1, + InternalConstants.L_CODES, + InternalConstants.MAX_BITS + ); + Distances = new StaticTree( + distTreeCodes, + DeflateManager.ExtraDistanceBits, + 0, + InternalConstants.D_CODES, + InternalConstants.MAX_BITS + ); + BitLengths = new StaticTree( + null, + extra_blbits, + 0, + InternalConstants.BL_CODES, + InternalConstants.MAX_BL_BITS + ); } } } diff --git a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs index 45d5dfac..a3a5eae5 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibBaseStream.cs @@ -69,11 +69,13 @@ namespace SharpCompress.Compressors.Deflate internal int Crc32 => crc?.Crc32Result ?? 0; - public ZlibBaseStream(Stream stream, - CompressionMode compressionMode, - CompressionLevel level, - ZlibStreamFlavor flavor, - Encoding encoding) + public ZlibBaseStream( + Stream stream, + CompressionMode compressionMode, + CompressionLevel level, + ZlibStreamFlavor flavor, + Encoding encoding + ) { _flushMode = FlushType.None; @@ -154,12 +156,12 @@ namespace SharpCompress.Compressors.Deflate _z.OutputBuffer = workingBuffer; _z.NextOut = 0; _z.AvailableBytesOut = _workingBuffer.Length; - int rc = (_wantCompress) - ? _z.Deflate(_flushMode) - : _z.Inflate(_flushMode); + int rc = (_wantCompress) ? _z.Deflate(_flushMode) : _z.Inflate(_flushMode); if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) { - throw new ZlibException((_wantCompress ? "de" : "in") + "flating: " + _z.Message); + throw new ZlibException( + (_wantCompress ? "de" : "in") + "flating: " + _z.Message + ); } //if (_workingBuffer.Length - _z.AvailableBytesOut > 0) @@ -172,8 +174,7 @@ namespace SharpCompress.Compressors.Deflate { done = (_z.AvailableBytesIn == 8 && _z.AvailableBytesOut != 0); } - } - while (!done); + } while (!done); } private void finish() @@ -191,9 +192,10 @@ namespace SharpCompress.Compressors.Deflate _z.OutputBuffer = workingBuffer; _z.NextOut = 0; _z.AvailableBytesOut = _workingBuffer.Length; - int rc = (_wantCompress) - ? _z.Deflate(FlushType.Finish) - : _z.Inflate(FlushType.Finish); + int rc = + (_wantCompress) + ? _z.Deflate(FlushType.Finish) + : _z.Inflate(FlushType.Finish); if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK) { @@ -207,7 +209,11 @@ namespace SharpCompress.Compressors.Deflate if (_workingBuffer.Length - _z.AvailableBytesOut > 0) { - _stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut); + _stream.Write( + _workingBuffer, + 0, + _workingBuffer.Length - _z.AvailableBytesOut + ); } done = _z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0; @@ -217,8 +223,7 @@ namespace SharpCompress.Compressors.Deflate { done = (_z.AvailableBytesIn == 8 && _z.AvailableBytesOut != 0); } - } - while (!done); + } while (!done); Flush(); @@ -241,7 +246,6 @@ namespace SharpCompress.Compressors.Deflate } } } - // workitem 7159 else if (_streamMode == StreamMode.Reader) { @@ -264,12 +268,17 @@ namespace SharpCompress.Compressors.Deflate // Make sure we have read to the end of the stream _z.InputBuffer.AsSpan(_z.NextIn, _z.AvailableBytesIn).CopyTo(trailer); int bytesNeeded = 8 - _z.AvailableBytesIn; - int bytesRead = _stream.Read(trailer.Slice(_z.AvailableBytesIn, bytesNeeded)); + int bytesRead = _stream.Read( + trailer.Slice(_z.AvailableBytesIn, bytesNeeded) + ); if (bytesNeeded != bytesRead) { - throw new ZlibException(String.Format( - "Protocol error. AvailableBytesIn={0}, expected 8", - _z.AvailableBytesIn + bytesRead)); + throw new ZlibException( + String.Format( + "Protocol error. AvailableBytesIn={0}, expected 8", + _z.AvailableBytesIn + bytesRead + ) + ); } } else @@ -279,21 +288,31 @@ namespace SharpCompress.Compressors.Deflate Int32 crc32_expected = BinaryPrimitives.ReadInt32LittleEndian(trailer); Int32 crc32_actual = crc.Crc32Result; - Int32 isize_expected = BinaryPrimitives.ReadInt32LittleEndian(trailer.Slice(4)); + Int32 isize_expected = BinaryPrimitives.ReadInt32LittleEndian( + trailer.Slice(4) + ); Int32 isize_actual = (Int32)(_z.TotalBytesOut & 0x00000000FFFFFFFF); if (crc32_actual != crc32_expected) { throw new ZlibException( - String.Format("Bad CRC32 in GZIP stream. (actual({0:X8})!=expected({1:X8}))", - crc32_actual, crc32_expected)); + String.Format( + "Bad CRC32 in GZIP stream. (actual({0:X8})!=expected({1:X8}))", + crc32_actual, + crc32_expected + ) + ); } if (isize_actual != isize_expected) { throw new ZlibException( - String.Format("Bad size in GZIP stream. (actual({0})!=expected({1}))", isize_actual, - isize_expected)); + String.Format( + "Bad size in GZIP stream. (actual({0})!=expected({1}))", + isize_actual, + isize_expected + ) + ); } } else @@ -371,8 +390,8 @@ namespace SharpCompress.Compressors.Deflate if (Read(_buf1, 0, 1) == 0) return 0; // calculate CRC after reading - if (crc!=null) - crc.SlurpBlock(_buf1,0,1); + if (crc != null) + crc.SlurpBlock(_buf1, 0, 1); return (_buf1[0] & 0xFF); } #endif @@ -400,8 +419,7 @@ namespace SharpCompress.Compressors.Deflate { list.Add(_buf1[0]); } - } - while (!done); + } while (!done); byte[] buffer = list.ToArray(); return _encoding.GetString(buffer, 0, buffer.Length); } @@ -521,7 +539,9 @@ namespace SharpCompress.Compressors.Deflate if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) { - throw new ZlibException(String.Format("Deflating: rc={0} msg={1}", rc, _z.Message)); + throw new ZlibException( + String.Format("Deflating: rc={0} msg={1}", rc, _z.Message) + ); } rc = (count - _z.AvailableBytesOut); @@ -571,9 +591,7 @@ namespace SharpCompress.Compressors.Deflate } // we have data in InputBuffer; now compress or decompress as appropriate - rc = (_wantCompress) - ? _z.Deflate(_flushMode) - : _z.Inflate(_flushMode); + rc = (_wantCompress) ? _z.Deflate(_flushMode) : _z.Inflate(_flushMode); if (nomoreinput && (rc == ZlibConstants.Z_BUF_ERROR)) { @@ -582,11 +600,20 @@ namespace SharpCompress.Compressors.Deflate if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) { - throw new ZlibException(String.Format("{0}flating: rc={1} msg={2}", (_wantCompress ? "de" : "in"), - rc, _z.Message)); + throw new ZlibException( + String.Format( + "{0}flating: rc={1} msg={2}", + (_wantCompress ? "de" : "in"), + rc, + _z.Message + ) + ); } - if ((nomoreinput || rc == ZlibConstants.Z_STREAM_END) && (_z.AvailableBytesOut == count)) + if ( + (nomoreinput || rc == ZlibConstants.Z_STREAM_END) + && (_z.AvailableBytesOut == count) + ) { break; // nothing more to read } @@ -614,7 +641,9 @@ namespace SharpCompress.Compressors.Deflate if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) { - throw new ZlibException(String.Format("Deflating: rc={0} msg={1}", rc, _z.Message)); + throw new ZlibException( + String.Format("Deflating: rc={0} msg={1}", rc, _z.Message) + ); } } } @@ -639,7 +668,11 @@ namespace SharpCompress.Compressors.Deflate public override Int64 Length => _stream.Length; - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } internal enum StreamMode { diff --git a/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs b/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs index 8b995018..4c8e0b78 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibCodec.cs @@ -3,20 +3,20 @@ // ZlibCodec.cs // ------------------------------------------------------------------ // -// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. +// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. // All rights reserved. // // This code module is part of DotNetZip, a zipfile class library. // // ------------------------------------------------------------------ // -// This code is licensed under the Microsoft Public License. +// This code is licensed under the Microsoft Public License. // See the file License.txt for the license details. // More info on: http://dotnetzip.codeplex.com // // ------------------------------------------------------------------ // -// last saved (in emacs): +// last saved (in emacs): // Time-stamp: <2009-November-03 15:40:51> // // ------------------------------------------------------------------ @@ -30,22 +30,22 @@ // is included below. // // ------------------------------------------------------------------ -// +// // Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the distribution. -// +// // 3. The names of the authors may not be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, @@ -56,7 +56,7 @@ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // ----------------------------------------------------------------------- // // This program is based on zlib-1.1.3; credit to authors @@ -87,15 +87,15 @@ namespace SharpCompress.Compressors.Deflate public byte[] InputBuffer; /// - /// An index into the InputBuffer array, indicating where to start reading. + /// An index into the InputBuffer array, indicating where to start reading. /// public int NextIn; /// - /// The number of bytes available in the InputBuffer, starting at NextIn. + /// The number of bytes available in the InputBuffer, starting at NextIn. /// /// - /// Generally you should set this to InputBuffer.Length before the first Inflate() or Deflate() call. + /// Generally you should set this to InputBuffer.Length before the first Inflate() or Deflate() call. /// The class will update this number as calls to Inflate/Deflate are made. /// public int AvailableBytesIn; @@ -111,15 +111,15 @@ namespace SharpCompress.Compressors.Deflate public byte[] OutputBuffer; /// - /// An index into the OutputBuffer array, indicating where to start writing. + /// An index into the OutputBuffer array, indicating where to start writing. /// public int NextOut; /// - /// The number of bytes available in the OutputBuffer, starting at NextOut. + /// The number of bytes available in the OutputBuffer, starting at NextOut. /// /// - /// Generally you should set this to OutputBuffer.Length before the first Inflate() or Deflate() call. + /// Generally you should set this to OutputBuffer.Length before the first Inflate() or Deflate() call. /// The class will update this number as calls to Inflate/Deflate are made. /// public int AvailableBytesOut; @@ -145,13 +145,13 @@ namespace SharpCompress.Compressors.Deflate public CompressionLevel CompressLevel = CompressionLevel.Default; /// - /// The number of Window Bits to use. + /// The number of Window Bits to use. /// /// - /// This gauges the size of the sliding window, and hence the - /// compression effectiveness as well as memory consumption. It's best to just leave this + /// This gauges the size of the sliding window, and hence the + /// compression effectiveness as well as memory consumption. It's best to just leave this /// setting alone if you don't know what it is. The maximum value is 15 bits, which implies - /// a 32k window. + /// a 32k window. /// public int WindowBits = ZlibConstants.WindowBitsDefault; @@ -179,13 +179,11 @@ namespace SharpCompress.Compressors.Deflate /// Create a ZlibCodec. /// /// - /// If you use this default constructor, you will later have to explicitly call - /// InitializeInflate() or InitializeDeflate() before using the ZlibCodec to compress - /// or decompress. + /// If you use this default constructor, you will later have to explicitly call + /// InitializeInflate() or InitializeDeflate() before using the ZlibCodec to compress + /// or decompress. /// - public ZlibCodec() - { - } + public ZlibCodec() { } /// /// Create a ZlibCodec that either compresses or decompresses. @@ -218,10 +216,10 @@ namespace SharpCompress.Compressors.Deflate } /// - /// Initialize the inflation state. + /// Initialize the inflation state. /// /// - /// It is not necessary to call this before using the ZlibCodec to inflate data; + /// It is not necessary to call this before using the ZlibCodec to inflate data; /// It is implicitly called when you call the constructor. /// /// Z_OK if everything goes well. @@ -254,9 +252,9 @@ namespace SharpCompress.Compressors.Deflate } /// - /// Initialize the ZlibCodec for inflation, with the specified number of window bits. + /// Initialize the ZlibCodec for inflation, with the specified number of window bits. /// - /// The number of window bits to use. If you need to ask what that is, + /// The number of window bits to use. If you need to ask what that is, /// then you shouldn't be calling this initializer. /// Z_OK if all goes well. public int InitializeInflate(int windowBits) @@ -267,7 +265,7 @@ namespace SharpCompress.Compressors.Deflate /// /// Initialize the inflation state with an explicit flag to govern the handling of - /// RFC1950 header bytes. + /// RFC1950 header bytes. /// /// /// @@ -279,9 +277,9 @@ namespace SharpCompress.Compressors.Deflate /// false. /// /// - /// whether to expect an RFC1950 header byte pair when reading + /// whether to expect an RFC1950 header byte pair when reading /// the stream of data to be inflated. - /// The number of window bits to use. If you need to ask what that is, + /// The number of window bits to use. If you need to ask what that is, /// then you shouldn't be calling this initializer. /// Z_OK if everything goes well. public int InitializeInflate(int windowBits, bool expectRfc1950Header) @@ -289,7 +287,9 @@ namespace SharpCompress.Compressors.Deflate WindowBits = windowBits; if (dstate != null) { - throw new ZlibException("You may not call InitializeInflate() after calling InitializeDeflate()."); + throw new ZlibException( + "You may not call InitializeInflate() after calling InitializeDeflate()." + ); } istate = new InflateManager(expectRfc1950Header); return istate.Initialize(this, windowBits); @@ -299,7 +299,7 @@ namespace SharpCompress.Compressors.Deflate /// Inflate the data in the InputBuffer, placing the result in the OutputBuffer. /// /// - /// You must have set InputBuffer and OutputBuffer, NextIn and NextOut, and AvailableBytesIn and + /// You must have set InputBuffer and OutputBuffer, NextIn and NextOut, and AvailableBytesIn and /// AvailableBytesOut before calling this method. /// /// @@ -309,48 +309,48 @@ namespace SharpCompress.Compressors.Deflate /// int bufferSize = 1024; /// byte[] buffer = new byte[bufferSize]; /// ZlibCodec decompressor = new ZlibCodec(); - /// + /// /// Console.WriteLine("\n============================================"); /// Console.WriteLine("Size of Buffer to Inflate: {0} bytes.", CompressedBytes.Length); /// MemoryStream ms = new MemoryStream(DecompressedBytes); - /// + /// /// int rc = decompressor.InitializeInflate(); - /// + /// /// decompressor.InputBuffer = CompressedBytes; /// decompressor.NextIn = 0; /// decompressor.AvailableBytesIn = CompressedBytes.Length; - /// + /// /// decompressor.OutputBuffer = buffer; - /// - /// // pass 1: inflate + /// + /// // pass 1: inflate /// do /// { /// decompressor.NextOut = 0; /// decompressor.AvailableBytesOut = buffer.Length; /// rc = decompressor.Inflate(FlushType.None); - /// + /// /// if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) /// throw new Exception("inflating: " + decompressor.Message); - /// + /// /// ms.Write(decompressor.OutputBuffer, 0, buffer.Length - decompressor.AvailableBytesOut); /// } /// while (decompressor.AvailableBytesIn > 0 || decompressor.AvailableBytesOut == 0); - /// + /// /// // pass 2: finish and flush /// do /// { /// decompressor.NextOut = 0; /// decompressor.AvailableBytesOut = buffer.Length; /// rc = decompressor.Inflate(FlushType.Finish); - /// + /// /// if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK) /// throw new Exception("inflating: " + decompressor.Message); - /// + /// /// if (buffer.Length - decompressor.AvailableBytesOut > 0) /// ms.Write(buffer, 0, buffer.Length - decompressor.AvailableBytesOut); /// } /// while (decompressor.AvailableBytesIn > 0 || decompressor.AvailableBytesOut == 0); - /// + /// /// decompressor.EndInflate(); /// } /// @@ -368,10 +368,10 @@ namespace SharpCompress.Compressors.Deflate } /// - /// Ends an inflation session. + /// Ends an inflation session. /// /// - /// Call this after successively calling Inflate(). This will cause all buffers to be flushed. + /// Call this after successively calling Inflate(). This will cause all buffers to be flushed. /// After calling this you cannot call Inflate() without a intervening call to one of the /// InitializeInflate() overloads. /// @@ -411,32 +411,32 @@ namespace SharpCompress.Compressors.Deflate /// int bufferSize = 40000; /// byte[] CompressedBytes = new byte[bufferSize]; /// byte[] DecompressedBytes = new byte[bufferSize]; - /// + /// /// ZlibCodec compressor = new ZlibCodec(); - /// + /// /// compressor.InitializeDeflate(CompressionLevel.Default); - /// + /// /// compressor.InputBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(TextToCompress); /// compressor.NextIn = 0; /// compressor.AvailableBytesIn = compressor.InputBuffer.Length; - /// + /// /// compressor.OutputBuffer = CompressedBytes; /// compressor.NextOut = 0; /// compressor.AvailableBytesOut = CompressedBytes.Length; - /// + /// /// while (compressor.TotalBytesIn != TextToCompress.Length && compressor.TotalBytesOut < bufferSize) /// { /// compressor.Deflate(FlushType.None); /// } - /// + /// /// while (true) /// { /// int rc= compressor.Deflate(FlushType.Finish); /// if (rc == ZlibConstants.Z_STREAM_END) break; /// } - /// + /// /// compressor.EndDeflate(); - /// + /// /// /// /// Z_OK if all goes well. You generally don't need to check the return code. @@ -461,7 +461,7 @@ namespace SharpCompress.Compressors.Deflate } /// - /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, + /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, /// and the explicit flag governing whether to emit an RFC1950 header byte pair. /// /// @@ -469,7 +469,7 @@ namespace SharpCompress.Compressors.Deflate /// If you want to generate a zlib stream, you should specify true for /// wantRfc1950Header. In this case, the library will emit a ZLIB /// header, as defined in RFC - /// 1950, in the compressed stream. + /// 1950, in the compressed stream. /// /// The compression level for the codec. /// whether to emit an initial RFC1950 byte pair in the compressed stream. @@ -481,8 +481,8 @@ namespace SharpCompress.Compressors.Deflate } /// - /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, - /// and the specified number of window bits. + /// Initialize the ZlibCodec for deflation operation, using the specified CompressionLevel, + /// and the specified number of window bits. /// /// /// The codec will use the specified number of window bits and the specified CompressionLevel. @@ -518,7 +518,9 @@ namespace SharpCompress.Compressors.Deflate { if (istate != null) { - throw new ZlibException("You may not call InitializeDeflate() after calling InitializeInflate()."); + throw new ZlibException( + "You may not call InitializeDeflate() after calling InitializeInflate()." + ); } dstate = new DeflateManager(); dstate.WantRfc1950HeaderBytes = wantRfc1950Header; @@ -539,59 +541,59 @@ namespace SharpCompress.Compressors.Deflate /// int bufferSize = 1024; /// byte[] buffer = new byte[bufferSize]; /// ZlibCodec compressor = new ZlibCodec(); - /// + /// /// Console.WriteLine("\n============================================"); /// Console.WriteLine("Size of Buffer to Deflate: {0} bytes.", UncompressedBytes.Length); /// MemoryStream ms = new MemoryStream(); - /// + /// /// int rc = compressor.InitializeDeflate(level); - /// + /// /// compressor.InputBuffer = UncompressedBytes; /// compressor.NextIn = 0; /// compressor.AvailableBytesIn = UncompressedBytes.Length; - /// + /// /// compressor.OutputBuffer = buffer; - /// - /// // pass 1: deflate + /// + /// // pass 1: deflate /// do /// { /// compressor.NextOut = 0; /// compressor.AvailableBytesOut = buffer.Length; /// rc = compressor.Deflate(FlushType.None); - /// + /// /// if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END) /// throw new Exception("deflating: " + compressor.Message); - /// + /// /// ms.Write(compressor.OutputBuffer, 0, buffer.Length - compressor.AvailableBytesOut); /// } /// while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0); - /// + /// /// // pass 2: finish and flush /// do /// { /// compressor.NextOut = 0; /// compressor.AvailableBytesOut = buffer.Length; /// rc = compressor.Deflate(FlushType.Finish); - /// + /// /// if (rc != ZlibConstants.Z_STREAM_END && rc != ZlibConstants.Z_OK) /// throw new Exception("deflating: " + compressor.Message); - /// + /// /// if (buffer.Length - compressor.AvailableBytesOut > 0) /// ms.Write(buffer, 0, buffer.Length - compressor.AvailableBytesOut); /// } /// while (compressor.AvailableBytesIn > 0 || compressor.AvailableBytesOut == 0); - /// + /// /// compressor.EndDeflate(); - /// + /// /// ms.Seek(0, SeekOrigin.Begin); /// CompressedBytes = new byte[compressor.TotalBytesOut]; /// ms.Read(CompressedBytes, 0, CompressedBytes.Length); /// } /// /// - /// whether to flush all data as you deflate. Generally you will want to - /// use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to - /// flush everything. + /// whether to flush all data as you deflate. Generally you will want to + /// use Z_NO_FLUSH here, in a series of calls to Deflate(), and then call EndDeflate() to + /// flush everything. /// /// Z_OK if all goes well. public int Deflate(FlushType flush) @@ -693,13 +695,20 @@ namespace SharpCompress.Compressors.Deflate return; } - if (dstate.pending.Length <= dstate.nextPending || - OutputBuffer.Length <= NextOut || - dstate.pending.Length < (dstate.nextPending + len) || - OutputBuffer.Length < (NextOut + len)) + if ( + dstate.pending.Length <= dstate.nextPending + || OutputBuffer.Length <= NextOut + || dstate.pending.Length < (dstate.nextPending + len) + || OutputBuffer.Length < (NextOut + len) + ) { - throw new ZlibException(String.Format("Invalid State. (pending.Length={0}, pendingCount={1})", - dstate.pending.Length, dstate.pendingCount)); + throw new ZlibException( + String.Format( + "Invalid State. (pending.Length={0}, pendingCount={1})", + dstate.pending.Length, + dstate.pendingCount + ) + ); } Array.Copy(dstate.pending, dstate.nextPending, OutputBuffer, NextOut, len); @@ -745,4 +754,4 @@ namespace SharpCompress.Compressors.Deflate return len; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/ZlibConstants.cs b/src/SharpCompress/Compressors/Deflate/ZlibConstants.cs index a6780614..48d6c170 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibConstants.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibConstants.cs @@ -1,20 +1,20 @@ // ZlibConstants.cs // ------------------------------------------------------------------ // -// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. +// Copyright (c) 2009 Dino Chiesa and Microsoft Corporation. // All rights reserved. // // This code module is part of DotNetZip, a zipfile class library. // // ------------------------------------------------------------------ // -// This code is licensed under the Microsoft Public License. +// This code is licensed under the Microsoft Public License. // See the file License.txt for the license details. // More info on: http://dotnetzip.codeplex.com // // ------------------------------------------------------------------ // -// last saved (in emacs): +// last saved (in emacs): // Time-stamp: <2009-November-03 18:50:19> // // ------------------------------------------------------------------ @@ -25,22 +25,22 @@ // copyright to that code is included here. // // ------------------------------------------------------------------ -// +// // Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the distribution. -// +// // 3. The names of the authors may not be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT, @@ -51,7 +51,7 @@ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // ----------------------------------------------------------------------- // // This program is based on zlib-1.1.3; credit to authors @@ -89,7 +89,7 @@ namespace SharpCompress.Compressors.Deflate public const int Z_STREAM_END = 1; /// - /// The operation ended in need of a dictionary. + /// The operation ended in need of a dictionary. /// public const int Z_NEED_DICT = 2; @@ -122,4 +122,4 @@ namespace SharpCompress.Compressors.Deflate /// public const int WorkingBufferSizeMin = 1024; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate/ZlibStream.cs b/src/SharpCompress/Compressors/Deflate/ZlibStream.cs index c82040ef..8d8be7ae 100644 --- a/src/SharpCompress/Compressors/Deflate/ZlibStream.cs +++ b/src/SharpCompress/Compressors/Deflate/ZlibStream.cs @@ -37,16 +37,17 @@ namespace SharpCompress.Compressors.Deflate private bool _disposed; public ZlibStream(Stream stream, CompressionMode mode) - : this(stream, mode, CompressionLevel.Default, Encoding.UTF8) - { - } + : this(stream, mode, CompressionLevel.Default, Encoding.UTF8) { } public ZlibStream(Stream stream, CompressionMode mode, CompressionLevel level) - : this(stream, mode, level, Encoding.UTF8) - { - } + : this(stream, mode, level, Encoding.UTF8) { } - public ZlibStream(Stream stream, CompressionMode mode, CompressionLevel level, Encoding encoding) + public ZlibStream( + Stream stream, + CompressionMode mode, + CompressionLevel level, + Encoding encoding + ) { _baseStream = new ZlibBaseStream(stream, mode, level, ZlibStreamFlavor.ZLIB, encoding); } @@ -103,8 +104,12 @@ namespace SharpCompress.Compressors.Deflate if (value < ZlibConstants.WorkingBufferSizeMin) { throw new ZlibException( - String.Format("Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", value, - ZlibConstants.WorkingBufferSizeMin)); + String.Format( + "Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.", + value, + ZlibConstants.WorkingBufferSizeMin + ) + ); } _baseStream._bufferSize = value; } @@ -194,7 +199,6 @@ namespace SharpCompress.Compressors.Deflate } return 0; } - set => throw new NotSupportedException(); } @@ -341,4 +345,4 @@ namespace SharpCompress.Compressors.Deflate #endregion System.IO.Stream methods } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs b/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs index c05f0c2a..d182db74 100644 --- a/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs +++ b/src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs @@ -30,12 +30,17 @@ namespace SharpCompress.Compressors.Deflate64 if (mode != CompressionMode.Decompress) { - throw new NotImplementedException("Deflate64: this implementation only supports decompression"); + throw new NotImplementedException( + "Deflate64: this implementation only supports decompression" + ); } if (!stream.CanRead) { - throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream)); + throw new ArgumentException( + "Deflate64: input stream is not readable", + nameof(stream) + ); } InitializeInflater(stream, ZipCompressionMethod.Deflate64); @@ -44,13 +49,21 @@ namespace SharpCompress.Compressors.Deflate64 /// /// Sets up this DeflateManagedStream to be used for Inflation/Decompression /// - private 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); + Debug.Assert( + method == ZipCompressionMethod.Deflate || method == ZipCompressionMethod.Deflate64 + ); if (!stream.CanRead) { - throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream)); + throw new ArgumentException( + "Deflate64: input stream is not readable", + nameof(stream) + ); } _inflater = new InflaterManaged(method == ZipCompressionMethod.Deflate64); @@ -138,7 +151,10 @@ namespace SharpCompress.Compressors.Deflate64 if (_inflater.Finished()) { // if we finished decompressing, we can't have anything left in the outputwindow. - Debug.Assert(_inflater.AvailableOutput == 0, "We should have copied all stuff out!"); + Debug.Assert( + _inflater.AvailableOutput == 0, + "We should have copied all stuff out!" + ); break; } diff --git a/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs b/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs index 16010e17..2305d241 100644 --- a/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs +++ b/src/SharpCompress/Compressors/Deflate64/DeflateInput.cs @@ -33,7 +33,8 @@ namespace SharpCompress.Compressors.Deflate64 StartIndex = state._startIndex; } - internal /*readonly */struct InputState + internal /*readonly */ + struct InputState { internal readonly int _count; internal readonly int _startIndex; diff --git a/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs b/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs index f5f26276..8b0992da 100644 --- a/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs +++ b/src/SharpCompress/Compressors/Deflate64/FastEncoderStatus.cs @@ -11,31 +11,211 @@ namespace SharpCompress.Compressors.Deflate64 { // static information for encoding, DO NOT MODIFY - internal static ReadOnlySpan FAST_ENCODER_TREE_STRUCTURE_DATA => new byte[] - { - 0xec,0xbd,0x07,0x60,0x1c,0x49,0x96,0x25,0x26,0x2f,0x6d,0xca, - 0x7b,0x7f,0x4a,0xf5,0x4a,0xd7,0xe0,0x74,0xa1,0x08,0x80,0x60, - 0x13,0x24,0xd8,0x90,0x40,0x10,0xec,0xc1,0x88,0xcd,0xe6,0x92, - 0xec,0x1d,0x69,0x47,0x23,0x29,0xab,0x2a,0x81,0xca,0x65,0x56, - 0x65,0x5d,0x66,0x16,0x40,0xcc,0xed,0x9d,0xbc,0xf7,0xde,0x7b, - 0xef,0xbd,0xf7,0xde,0x7b,0xef,0xbd,0xf7,0xba,0x3b,0x9d,0x4e, - 0x27,0xf7,0xdf,0xff,0x3f,0x5c,0x66,0x64,0x01,0x6c,0xf6,0xce, - 0x4a,0xda,0xc9,0x9e,0x21,0x80,0xaa,0xc8,0x1f,0x3f,0x7e,0x7c, - 0x1f,0x3f - }; + internal static ReadOnlySpan FAST_ENCODER_TREE_STRUCTURE_DATA => + new byte[] + { + 0xec, + 0xbd, + 0x07, + 0x60, + 0x1c, + 0x49, + 0x96, + 0x25, + 0x26, + 0x2f, + 0x6d, + 0xca, + 0x7b, + 0x7f, + 0x4a, + 0xf5, + 0x4a, + 0xd7, + 0xe0, + 0x74, + 0xa1, + 0x08, + 0x80, + 0x60, + 0x13, + 0x24, + 0xd8, + 0x90, + 0x40, + 0x10, + 0xec, + 0xc1, + 0x88, + 0xcd, + 0xe6, + 0x92, + 0xec, + 0x1d, + 0x69, + 0x47, + 0x23, + 0x29, + 0xab, + 0x2a, + 0x81, + 0xca, + 0x65, + 0x56, + 0x65, + 0x5d, + 0x66, + 0x16, + 0x40, + 0xcc, + 0xed, + 0x9d, + 0xbc, + 0xf7, + 0xde, + 0x7b, + 0xef, + 0xbd, + 0xf7, + 0xde, + 0x7b, + 0xef, + 0xbd, + 0xf7, + 0xba, + 0x3b, + 0x9d, + 0x4e, + 0x27, + 0xf7, + 0xdf, + 0xff, + 0x3f, + 0x5c, + 0x66, + 0x64, + 0x01, + 0x6c, + 0xf6, + 0xce, + 0x4a, + 0xda, + 0xc9, + 0x9e, + 0x21, + 0x80, + 0xaa, + 0xc8, + 0x1f, + 0x3f, + 0x7e, + 0x7c, + 0x1f, + 0x3f + }; - internal static ReadOnlySpan B_FINAL_FAST_ENCODER_TREE_STRUCTURE_DATA => new byte[] - { - 0xed,0xbd,0x07,0x60,0x1c,0x49,0x96,0x25,0x26,0x2f,0x6d,0xca, - 0x7b,0x7f,0x4a,0xf5,0x4a,0xd7,0xe0,0x74,0xa1,0x08,0x80,0x60, - 0x13,0x24,0xd8,0x90,0x40,0x10,0xec,0xc1,0x88,0xcd,0xe6,0x92, - 0xec,0x1d,0x69,0x47,0x23,0x29,0xab,0x2a,0x81,0xca,0x65,0x56, - 0x65,0x5d,0x66,0x16,0x40,0xcc,0xed,0x9d,0xbc,0xf7,0xde,0x7b, - 0xef,0xbd,0xf7,0xde,0x7b,0xef,0xbd,0xf7,0xba,0x3b,0x9d,0x4e, - 0x27,0xf7,0xdf,0xff,0x3f,0x5c,0x66,0x64,0x01,0x6c,0xf6,0xce, - 0x4a,0xda,0xc9,0x9e,0x21,0x80,0xaa,0xc8,0x1f,0x3f,0x7e,0x7c, - 0x1f,0x3f - }; + internal static ReadOnlySpan B_FINAL_FAST_ENCODER_TREE_STRUCTURE_DATA => + new byte[] + { + 0xed, + 0xbd, + 0x07, + 0x60, + 0x1c, + 0x49, + 0x96, + 0x25, + 0x26, + 0x2f, + 0x6d, + 0xca, + 0x7b, + 0x7f, + 0x4a, + 0xf5, + 0x4a, + 0xd7, + 0xe0, + 0x74, + 0xa1, + 0x08, + 0x80, + 0x60, + 0x13, + 0x24, + 0xd8, + 0x90, + 0x40, + 0x10, + 0xec, + 0xc1, + 0x88, + 0xcd, + 0xe6, + 0x92, + 0xec, + 0x1d, + 0x69, + 0x47, + 0x23, + 0x29, + 0xab, + 0x2a, + 0x81, + 0xca, + 0x65, + 0x56, + 0x65, + 0x5d, + 0x66, + 0x16, + 0x40, + 0xcc, + 0xed, + 0x9d, + 0xbc, + 0xf7, + 0xde, + 0x7b, + 0xef, + 0xbd, + 0xf7, + 0xde, + 0x7b, + 0xef, + 0xbd, + 0xf7, + 0xba, + 0x3b, + 0x9d, + 0x4e, + 0x27, + 0xf7, + 0xdf, + 0xff, + 0x3f, + 0x5c, + 0x66, + 0x64, + 0x01, + 0x6c, + 0xf6, + 0xce, + 0x4a, + 0xda, + 0xc9, + 0x9e, + 0x21, + 0x80, + 0xaa, + 0xc8, + 0x1f, + 0x3f, + 0x7e, + 0x7c, + 0x1f, + 0x3f + }; // Output a currentMatch with length matchLen (>= MIN_MATCH) and displacement matchPos // @@ -70,94 +250,643 @@ namespace SharpCompress.Compressors.Deflate64 internal static readonly uint[] FAST_ENCODER_LITERAL_CODE_INFO = { - 0x0000d7ee,0x0004d7ee,0x0002d7ee,0x0006d7ee,0x0001d7ee,0x0005d7ee,0x0003d7ee, - 0x0007d7ee,0x000037ee,0x0000c7ec,0x00000126,0x000437ee,0x000237ee,0x000637ee, - 0x000137ee,0x000537ee,0x000337ee,0x000737ee,0x0000b7ee,0x0004b7ee,0x0002b7ee, - 0x0006b7ee,0x0001b7ee,0x0005b7ee,0x0003b7ee,0x0007b7ee,0x000077ee,0x000477ee, - 0x000277ee,0x000677ee,0x000017ed,0x000177ee,0x00000526,0x000577ee,0x000023ea, - 0x0001c7ec,0x000377ee,0x000777ee,0x000217ed,0x000063ea,0x00000b68,0x00000ee9, - 0x00005beb,0x000013ea,0x00000467,0x00001b68,0x00000c67,0x00002ee9,0x00000768, - 0x00001768,0x00000f68,0x00001ee9,0x00001f68,0x00003ee9,0x000053ea,0x000001e9, - 0x000000e8,0x000021e9,0x000011e9,0x000010e8,0x000031e9,0x000033ea,0x000008e8, - 0x0000f7ee,0x0004f7ee,0x000018e8,0x000009e9,0x000004e8,0x000029e9,0x000014e8, - 0x000019e9,0x000073ea,0x0000dbeb,0x00000ce8,0x00003beb,0x0002f7ee,0x000039e9, - 0x00000bea,0x000005e9,0x00004bea,0x000025e9,0x000027ec,0x000015e9,0x000035e9, - 0x00000de9,0x00002bea,0x000127ec,0x0000bbeb,0x0006f7ee,0x0001f7ee,0x0000a7ec, - 0x00007beb,0x0005f7ee,0x0000fbeb,0x0003f7ee,0x0007f7ee,0x00000fee,0x00000326, - 0x00000267,0x00000a67,0x00000667,0x00000726,0x00001ce8,0x000002e8,0x00000e67, - 0x000000a6,0x0001a7ec,0x00002de9,0x000004a6,0x00000167,0x00000967,0x000002a6, - 0x00000567,0x000117ed,0x000006a6,0x000001a6,0x000005a6,0x00000d67,0x000012e8, - 0x00000ae8,0x00001de9,0x00001ae8,0x000007eb,0x000317ed,0x000067ec,0x000097ed, - 0x000297ed,0x00040fee,0x00020fee,0x00060fee,0x00010fee,0x00050fee,0x00030fee, - 0x00070fee,0x00008fee,0x00048fee,0x00028fee,0x00068fee,0x00018fee,0x00058fee, - 0x00038fee,0x00078fee,0x00004fee,0x00044fee,0x00024fee,0x00064fee,0x00014fee, - 0x00054fee,0x00034fee,0x00074fee,0x0000cfee,0x0004cfee,0x0002cfee,0x0006cfee, - 0x0001cfee,0x0005cfee,0x0003cfee,0x0007cfee,0x00002fee,0x00042fee,0x00022fee, - 0x00062fee,0x00012fee,0x00052fee,0x00032fee,0x00072fee,0x0000afee,0x0004afee, - 0x0002afee,0x0006afee,0x0001afee,0x0005afee,0x0003afee,0x0007afee,0x00006fee, - 0x00046fee,0x00026fee,0x00066fee,0x00016fee,0x00056fee,0x00036fee,0x00076fee, - 0x0000efee,0x0004efee,0x0002efee,0x0006efee,0x0001efee,0x0005efee,0x0003efee, - 0x0007efee,0x00001fee,0x00041fee,0x00021fee,0x00061fee,0x00011fee,0x00051fee, - 0x00031fee,0x00071fee,0x00009fee,0x00049fee,0x00029fee,0x00069fee,0x00019fee, - 0x00059fee,0x00039fee,0x00079fee,0x00005fee,0x00045fee,0x00025fee,0x00065fee, - 0x00015fee,0x00055fee,0x00035fee,0x00075fee,0x0000dfee,0x0004dfee,0x0002dfee, - 0x0006dfee,0x0001dfee,0x0005dfee,0x0003dfee,0x0007dfee,0x00003fee,0x00043fee, - 0x00023fee,0x00063fee,0x00013fee,0x00053fee,0x00033fee,0x00073fee,0x0000bfee, - 0x0004bfee,0x0002bfee,0x0006bfee,0x0001bfee,0x0005bfee,0x0003bfee,0x0007bfee, - 0x00007fee,0x00047fee,0x00027fee,0x00067fee,0x00017fee,0x000197ed,0x000397ed, - 0x000057ed,0x00057fee,0x000257ed,0x00037fee,0x000157ed,0x00077fee,0x000357ed, - 0x0000ffee,0x0004ffee,0x0002ffee,0x0006ffee,0x0001ffee,0x00000084,0x00000003, - 0x00000184,0x00000044,0x00000144,0x000000c5,0x000002c5,0x000001c5,0x000003c6, - 0x000007c6,0x00000026,0x00000426,0x000003a7,0x00000ba7,0x000007a7,0x00000fa7, - 0x00000227,0x00000627,0x00000a27,0x00000e27,0x00000068,0x00000868,0x00001068, - 0x00001868,0x00000369,0x00001369,0x00002369,0x00003369,0x000006ea,0x000026ea, - 0x000046ea,0x000066ea,0x000016eb,0x000036eb,0x000056eb,0x000076eb,0x000096eb, - 0x0000b6eb,0x0000d6eb,0x0000f6eb,0x00003dec,0x00007dec,0x0000bdec,0x0000fdec, - 0x00013dec,0x00017dec,0x0001bdec,0x0001fdec,0x00006bed,0x0000ebed,0x00016bed, - 0x0001ebed,0x00026bed,0x0002ebed,0x00036bed,0x0003ebed,0x000003ec,0x000043ec, - 0x000083ec,0x0000c3ec,0x000103ec,0x000143ec,0x000183ec,0x0001c3ec,0x00001bee, - 0x00009bee,0x00011bee,0x00019bee,0x00021bee,0x00029bee,0x00031bee,0x00039bee, - 0x00041bee,0x00049bee,0x00051bee,0x00059bee,0x00061bee,0x00069bee,0x00071bee, - 0x00079bee,0x000167f0,0x000367f0,0x000567f0,0x000767f0,0x000967f0,0x000b67f0, - 0x000d67f0,0x000f67f0,0x001167f0,0x001367f0,0x001567f0,0x001767f0,0x001967f0, - 0x001b67f0,0x001d67f0,0x001f67f0,0x000087ef,0x000187ef,0x000287ef,0x000387ef, - 0x000487ef,0x000587ef,0x000687ef,0x000787ef,0x000887ef,0x000987ef,0x000a87ef, - 0x000b87ef,0x000c87ef,0x000d87ef,0x000e87ef,0x000f87ef,0x0000e7f0,0x0002e7f0, - 0x0004e7f0,0x0006e7f0,0x0008e7f0,0x000ae7f0,0x000ce7f0,0x000ee7f0,0x0010e7f0, - 0x0012e7f0,0x0014e7f0,0x0016e7f0,0x0018e7f0,0x001ae7f0,0x001ce7f0,0x001ee7f0, - 0x0005fff3,0x000dfff3,0x0015fff3,0x001dfff3,0x0025fff3,0x002dfff3,0x0035fff3, - 0x003dfff3,0x0045fff3,0x004dfff3,0x0055fff3,0x005dfff3,0x0065fff3,0x006dfff3, - 0x0075fff3,0x007dfff3,0x0085fff3,0x008dfff3,0x0095fff3,0x009dfff3,0x00a5fff3, - 0x00adfff3,0x00b5fff3,0x00bdfff3,0x00c5fff3,0x00cdfff3,0x00d5fff3,0x00ddfff3, - 0x00e5fff3,0x00edfff3,0x00f5fff3,0x00fdfff3,0x0003fff3,0x000bfff3,0x0013fff3, - 0x001bfff3,0x0023fff3,0x002bfff3,0x0033fff3,0x003bfff3,0x0043fff3,0x004bfff3, - 0x0053fff3,0x005bfff3,0x0063fff3,0x006bfff3,0x0073fff3,0x007bfff3,0x0083fff3, - 0x008bfff3,0x0093fff3,0x009bfff3,0x00a3fff3,0x00abfff3,0x00b3fff3,0x00bbfff3, - 0x00c3fff3,0x00cbfff3,0x00d3fff3,0x00dbfff3,0x00e3fff3,0x00ebfff3,0x00f3fff3, - 0x00fbfff3,0x0007fff3,0x000ffff3,0x0017fff3,0x001ffff3,0x0027fff3,0x002ffff3, - 0x0037fff3,0x003ffff3,0x0047fff3,0x004ffff3,0x0057fff3,0x005ffff3,0x0067fff3, - 0x006ffff3,0x0077fff3,0x007ffff3,0x0087fff3,0x008ffff3,0x0097fff3,0x009ffff3, - 0x00a7fff3,0x00affff3,0x00b7fff3,0x00bffff3,0x00c7fff3,0x00cffff3,0x00d7fff3, - 0x00dffff3,0x00e7fff3,0x00effff3,0x00f7fff3,0x00fffff3,0x0001e7f1,0x0003e7f1, - 0x0005e7f1,0x0007e7f1,0x0009e7f1,0x000be7f1,0x000de7f1,0x000fe7f1,0x0011e7f1, - 0x0013e7f1,0x0015e7f1,0x0017e7f1,0x0019e7f1,0x001be7f1,0x001de7f1,0x001fe7f1, - 0x0021e7f1,0x0023e7f1,0x0025e7f1,0x0027e7f1,0x0029e7f1,0x002be7f1,0x002de7f1, - 0x002fe7f1,0x0031e7f1,0x0033e7f1,0x0035e7f1,0x0037e7f1,0x0039e7f1,0x003be7f1, - 0x003de7f1,0x000047eb + 0x0000d7ee, + 0x0004d7ee, + 0x0002d7ee, + 0x0006d7ee, + 0x0001d7ee, + 0x0005d7ee, + 0x0003d7ee, + 0x0007d7ee, + 0x000037ee, + 0x0000c7ec, + 0x00000126, + 0x000437ee, + 0x000237ee, + 0x000637ee, + 0x000137ee, + 0x000537ee, + 0x000337ee, + 0x000737ee, + 0x0000b7ee, + 0x0004b7ee, + 0x0002b7ee, + 0x0006b7ee, + 0x0001b7ee, + 0x0005b7ee, + 0x0003b7ee, + 0x0007b7ee, + 0x000077ee, + 0x000477ee, + 0x000277ee, + 0x000677ee, + 0x000017ed, + 0x000177ee, + 0x00000526, + 0x000577ee, + 0x000023ea, + 0x0001c7ec, + 0x000377ee, + 0x000777ee, + 0x000217ed, + 0x000063ea, + 0x00000b68, + 0x00000ee9, + 0x00005beb, + 0x000013ea, + 0x00000467, + 0x00001b68, + 0x00000c67, + 0x00002ee9, + 0x00000768, + 0x00001768, + 0x00000f68, + 0x00001ee9, + 0x00001f68, + 0x00003ee9, + 0x000053ea, + 0x000001e9, + 0x000000e8, + 0x000021e9, + 0x000011e9, + 0x000010e8, + 0x000031e9, + 0x000033ea, + 0x000008e8, + 0x0000f7ee, + 0x0004f7ee, + 0x000018e8, + 0x000009e9, + 0x000004e8, + 0x000029e9, + 0x000014e8, + 0x000019e9, + 0x000073ea, + 0x0000dbeb, + 0x00000ce8, + 0x00003beb, + 0x0002f7ee, + 0x000039e9, + 0x00000bea, + 0x000005e9, + 0x00004bea, + 0x000025e9, + 0x000027ec, + 0x000015e9, + 0x000035e9, + 0x00000de9, + 0x00002bea, + 0x000127ec, + 0x0000bbeb, + 0x0006f7ee, + 0x0001f7ee, + 0x0000a7ec, + 0x00007beb, + 0x0005f7ee, + 0x0000fbeb, + 0x0003f7ee, + 0x0007f7ee, + 0x00000fee, + 0x00000326, + 0x00000267, + 0x00000a67, + 0x00000667, + 0x00000726, + 0x00001ce8, + 0x000002e8, + 0x00000e67, + 0x000000a6, + 0x0001a7ec, + 0x00002de9, + 0x000004a6, + 0x00000167, + 0x00000967, + 0x000002a6, + 0x00000567, + 0x000117ed, + 0x000006a6, + 0x000001a6, + 0x000005a6, + 0x00000d67, + 0x000012e8, + 0x00000ae8, + 0x00001de9, + 0x00001ae8, + 0x000007eb, + 0x000317ed, + 0x000067ec, + 0x000097ed, + 0x000297ed, + 0x00040fee, + 0x00020fee, + 0x00060fee, + 0x00010fee, + 0x00050fee, + 0x00030fee, + 0x00070fee, + 0x00008fee, + 0x00048fee, + 0x00028fee, + 0x00068fee, + 0x00018fee, + 0x00058fee, + 0x00038fee, + 0x00078fee, + 0x00004fee, + 0x00044fee, + 0x00024fee, + 0x00064fee, + 0x00014fee, + 0x00054fee, + 0x00034fee, + 0x00074fee, + 0x0000cfee, + 0x0004cfee, + 0x0002cfee, + 0x0006cfee, + 0x0001cfee, + 0x0005cfee, + 0x0003cfee, + 0x0007cfee, + 0x00002fee, + 0x00042fee, + 0x00022fee, + 0x00062fee, + 0x00012fee, + 0x00052fee, + 0x00032fee, + 0x00072fee, + 0x0000afee, + 0x0004afee, + 0x0002afee, + 0x0006afee, + 0x0001afee, + 0x0005afee, + 0x0003afee, + 0x0007afee, + 0x00006fee, + 0x00046fee, + 0x00026fee, + 0x00066fee, + 0x00016fee, + 0x00056fee, + 0x00036fee, + 0x00076fee, + 0x0000efee, + 0x0004efee, + 0x0002efee, + 0x0006efee, + 0x0001efee, + 0x0005efee, + 0x0003efee, + 0x0007efee, + 0x00001fee, + 0x00041fee, + 0x00021fee, + 0x00061fee, + 0x00011fee, + 0x00051fee, + 0x00031fee, + 0x00071fee, + 0x00009fee, + 0x00049fee, + 0x00029fee, + 0x00069fee, + 0x00019fee, + 0x00059fee, + 0x00039fee, + 0x00079fee, + 0x00005fee, + 0x00045fee, + 0x00025fee, + 0x00065fee, + 0x00015fee, + 0x00055fee, + 0x00035fee, + 0x00075fee, + 0x0000dfee, + 0x0004dfee, + 0x0002dfee, + 0x0006dfee, + 0x0001dfee, + 0x0005dfee, + 0x0003dfee, + 0x0007dfee, + 0x00003fee, + 0x00043fee, + 0x00023fee, + 0x00063fee, + 0x00013fee, + 0x00053fee, + 0x00033fee, + 0x00073fee, + 0x0000bfee, + 0x0004bfee, + 0x0002bfee, + 0x0006bfee, + 0x0001bfee, + 0x0005bfee, + 0x0003bfee, + 0x0007bfee, + 0x00007fee, + 0x00047fee, + 0x00027fee, + 0x00067fee, + 0x00017fee, + 0x000197ed, + 0x000397ed, + 0x000057ed, + 0x00057fee, + 0x000257ed, + 0x00037fee, + 0x000157ed, + 0x00077fee, + 0x000357ed, + 0x0000ffee, + 0x0004ffee, + 0x0002ffee, + 0x0006ffee, + 0x0001ffee, + 0x00000084, + 0x00000003, + 0x00000184, + 0x00000044, + 0x00000144, + 0x000000c5, + 0x000002c5, + 0x000001c5, + 0x000003c6, + 0x000007c6, + 0x00000026, + 0x00000426, + 0x000003a7, + 0x00000ba7, + 0x000007a7, + 0x00000fa7, + 0x00000227, + 0x00000627, + 0x00000a27, + 0x00000e27, + 0x00000068, + 0x00000868, + 0x00001068, + 0x00001868, + 0x00000369, + 0x00001369, + 0x00002369, + 0x00003369, + 0x000006ea, + 0x000026ea, + 0x000046ea, + 0x000066ea, + 0x000016eb, + 0x000036eb, + 0x000056eb, + 0x000076eb, + 0x000096eb, + 0x0000b6eb, + 0x0000d6eb, + 0x0000f6eb, + 0x00003dec, + 0x00007dec, + 0x0000bdec, + 0x0000fdec, + 0x00013dec, + 0x00017dec, + 0x0001bdec, + 0x0001fdec, + 0x00006bed, + 0x0000ebed, + 0x00016bed, + 0x0001ebed, + 0x00026bed, + 0x0002ebed, + 0x00036bed, + 0x0003ebed, + 0x000003ec, + 0x000043ec, + 0x000083ec, + 0x0000c3ec, + 0x000103ec, + 0x000143ec, + 0x000183ec, + 0x0001c3ec, + 0x00001bee, + 0x00009bee, + 0x00011bee, + 0x00019bee, + 0x00021bee, + 0x00029bee, + 0x00031bee, + 0x00039bee, + 0x00041bee, + 0x00049bee, + 0x00051bee, + 0x00059bee, + 0x00061bee, + 0x00069bee, + 0x00071bee, + 0x00079bee, + 0x000167f0, + 0x000367f0, + 0x000567f0, + 0x000767f0, + 0x000967f0, + 0x000b67f0, + 0x000d67f0, + 0x000f67f0, + 0x001167f0, + 0x001367f0, + 0x001567f0, + 0x001767f0, + 0x001967f0, + 0x001b67f0, + 0x001d67f0, + 0x001f67f0, + 0x000087ef, + 0x000187ef, + 0x000287ef, + 0x000387ef, + 0x000487ef, + 0x000587ef, + 0x000687ef, + 0x000787ef, + 0x000887ef, + 0x000987ef, + 0x000a87ef, + 0x000b87ef, + 0x000c87ef, + 0x000d87ef, + 0x000e87ef, + 0x000f87ef, + 0x0000e7f0, + 0x0002e7f0, + 0x0004e7f0, + 0x0006e7f0, + 0x0008e7f0, + 0x000ae7f0, + 0x000ce7f0, + 0x000ee7f0, + 0x0010e7f0, + 0x0012e7f0, + 0x0014e7f0, + 0x0016e7f0, + 0x0018e7f0, + 0x001ae7f0, + 0x001ce7f0, + 0x001ee7f0, + 0x0005fff3, + 0x000dfff3, + 0x0015fff3, + 0x001dfff3, + 0x0025fff3, + 0x002dfff3, + 0x0035fff3, + 0x003dfff3, + 0x0045fff3, + 0x004dfff3, + 0x0055fff3, + 0x005dfff3, + 0x0065fff3, + 0x006dfff3, + 0x0075fff3, + 0x007dfff3, + 0x0085fff3, + 0x008dfff3, + 0x0095fff3, + 0x009dfff3, + 0x00a5fff3, + 0x00adfff3, + 0x00b5fff3, + 0x00bdfff3, + 0x00c5fff3, + 0x00cdfff3, + 0x00d5fff3, + 0x00ddfff3, + 0x00e5fff3, + 0x00edfff3, + 0x00f5fff3, + 0x00fdfff3, + 0x0003fff3, + 0x000bfff3, + 0x0013fff3, + 0x001bfff3, + 0x0023fff3, + 0x002bfff3, + 0x0033fff3, + 0x003bfff3, + 0x0043fff3, + 0x004bfff3, + 0x0053fff3, + 0x005bfff3, + 0x0063fff3, + 0x006bfff3, + 0x0073fff3, + 0x007bfff3, + 0x0083fff3, + 0x008bfff3, + 0x0093fff3, + 0x009bfff3, + 0x00a3fff3, + 0x00abfff3, + 0x00b3fff3, + 0x00bbfff3, + 0x00c3fff3, + 0x00cbfff3, + 0x00d3fff3, + 0x00dbfff3, + 0x00e3fff3, + 0x00ebfff3, + 0x00f3fff3, + 0x00fbfff3, + 0x0007fff3, + 0x000ffff3, + 0x0017fff3, + 0x001ffff3, + 0x0027fff3, + 0x002ffff3, + 0x0037fff3, + 0x003ffff3, + 0x0047fff3, + 0x004ffff3, + 0x0057fff3, + 0x005ffff3, + 0x0067fff3, + 0x006ffff3, + 0x0077fff3, + 0x007ffff3, + 0x0087fff3, + 0x008ffff3, + 0x0097fff3, + 0x009ffff3, + 0x00a7fff3, + 0x00affff3, + 0x00b7fff3, + 0x00bffff3, + 0x00c7fff3, + 0x00cffff3, + 0x00d7fff3, + 0x00dffff3, + 0x00e7fff3, + 0x00effff3, + 0x00f7fff3, + 0x00fffff3, + 0x0001e7f1, + 0x0003e7f1, + 0x0005e7f1, + 0x0007e7f1, + 0x0009e7f1, + 0x000be7f1, + 0x000de7f1, + 0x000fe7f1, + 0x0011e7f1, + 0x0013e7f1, + 0x0015e7f1, + 0x0017e7f1, + 0x0019e7f1, + 0x001be7f1, + 0x001de7f1, + 0x001fe7f1, + 0x0021e7f1, + 0x0023e7f1, + 0x0025e7f1, + 0x0027e7f1, + 0x0029e7f1, + 0x002be7f1, + 0x002de7f1, + 0x002fe7f1, + 0x0031e7f1, + 0x0033e7f1, + 0x0035e7f1, + 0x0037e7f1, + 0x0039e7f1, + 0x003be7f1, + 0x003de7f1, + 0x000047eb }; internal static readonly uint[] FAST_ENCODER_DISTANCE_CODE_INFO = { - 0x00000f06,0x0001ff0a,0x0003ff0b,0x0007ff0b,0x0000ff19,0x00003f18,0x0000bf28, - 0x00007f28,0x00001f37,0x00005f37,0x00000d45,0x00002f46,0x00000054,0x00001d55, - 0x00000864,0x00000365,0x00000474,0x00001375,0x00000c84,0x00000284,0x00000a94, - 0x00000694,0x00000ea4,0x000001a4,0x000009b4,0x00000bb5,0x000005c4,0x00001bc5, - 0x000007d5,0x000017d5,0x00000000,0x00000100 + 0x00000f06, + 0x0001ff0a, + 0x0003ff0b, + 0x0007ff0b, + 0x0000ff19, + 0x00003f18, + 0x0000bf28, + 0x00007f28, + 0x00001f37, + 0x00005f37, + 0x00000d45, + 0x00002f46, + 0x00000054, + 0x00001d55, + 0x00000864, + 0x00000365, + 0x00000474, + 0x00001375, + 0x00000c84, + 0x00000284, + 0x00000a94, + 0x00000694, + 0x00000ea4, + 0x000001a4, + 0x000009b4, + 0x00000bb5, + 0x000005c4, + 0x00001bc5, + 0x000007d5, + 0x000017d5, + 0x00000000, + 0x00000100 }; - 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 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; diff --git a/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs b/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs index 017c1cb9..eac0ff5f 100644 --- a/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs +++ b/src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs @@ -42,17 +42,20 @@ namespace SharpCompress.Compressors.Deflate64 private readonly int _tableMask; // huffman tree for static block - public static HuffmanTree StaticLiteralLengthTree { get; } = new HuffmanTree(GetStaticLiteralTreeLength()); + public static HuffmanTree StaticLiteralLengthTree { get; } = + new HuffmanTree(GetStaticLiteralTreeLength()); - public static HuffmanTree StaticDistanceTree { get; } = new HuffmanTree(GetStaticDistanceTreeLength()); + public static HuffmanTree StaticDistanceTree { get; } = + new HuffmanTree(GetStaticDistanceTreeLength()); public HuffmanTree(byte[] codeLengths) { Debug.Assert( - 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"); + 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 == MAX_LITERAL_TREE_ELEMENTS) @@ -124,7 +127,7 @@ namespace SharpCompress.Compressors.Deflate64 { bitLengthCount[codeLength]++; } - bitLengthCount[0] = 0; // clear count for length 0 + bitLengthCount[0] = 0; // clear count for length 0 Span nextCode = stackalloc uint[17]; uint tempCode = 0; @@ -236,7 +239,10 @@ namespace SharpCompress.Compressors.Deflate64 throw new InvalidDataException("Deflate64: invalid Huffman data"); } - Debug.Assert(value < 0, "CreateTable: Only negative numbers are used for tree pointers!"); + Debug.Assert( + value < 0, + "CreateTable: Only negative numbers are used for tree pointers!" + ); if ((start & codeBitMask) == 0) { @@ -272,14 +278,14 @@ namespace SharpCompress.Compressors.Deflate64 // input buffer. uint bitBuffer = input.TryLoad16Bits(); if (input.AvailableBits == 0) - { // running out of input. + { // running out of input. return -1; } // decode an element int symbol = _table[bitBuffer & _tableMask]; if (symbol < 0) - { // this will be the start of the binary tree + { // this will be the start of the binary tree // navigate the tree uint mask = (uint)1 << _tableBits; do diff --git a/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs b/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs index de9b78d5..3864ff44 100644 --- a/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs +++ b/src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs @@ -39,28 +39,153 @@ namespace SharpCompress.Compressors.Deflate64 // const tables used in decoding: // Extra bits for length code 257 - 285. - private static ReadOnlySpan S_EXTRA_LENGTH_BITS => new byte[] - { 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 }; + private static ReadOnlySpan S_EXTRA_LENGTH_BITS => + new byte[] + { + 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_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}; + { + 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_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 }; + { + 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 ReadOnlySpan S_CODE_ORDER => new byte[] { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + private static ReadOnlySpan S_CODE_ORDER => + new byte[] { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; - private static ReadOnlySpan S_STATIC_DISTANCE_TREE_TABLE => new byte[] - { - 0x00,0x10,0x08,0x18,0x04,0x14,0x0c,0x1c,0x02,0x12,0x0a,0x1a, - 0x06,0x16,0x0e,0x1e,0x01,0x11,0x09,0x19,0x05,0x15,0x0d,0x1d, - 0x03,0x13,0x0b,0x1b,0x07,0x17,0x0f,0x1f - }; + private static ReadOnlySpan S_STATIC_DISTANCE_TREE_TABLE => + new byte[] + { + 0x00, + 0x10, + 0x08, + 0x18, + 0x04, + 0x14, + 0x0c, + 0x1c, + 0x02, + 0x12, + 0x0a, + 0x1a, + 0x06, + 0x16, + 0x0e, + 0x1e, + 0x01, + 0x11, + 0x09, + 0x19, + 0x05, + 0x15, + 0x0d, + 0x1d, + 0x03, + 0x13, + 0x0b, + 0x1b, + 0x07, + 0x17, + 0x0f, + 0x1f + }; private readonly OutputWindow _output; private readonly InputBuffer _input; @@ -68,6 +193,7 @@ namespace SharpCompress.Compressors.Deflate64 private HuffmanTree _distanceTree; private InflaterState _state; + //private bool _hasFormatReader; private int _bfinal; private BlockType _blockType; @@ -95,12 +221,16 @@ namespace SharpCompress.Compressors.Deflate64 //private IFileFormatReader _formatReader; // class to decode header and footer (e.g. gzip) - internal InflaterManaged(/*IFileFormatReader reader, */bool deflate64) + internal InflaterManaged( /*IFileFormatReader reader, */ + bool deflate64 + ) { _output = new OutputWindow(); _input = new InputBuffer(); - _codeList = new byte[HuffmanTree.MAX_LITERAL_TREE_ELEMENTS + HuffmanTree.MAX_DIST_TREE_ELEMENTS]; + _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) @@ -114,14 +244,15 @@ namespace SharpCompress.Compressors.Deflate64 private void Reset() { _state = //_hasFormatReader ? - //InflaterState.ReadingHeader : // start by reading Header info - InflaterState.ReadingBFinal; // start by reading BFinal bit + //InflaterState.ReadingHeader : // start by reading Header info + InflaterState.ReadingBFinal; // start by reading BFinal bit } public void SetInput(byte[] inputBytes, int offset, int length) => _input.SetInput(inputBytes, offset, length); // append the bytes - public bool Finished() => _state == InflaterState.Done || _state == InflaterState.VerifyingFooter; + public bool Finished() => + _state == InflaterState.Done || _state == InflaterState.VerifyingFooter; public int AvailableOutput => _output.AvailableBytes; @@ -147,14 +278,14 @@ namespace SharpCompress.Compressors.Deflate64 } if (length == 0) - { // filled in the bytes array + { // filled in the bytes array break; } // Decode will return false when more input is needed } while (!Finished() && Decode()); if (_state == InflaterState.VerifyingFooter) - { // finished reading CRC + { // finished reading CRC // In this case finished is true and output window has all the data. // But some data in output window might not be copied out. if (_output.AvailableBytes == 0) @@ -299,7 +430,6 @@ namespace SharpCompress.Compressors.Deflate64 return result; } - // Format of Non-compressed blocks (BTYPE=00): // // Any bits of input up to the next byte boundary are ignored. @@ -320,12 +450,12 @@ namespace SharpCompress.Compressors.Deflate64 switch (_state) { case InflaterState.UncompressedAligning: // initial state when calling this function - // we must skip to a byte boundary + // we must skip to a byte boundary _input.SkipToByteBoundary(); _state = InflaterState.UncompressedByte1; goto case InflaterState.UncompressedByte1; - case InflaterState.UncompressedByte1: // decoding block length + case InflaterState.UncompressedByte1: // decoding block length case InflaterState.UncompressedByte2: case InflaterState.UncompressedByte3: case InflaterState.UncompressedByte4: @@ -338,8 +468,10 @@ namespace SharpCompress.Compressors.Deflate64 _blockLengthBuffer[_state - InflaterState.UncompressedByte1] = (byte)bits; if (_state == InflaterState.UncompressedByte4) { - _blockLength = _blockLengthBuffer[0] + ((int)_blockLengthBuffer[1]) * 256; - int blockLengthComplement = _blockLengthBuffer[2] + ((int)_blockLengthBuffer[3]) * 256; + _blockLength = + _blockLengthBuffer[0] + ((int)_blockLengthBuffer[1]) * 256; + int blockLengthComplement = + _blockLengthBuffer[2] + ((int)_blockLengthBuffer[3]) * 256; // make sure complement matches if ((ushort)_blockLength != (ushort)(~blockLengthComplement)) @@ -376,7 +508,8 @@ namespace SharpCompress.Compressors.Deflate64 return false; default: - Debug./*Fail*/Assert(false, "check why we are here!"); + Debug. /*Fail*/ + Assert(false, "check why we are here!"); throw new InvalidDataException("Deflate64: unknown state"); } } @@ -386,7 +519,7 @@ namespace SharpCompress.Compressors.Deflate64 { endOfBlockCodeSeen = false; - int freeBytes = _output.FreeBytes; // it is a little bit faster than frequently accessing the property + int freeBytes = _output.FreeBytes; // it is a little bit faster than frequently accessing the property while (freeBytes > 65536) { // With Deflate64 we can have up to a 64kb length, so we ensure at least that much space is available @@ -423,16 +556,16 @@ namespace SharpCompress.Compressors.Deflate64 else { // length/distance pair - symbol -= 257; // length code started at 257 + symbol -= 257; // length code started at 257 if (symbol < 8) { - symbol += 3; // match length = 3,4,5,6,7,8,9,10 + symbol += 3; // match length = 3,4,5,6,7,8,9,10 _extraBits = 0; } else if (!_deflate64 && symbol == 28) { // extra bits for code 285 is 0 - symbol = 258; // code 285 means length 258 + symbol = 258; // code 285 means length 258 _extraBits = 0; } else @@ -517,7 +650,8 @@ namespace SharpCompress.Compressors.Deflate64 break; default: - Debug./*Fail*/Assert(false, "check why we are here!"); + Debug. /*Fail*/ + Assert(false, "check why we are here!"); throw new InvalidDataException("Deflate64: unknown state"); } } @@ -525,7 +659,6 @@ namespace SharpCompress.Compressors.Deflate64 return true; } - // Format of the dynamic block header: // 5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286) // 5 Bits: HDIST, # of Distance codes - 1 (1 - 32) @@ -714,7 +847,8 @@ namespace SharpCompress.Compressors.Deflate64 break; default: - Debug./*Fail*/Assert(false, "check why we are here!"); + Debug. /*Fail*/ + Assert(false, "check why we are here!"); throw new InvalidDataException("Deflate64: unknown state"); } @@ -723,7 +857,13 @@ namespace SharpCompress.Compressors.Deflate64 // Create literal and distance tables Array.Copy(_codeList, literalTreeCodeLength, _literalLengthCodeCount); - Array.Copy(_codeList, _literalLengthCodeCount, distanceTreeCodeLength, 0, _distanceCodeCount); + 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.END_OF_BLOCK_CODE] == 0) diff --git a/src/SharpCompress/Compressors/Deflate64/InflaterState.cs b/src/SharpCompress/Compressors/Deflate64/InflaterState.cs index 356ea88f..64450931 100644 --- a/src/SharpCompress/Compressors/Deflate64/InflaterState.cs +++ b/src/SharpCompress/Compressors/Deflate64/InflaterState.cs @@ -7,22 +7,22 @@ namespace SharpCompress.Compressors.Deflate64 // Do not rearrange the enum values. internal enum InflaterState { - ReadingHeader = 0, // Only applies to GZIP + ReadingHeader = 0, // Only applies to GZIP - ReadingBFinal = 2, // About to read bfinal bit - ReadingBType = 3, // About to read blockType bits + ReadingBFinal = 2, // About to read bfinal bit + ReadingBType = 3, // About to read blockType bits - ReadingNumLitCodes = 4, // About to read # literal codes - ReadingNumDistCodes = 5, // About to read # dist codes - ReadingNumCodeLengthCodes = 6, // About to read # code length codes - ReadingCodeLengthCodes = 7, // In the middle of reading the code length codes - ReadingTreeCodesBefore = 8, // In the middle of reading tree codes (loop top) - ReadingTreeCodesAfter = 9, // In the middle of reading tree codes (extension; code > 15) + ReadingNumLitCodes = 4, // About to read # literal codes + ReadingNumDistCodes = 5, // About to read # dist codes + ReadingNumCodeLengthCodes = 6, // About to read # code length codes + ReadingCodeLengthCodes = 7, // In the middle of reading the code length codes + ReadingTreeCodesBefore = 8, // In the middle of reading tree codes (loop top) + ReadingTreeCodesAfter = 9, // In the middle of reading tree codes (extension; code > 15) - DecodeTop = 10, // About to decode a literal (char/match) in a compressed block - HaveInitialLength = 11, // Decoding a match, have the literal code (base length) - HaveFullLength = 12, // Ditto, now have the full match length (incl. extra length bits) - HaveDistCode = 13, // Ditto, now have the distance code also, need extra dist bits + DecodeTop = 10, // About to decode a literal (char/match) in a compressed block + HaveInitialLength = 11, // Decoding a match, have the literal code (base length) + HaveFullLength = 12, // Ditto, now have the full match length (incl. extra length bits) + HaveDistCode = 13, // Ditto, now have the distance code also, need extra dist bits /* uncompressed blocks */ UncompressedAligning = 15, @@ -33,7 +33,7 @@ namespace SharpCompress.Compressors.Deflate64 DecodingUncompressed = 20, // These three apply only to GZIP - StartReadingFooter = 21, // (Initialisation for reading footer) + StartReadingFooter = 21, // (Initialisation for reading footer) ReadingFooter = 22, VerifyingFooter = 23, diff --git a/src/SharpCompress/Compressors/Deflate64/InputBuffer.cs b/src/SharpCompress/Compressors/Deflate64/InputBuffer.cs index 931a22fa..a7357565 100644 --- a/src/SharpCompress/Compressors/Deflate64/InputBuffer.cs +++ b/src/SharpCompress/Compressors/Deflate64/InputBuffer.cs @@ -21,11 +21,11 @@ namespace SharpCompress.Compressors.Deflate64 internal sealed class InputBuffer { - private byte[] _buffer; // byte array to store input - private int _start; // start poisition of the buffer - private int _end; // end position of the buffer - private uint _bitBuffer = 0; // store the bits here, we can quickly shift in this buffer - private int _bitsInBuffer = 0; // number of bits available in bitBuffer + private byte[] _buffer; // byte array to store input + private int _start; // start poisition of the buffer + private int _end; // end position of the buffer + private uint _bitBuffer = 0; // store the bits here, we can quickly shift in this buffer + private int _bitsInBuffer = 0; // number of bits available in bitBuffer /// Total bits available in the input buffer. public int AvailableBits => _bitsInBuffer; @@ -189,7 +189,10 @@ namespace SharpCompress.Compressors.Deflate64 /// Skip n bits in the buffer. public void SkipBits(int n) { - Debug.Assert(_bitsInBuffer >= n, "No enough bits in the buffer, Did you call EnsureBitsAvailable?"); + Debug.Assert( + _bitsInBuffer >= n, + "No enough bits in the buffer, Did you call EnsureBitsAvailable?" + ); _bitBuffer >>= n; _bitsInBuffer -= n; } diff --git a/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs b/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs index 13bf90c2..d48cd5fb 100644 --- a/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs +++ b/src/SharpCompress/Compressors/Deflate64/OutputWindow.cs @@ -17,13 +17,13 @@ namespace SharpCompress.Compressors.Deflate64 internal sealed class OutputWindow { // 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 + // 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 WINDOW_SIZE = 262144; private const int WINDOW_MASK = 262143; 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 _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. @@ -137,14 +137,16 @@ namespace SharpCompress.Compressors.Deflate64 { // this means we need to copy two parts separately // copy tailLen bytes from the end of output window - Array.Copy(_window, WINDOW_SIZE - tailLen, - output, offset, tailLen); + Array.Copy(_window, WINDOW_SIZE - tailLen, output, offset, tailLen); offset += tailLen; length = copyEnd; } 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"); + 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/Filters/BCJ2Filter.cs b/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs index d767cd6c..636f5dc0 100644 --- a/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs +++ b/src/SharpCompress/Compressors/Filters/BCJ2Filter.cs @@ -25,7 +25,8 @@ namespace SharpCompress.Compressors.Filters private int _data2Pos; private readonly ushort[] _p = new ushort[256 + 2]; - private uint _range, _code; + private uint _range, + _code; private byte _prevByte; private bool _isDisposed; @@ -91,7 +92,11 @@ namespace SharpCompress.Compressors.Filters public override long Length => _baseStream.Length + _data1.Length + _data2.Length; - public override long Position { get => _position; set => throw new NotSupportedException(); } + public override long Position + { + get => _position; + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -176,17 +181,21 @@ namespace SharpCompress.Compressors.Filters uint dest; if (b == 0xE8) { - dest = - (uint) - ((_data1[_data1Pos++] << 24) | (_data1[_data1Pos++] << 16) | (_data1[_data1Pos++] << 8) | - _data1[_data1Pos++]); + dest = (uint)( + (_data1[_data1Pos++] << 24) + | (_data1[_data1Pos++] << 16) + | (_data1[_data1Pos++] << 8) + | _data1[_data1Pos++] + ); } else { - dest = - (uint) - ((_data2[_data2Pos++] << 24) | (_data2[_data2Pos++] << 16) | (_data2[_data2Pos++] << 8) | - _data2[_data2Pos++]); + dest = (uint)( + (_data2[_data2Pos++] << 24) + | (_data2[_data2Pos++] << 16) + | (_data2[_data2Pos++] << 8) + | _data2[_data2Pos++] + ); } dest -= (uint)(_position + 4); @@ -218,4 +227,4 @@ namespace SharpCompress.Compressors.Filters throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Filters/BCJFilter.cs b/src/SharpCompress/Compressors/Filters/BCJFilter.cs index 4bc6bb2e..57b025a8 100644 --- a/src/SharpCompress/Compressors/Filters/BCJFilter.cs +++ b/src/SharpCompress/Compressors/Filters/BCJFilter.cs @@ -4,15 +4,24 @@ namespace SharpCompress.Compressors.Filters { internal class BCJFilter : Filter { - private static readonly bool[] MASK_TO_ALLOWED_STATUS = { true, true, true, false, true, false, false, false }; + private static readonly bool[] MASK_TO_ALLOWED_STATUS = + { + true, + true, + true, + false, + true, + false, + false, + false + }; private static readonly int[] MASK_TO_BIT_NUMBER = { 0, 1, 2, 2, 3, 3, 3, 3 }; private int _pos; private int _prevMask; - public BCJFilter(bool isEncoder, Stream baseStream) - : base(isEncoder, baseStream, 5) + public BCJFilter(bool isEncoder, Stream baseStream) : base(isEncoder, baseStream, 5) { _pos = 5; } @@ -46,8 +55,10 @@ namespace SharpCompress.Compressors.Filters _prevMask = (_prevMask << (prevPos - 1)) & 7; if (_prevMask != 0) { - if (!MASK_TO_ALLOWED_STATUS[_prevMask] || Test86MsByte( - buffer[i + 4 - MASK_TO_BIT_NUMBER[_prevMask]])) + if ( + !MASK_TO_ALLOWED_STATUS[_prevMask] + || Test86MsByte(buffer[i + 4 - MASK_TO_BIT_NUMBER[_prevMask]]) + ) { prevPos = i; _prevMask = (_prevMask << 1) | 1; @@ -60,10 +71,11 @@ namespace SharpCompress.Compressors.Filters if (Test86MsByte(buffer[i + 4])) { - int src = buffer[i + 1] - | (buffer[i + 2] << 8) - | (buffer[i + 3] << 16) - | (buffer[i + 4] << 24); + int src = + buffer[i + 1] + | (buffer[i + 2] << 8) + | (buffer[i + 3] << 16) + | (buffer[i + 4] << 24); int dest; while (true) { @@ -110,4 +122,4 @@ namespace SharpCompress.Compressors.Filters return i; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs b/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs index 02f92ac5..6e8278cb 100644 --- a/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs +++ b/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs @@ -26,8 +26,8 @@ namespace SharpCompress.Compressors.Filters ARCH_SPARC_ALIGNMENT = 4, } - public static void X86Converter(byte[] data, UInt32 ip, ref UInt32 state) { - + public static void X86Converter(byte[] data, UInt32 ip, ref UInt32 state) + { long i = 0; long size = data.Length; UInt32 pos = 0; @@ -36,11 +36,11 @@ namespace SharpCompress.Compressors.Filters return; size -= 4; ip += 5; - - for (;;) + + for (; ; ) { i = pos; - + for (; i < size; i++) { if ((data[i] & 0xFE) == 0xE8) @@ -63,17 +63,28 @@ namespace SharpCompress.Compressors.Filters else { mask >>= (int)d; - if (mask != 0 && (mask > 4 || mask == 3 || (((((data[(UInt32)(mask >> 1) + 1])) + 1) & 0xFE) == 0) )) + if ( + mask != 0 + && ( + mask > 4 + || mask == 3 + || (((((data[(UInt32)(mask >> 1) + 1])) + 1) & 0xFE) == 0) + ) + ) { mask = (mask >> 1) | 4; pos++; continue; } } - + if ((((data[i + 4]) + 1) & 0xFE) == 0) { - UInt32 inst = ((UInt32)data[i + 4] << 24) | ((UInt32)data[i + 3] << 16) | ((UInt32)data[i + 2] << 8) | ((UInt32)data[i + 1]); + UInt32 inst = + ((UInt32)data[i + 4] << 24) + | ((UInt32)data[i + 3] << 16) + | ((UInt32)data[i + 2] << 8) + | ((UInt32)data[i + 1]); UInt32 cur = ip + (UInt32)pos; pos += 5; @@ -108,9 +119,9 @@ namespace SharpCompress.Compressors.Filters size &= ~(UInt32)3; ip -= 4; - for (;; ) // infinite loop + for (; ; ) // infinite loop { - for (;; ) // infinite loop + for (; ; ) // infinite loop { if (i >= size) return; @@ -143,9 +154,9 @@ namespace SharpCompress.Compressors.Filters size &= ~(UInt32)3; ip += 4; - for (;;) // infinite loop + for (; ; ) // infinite loop { - for (;;) // infinite loop + for (; ; ) // infinite loop { if (i >= size) { @@ -175,10 +186,10 @@ namespace SharpCompress.Compressors.Filters size &= ~(UInt32)1; long lim = size - 4; - for (;;) + for (; ; ) { UInt32 b1; - for (;;) + for (; ; ) { UInt32 b3; if (i > lim) @@ -191,21 +202,21 @@ namespace SharpCompress.Compressors.Filters break; } - UInt32 inst = ((UInt32)b1 << 19) - + (((UInt32)data[i + 1] & 0x7) << 8) - + (((UInt32)data[i - 2] << 11)) - + (data[i]); - - i += 2; + UInt32 inst = + ((UInt32)b1 << 19) + + (((UInt32)data[i + 1] & 0x7) << 8) + + (((UInt32)data[i - 2] << 11)) + + (data[i]); - UInt32 cur = ((UInt32)(ip + i)) >> 1; - inst -= cur; + i += 2; - - data[i - 4] = (Byte)(inst >> 11); - data[i - 3] = (Byte)(0xF0 | ((inst >> 19) & 0x7)); - data[i - 2] = (Byte)inst; - data[i - 1] = (Byte)(0xF8 | (inst >> 8)); + UInt32 cur = ((UInt32)(ip + i)) >> 1; + inst -= cur; + + data[i - 4] = (Byte)(inst >> 11); + data[i - 3] = (Byte)(0xF0 | ((inst >> 19) & 0x7)); + data[i - 2] = (Byte)inst; + data[i - 1] = (Byte)(0xF8 | (inst >> 8)); } } @@ -225,9 +236,14 @@ namespace SharpCompress.Compressors.Filters m++; do { - UInt32 iterator = (UInt32)( (i + (m * 5) - 8)); - if (((data[iterator + 3] >> (int)m) & 15) == 5 - && (((data[iterator - 1] | ((UInt32)data[iterator] << 8)) >> (int)m) & 0x70) == 0) + UInt32 iterator = (UInt32)((i + (m * 5) - 8)); + if ( + ((data[iterator + 3] >> (int)m) & 15) == 5 + && ( + ((data[iterator - 1] | ((UInt32)data[iterator] << 8)) >> (int)m) + & 0x70 + ) == 0 + ) { UInt32 raw = BitConverter.ToUInt32(data, (int)iterator); UInt32 inst = raw >> (int)m; @@ -245,12 +261,10 @@ namespace SharpCompress.Compressors.Filters Utility.SetLittleUInt32(ref data, raw, iterator); } - } - while (++m <= 4); + } while (++m <= 4); } i += 16; - } - while (i <= size); + } while (i <= size); return; } @@ -261,19 +275,21 @@ namespace SharpCompress.Compressors.Filters size &= ~(UInt32)3; ip -= 4; - for (;;) // infinite loop + for (; ; ) // infinite loop { - for (;;) // infinite loop + for (; ; ) // infinite loop { if (i >= size) return; i += 4; - if ((data[i - 4] == 0x40 && (data[i - 3] & 0xC0) == 0) || - (data[i - 4] == 0x7F && (data[i - 3] >= 0xC0))) + if ( + (data[i - 4] == 0x40 && (data[i - 3] & 0xC0) == 0) + || (data[i - 4] == 0x7F && (data[i - 3] >= 0xC0)) + ) break; } - + UInt32 inst = BitConverter.ToUInt32(data, (int)i - 4); if (BitConverter.IsLittleEndian) diff --git a/src/SharpCompress/Compressors/Filters/Filter.cs b/src/SharpCompress/Compressors/Filters/Filter.cs index b7fd8159..1ee8c076 100644 --- a/src/SharpCompress/Compressors/Filters/Filter.cs +++ b/src/SharpCompress/Compressors/Filters/Filter.cs @@ -47,7 +47,11 @@ namespace SharpCompress.Compressors.Filters public override long Length => _baseStream.Length; - public override long Position { get => _baseStream.Position; set => throw new NotSupportedException(); } + public override long Position + { + get => _baseStream.Position; + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -151,4 +155,4 @@ namespace SharpCompress.Compressors.Filters protected abstract int Transform(byte[] buffer, int offset, int count); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs index 3e44ff89..a3c47462 100644 --- a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs @@ -22,7 +22,9 @@ namespace SharpCompress.Compressors.LZMA { if (pass.CryptoGetTextPassword() == null) { - throw new SharpCompress.Common.CryptographicException("Encrypted 7Zip archive has no password specified."); + throw new SharpCompress.Common.CryptographicException( + "Encrypted 7Zip archive has no password specified." + ); } mStream = input; @@ -79,8 +81,7 @@ namespace SharpCompress.Compressors.LZMA public override int Read(byte[] buffer, int offset, int count) { - if (count == 0 - || mWritten == mLimit) + if (count == 0 || mWritten == mLimit) { return 0; } @@ -107,8 +108,7 @@ namespace SharpCompress.Compressors.LZMA } mEnding += read; - } - while (mEnding - mOffset < 16); + } while (mEnding - mOffset < 16); } // We shouldn't return more data than we are limited to. diff --git a/src/SharpCompress/Compressors/LZMA/Bcj2DecoderStream.cs b/src/SharpCompress/Compressors/LZMA/Bcj2DecoderStream.cs index 62a7ad65..649801a3 100644 --- a/src/SharpCompress/Compressors/LZMA/Bcj2DecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/Bcj2DecoderStream.cs @@ -149,14 +149,12 @@ namespace SharpCompress.Compressors.LZMA private static bool IsJcc(byte b0, byte b1) { - return b0 == 0x0F - && (b1 & 0xF0) == 0x80; + return b0 == 0x0F && (b1 & 0xF0) == 0x80; } private static bool IsJ(byte b0, byte b1) { - return (b1 & 0xFE) == 0xE8 - || IsJcc(b0, b1); + return (b1 & 0xFE) == 0xE8 || IsJcc(b0, b1); } private static int GetIndex(byte b0, byte b1) @@ -280,4 +278,4 @@ namespace SharpCompress.Compressors.LZMA } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/BitVector.cs b/src/SharpCompress/Compressors/LZMA/BitVector.cs index 9f267f72..5995512a 100644 --- a/src/SharpCompress/Compressors/LZMA/BitVector.cs +++ b/src/SharpCompress/Compressors/LZMA/BitVector.cs @@ -28,8 +28,7 @@ namespace SharpCompress.Compressors.LZMA } } - public BitVector(List bits) - : this(bits.Count) + public BitVector(List bits) : this(bits.Count) { for (int i = 0; i < bits.Count; i++) { @@ -98,4 +97,4 @@ namespace SharpCompress.Compressors.LZMA return sb.ToString(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/CRC.cs b/src/SharpCompress/Compressors/LZMA/CRC.cs index 2ee0600a..478cb944 100644 --- a/src/SharpCompress/Compressors/LZMA/CRC.cs +++ b/src/SharpCompress/Compressors/LZMA/CRC.cs @@ -61,9 +61,9 @@ namespace SharpCompress.Compressors.LZMA { crc ^= value; return TABLE[0x300 + (crc & 0xFF)] - ^ TABLE[0x200 + ((crc >> 8) & 0xFF)] - ^ TABLE[0x100 + ((crc >> 16) & 0xFF)] - ^ TABLE[0x000 + (crc >> 24)]; + ^ TABLE[0x200 + ((crc >> 8) & 0xFF)] + ^ TABLE[0x100 + ((crc >> 16) & 0xFF)] + ^ TABLE[0x000 + (crc >> 24)]; } public static uint Update(uint crc, ulong value) @@ -86,4 +86,4 @@ namespace SharpCompress.Compressors.LZMA return crc; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs index 1921ebab..084e2a5f 100644 --- a/src/SharpCompress/Compressors/LZMA/DecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/DecoderStream.cs @@ -21,7 +21,11 @@ namespace SharpCompress.Compressors.LZMA public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override long Seek(long offset, SeekOrigin origin) { @@ -56,20 +60,27 @@ namespace SharpCompress.Compressors.LZMA throw new InvalidOperationException("Could not link output stream to coder."); } - private static void FindPrimaryOutStreamIndex(CFolder folderInfo, out int primaryCoderIndex, - out int primaryOutStreamIndex) + private static void FindPrimaryOutStreamIndex( + CFolder folderInfo, + out int primaryCoderIndex, + out int primaryOutStreamIndex + ) { bool foundPrimaryOutStream = false; primaryCoderIndex = -1; primaryOutStreamIndex = -1; - for (int outStreamIndex = 0, coderIndex = 0; - coderIndex < folderInfo._coders.Count; - coderIndex++) + for ( + int outStreamIndex = 0, coderIndex = 0; + coderIndex < folderInfo._coders.Count; + coderIndex++ + ) { - for (int coderOutStreamIndex = 0; - coderOutStreamIndex < folderInfo._coders[coderIndex]._numOutStreams; - coderOutStreamIndex++, outStreamIndex++) + for ( + int coderOutStreamIndex = 0; + coderOutStreamIndex < folderInfo._coders[coderIndex]._numOutStreams; + coderOutStreamIndex++, outStreamIndex++ + ) { if (folderInfo.FindBindPairForOutStream(outStreamIndex) < 0) { @@ -91,8 +102,14 @@ namespace SharpCompress.Compressors.LZMA } } - private static Stream CreateDecoderStream(Stream[] packStreams, long[] packSizes, Stream[] outStreams, - CFolder folderInfo, int coderIndex, IPasswordProvider pass) + 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) @@ -123,18 +140,31 @@ namespace SharpCompress.Compressors.LZMA if (outStreams[pairedOutIndex] != null) { - throw new NotSupportedException("Overlapping stream bindings are not supported."); + throw new NotSupportedException( + "Overlapping stream bindings are not supported." + ); } - int otherCoderIndex = FindCoderIndexForOutStreamIndex(folderInfo, pairedOutIndex); - inStreams[i] = CreateDecoderStream(packStreams, packSizes, outStreams, folderInfo, otherCoderIndex, - pass); + int otherCoderIndex = FindCoderIndexForOutStreamIndex( + folderInfo, + pairedOutIndex + ); + inStreams[i] = CreateDecoderStream( + packStreams, + packSizes, + outStreams, + folderInfo, + otherCoderIndex, + pass + ); //inStreamSizes[i] = folderInfo.UnpackSizes[pairedOutIndex]; if (outStreams[pairedOutIndex] != null) { - throw new NotSupportedException("Overlapping stream bindings are not supported."); + throw new NotSupportedException( + "Overlapping stream bindings are not supported." + ); } outStreams[pairedOutIndex] = inStreams[i]; @@ -154,11 +184,22 @@ namespace SharpCompress.Compressors.LZMA } long unpackSize = folderInfo._unpackSizes[outStreamId]; - return DecoderRegistry.CreateDecoderStream(coderInfo._methodId, inStreams, coderInfo._props, pass, unpackSize); + return DecoderRegistry.CreateDecoderStream( + coderInfo._methodId, + inStreams, + coderInfo._props, + pass, + unpackSize + ); } - internal static Stream CreateDecoderStream(Stream inStream, long startPos, long[] packSizes, CFolder folderInfo, - IPasswordProvider pass) + internal static Stream CreateDecoderStream( + Stream inStream, + long startPos, + long[] packSizes, + CFolder folderInfo, + IPasswordProvider pass + ) { if (!folderInfo.CheckStructure()) { @@ -174,9 +215,17 @@ namespace SharpCompress.Compressors.LZMA Stream[] outStreams = new Stream[folderInfo._unpackSizes.Count]; - int primaryCoderIndex, primaryOutStreamIndex; + int primaryCoderIndex, + primaryOutStreamIndex; FindPrimaryOutStreamIndex(folderInfo, out primaryCoderIndex, out primaryOutStreamIndex); - return CreateDecoderStream(inStreams, packSizes, outStreams, folderInfo, primaryCoderIndex, pass); + return CreateDecoderStream( + inStreams, + packSizes, + outStreams, + folderInfo, + primaryCoderIndex, + pass + ); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/ICoder.cs b/src/SharpCompress/Compressors/LZMA/ICoder.cs index 3ae84f48..a571ddc5 100644 --- a/src/SharpCompress/Compressors/LZMA/ICoder.cs +++ b/src/SharpCompress/Compressors/LZMA/ICoder.cs @@ -8,10 +8,7 @@ namespace SharpCompress.Compressors.LZMA /// internal class DataErrorException : Exception { - public DataErrorException() - : base("Data Error") - { - } + public DataErrorException() : base("Data Error") { } } /// @@ -19,10 +16,7 @@ namespace SharpCompress.Compressors.LZMA /// internal class InvalidParamException : Exception { - public InvalidParamException() - : base("Invalid Parameter") - { - } + public InvalidParamException() : base("Invalid Parameter") { } } public interface ICodeProgress @@ -59,16 +53,21 @@ namespace SharpCompress.Compressors.LZMA /// /// callback progress reference. /// - void Code(Stream inStream, Stream outStream, - Int64 inSize, Int64 outSize, ICodeProgress progress); + void Code( + Stream inStream, + Stream outStream, + Int64 inSize, + Int64 outSize, + ICodeProgress progress + ); } /* public interface ICoder2 { void Code(ISequentialInStream []inStreams, - const UInt64 []inSizes, - ISequentialOutStream []outStreams, + const UInt64 []inSizes, + ISequentialOutStream []outStreams, UInt64 []outSizes, ICodeProgress progress); }; diff --git a/src/SharpCompress/Compressors/LZMA/LZ/LzBinTree.cs b/src/SharpCompress/Compressors/LZMA/LZ/LzBinTree.cs index 37c70720..6d630b59 100644 --- a/src/SharpCompress/Compressors/LZMA/LZ/LzBinTree.cs +++ b/src/SharpCompress/Compressors/LZMA/LZ/LzBinTree.cs @@ -98,8 +98,12 @@ namespace SharpCompress.Compressors.LZMA.LZ return base.GetNumAvailableBytes(); } - public void Create(UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter) + public void Create( + UInt32 historySize, + UInt32 keepAddBufferBefore, + UInt32 matchMaxLen, + UInt32 keepAddBufferAfter + ) { if (historySize > K_MAX_VAL_FOR_NORMALIZE - 256) { @@ -107,10 +111,14 @@ namespace SharpCompress.Compressors.LZMA.LZ } _cutValue = 16 + (matchMaxLen >> 1); - UInt32 windowReservSize = (historySize + keepAddBufferBefore + - matchMaxLen + keepAddBufferAfter) / 2 + 256; + UInt32 windowReservSize = + (historySize + keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + 256; - base.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize); + base.Create( + historySize + keepAddBufferBefore, + matchMaxLen + keepAddBufferAfter, + windowReservSize + ); _matchMaxLen = matchMaxLen; @@ -166,7 +174,9 @@ namespace SharpCompress.Compressors.LZMA.LZ UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0; UInt32 cur = _bufferOffset + _pos; UInt32 maxLen = K_START_MAX_LEN; // to avoid items for len < hashSize; - UInt32 hashValue, hash2Value = 0, hash3Value = 0; + UInt32 hashValue, + hash2Value = 0, + hash3Value = 0; if (_hashArray) { @@ -221,15 +231,18 @@ namespace SharpCompress.Compressors.LZMA.LZ UInt32 ptr0 = (_cyclicBufferPos << 1) + 1; UInt32 ptr1 = (_cyclicBufferPos << 1); - UInt32 len0, len1; + UInt32 len0, + len1; len0 = len1 = _kNumHashDirectBytes; if (_kNumHashDirectBytes != 0) { if (curMatch > matchMinPos) { - if (_bufferBase[_bufferOffset + curMatch + _kNumHashDirectBytes] != - _bufferBase[cur + _kNumHashDirectBytes]) + if ( + _bufferBase[_bufferOffset + curMatch + _kNumHashDirectBytes] + != _bufferBase[cur + _kNumHashDirectBytes] + ) { distances[offset++] = maxLen = _kNumHashDirectBytes; distances[offset++] = _pos - curMatch - 1; @@ -247,9 +260,12 @@ namespace SharpCompress.Compressors.LZMA.LZ break; } UInt32 delta = _pos - curMatch; - UInt32 cyclicPos = ((delta <= _cyclicBufferPos) - ? (_cyclicBufferPos - delta) - : (_cyclicBufferPos - delta + _cyclicBufferSize)) << 1; + UInt32 cyclicPos = + ( + (delta <= _cyclicBufferPos) + ? (_cyclicBufferPos - delta) + : (_cyclicBufferPos - delta + _cyclicBufferSize) + ) << 1; UInt32 pby1 = _bufferOffset + curMatch; UInt32 len = Math.Min(len0, len1); @@ -338,7 +354,8 @@ namespace SharpCompress.Compressors.LZMA.LZ UInt32 ptr0 = (_cyclicBufferPos << 1) + 1; UInt32 ptr1 = (_cyclicBufferPos << 1); - UInt32 len0, len1; + UInt32 len0, + len1; len0 = len1 = _kNumHashDirectBytes; UInt32 count = _cutValue; @@ -351,9 +368,12 @@ namespace SharpCompress.Compressors.LZMA.LZ } UInt32 delta = _pos - curMatch; - UInt32 cyclicPos = ((delta <= _cyclicBufferPos) - ? (_cyclicBufferPos - delta) - : (_cyclicBufferPos - delta + _cyclicBufferSize)) << 1; + UInt32 cyclicPos = + ( + (delta <= _cyclicBufferPos) + ? (_cyclicBufferPos - delta) + : (_cyclicBufferPos - delta + _cyclicBufferSize) + ) << 1; UInt32 pby1 = _bufferOffset + curMatch; UInt32 len = Math.Min(len0, len1); @@ -389,8 +409,7 @@ namespace SharpCompress.Compressors.LZMA.LZ } } MovePos(); - } - while (--num != 0); + } while (--num != 0); } private void NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue) diff --git a/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs b/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs index 9ce2121a..943009d2 100644 --- a/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs +++ b/src/SharpCompress/Compressors/LZMA/LZ/LzInWindow.cs @@ -55,9 +55,10 @@ namespace SharpCompress.Compressors.LZMA.LZ { return; } - int numReadBytes = _stream != null - ? _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size) - : 0; + int numReadBytes = + _stream != null + ? _stream.Read(_bufferBase, (int)(_bufferOffset + _streamPos), size) + : 0; if (numReadBytes == 0) { _posLimit = _streamPos; @@ -182,4 +183,4 @@ namespace SharpCompress.Compressors.LZMA.LZ public bool IsDataStarved => _streamPos - _pos < _keepSizeAfter; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs b/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs index 483b3a98..6542ff91 100644 --- a/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs +++ b/src/SharpCompress/Compressors/LZMA/LZ/LzOutWindow.cs @@ -204,4 +204,4 @@ namespace SharpCompress.Compressors.LZMA.LZ public int AvailableBytes => _pos - _streamPos; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/LZipStream.cs b/src/SharpCompress/Compressors/LZMA/LZipStream.cs index a736bca1..912e4eff 100644 --- a/src/SharpCompress/Compressors/LZMA/LZipStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LZipStream.cs @@ -44,7 +44,13 @@ namespace SharpCompress.Compressors.LZMA WriteHeaderSize(stream); _countingWritableSubStream = new CountingWritableSubStream(stream); - _stream = new Crc32Stream(new LzmaStream(new LzmaEncoderProperties(true, dSize), false, _countingWritableSubStream)); + _stream = new Crc32Stream( + new LzmaStream( + new LzmaEncoderProperties(true, dSize), + false, + _countingWritableSubStream + ) + ); } } @@ -107,17 +113,22 @@ namespace SharpCompress.Compressors.LZMA // reading the output length when we initialize. public override long Length => throw new NotImplementedException(); - public override long Position { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public override long Position + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } - public override int Read(byte[] buffer, int offset, int count) => _stream.Read(buffer, offset, count); + public override int Read(byte[] buffer, int offset, int count) => + _stream.Read(buffer, offset, count); public override int ReadByte() => _stream.ReadByte(); - public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) => + throw new NotSupportedException(); public override void SetLength(long value) => throw new NotImplementedException(); - #if !NETFRAMEWORK && !NETSTANDARD2_0 public override int Read(Span buffer) @@ -131,7 +142,6 @@ namespace SharpCompress.Compressors.LZMA _writeCount += buffer.Length; } - #endif public override void Write(byte[] buffer, int offset, int count) @@ -180,7 +190,13 @@ namespace SharpCompress.Compressors.LZMA return 0; } - if (header[0] != 'L' || header[1] != 'Z' || header[2] != 'I' || header[3] != 'P' || header[4] != 1 /* version 1 */) + if ( + header[0] != 'L' + || header[1] != 'Z' + || header[2] != 'I' + || header[3] != 'P' + || header[4] != 1 /* version 1 */ + ) { return 0; } @@ -189,7 +205,15 @@ namespace SharpCompress.Compressors.LZMA return (1 << basePower) - subtractionNumerator * (1 << (basePower - 4)); } - private static readonly byte[] headerBytes = new byte[6] { (byte)'L', (byte)'Z', (byte)'I', (byte)'P', 1, 113 }; + private static readonly byte[] headerBytes = new byte[6] + { + (byte)'L', + (byte)'Z', + (byte)'I', + (byte)'P', + 1, + 113 + }; public static void WriteHeaderSize(Stream stream) { diff --git a/src/SharpCompress/Compressors/LZMA/Log.cs b/src/SharpCompress/Compressors/LZMA/Log.cs index f4cbed5e..a31d2b69 100644 --- a/src/SharpCompress/Compressors/LZMA/Log.cs +++ b/src/SharpCompress/Compressors/LZMA/Log.cs @@ -83,4 +83,4 @@ namespace SharpCompress.Compressors.LZMA NEEDS_INDENT = true; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/LzmaBase.cs b/src/SharpCompress/Compressors/LZMA/LzmaBase.cs index 6e2b8a5d..74ca3cfb 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaBase.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaBase.cs @@ -101,9 +101,9 @@ namespace SharpCompress.Compressors.LZMA public const uint K_NUM_LOW_LEN_SYMBOLS = 1 << K_NUM_LOW_LEN_BITS; public const uint K_NUM_MID_LEN_SYMBOLS = 1 << K_NUM_MID_LEN_BITS; - public const uint K_NUM_LEN_SYMBOLS = K_NUM_LOW_LEN_SYMBOLS + K_NUM_MID_LEN_SYMBOLS + - (1 << K_NUM_HIGH_LEN_BITS); + public const uint K_NUM_LEN_SYMBOLS = + K_NUM_LOW_LEN_SYMBOLS + K_NUM_MID_LEN_SYMBOLS + (1 << K_NUM_HIGH_LEN_BITS); public const uint K_MATCH_MAX_LEN = K_MATCH_MIN_LEN + K_NUM_LEN_SYMBOLS - 1; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs index f54c2bf7..a3841197 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaDecoder.cs @@ -13,8 +13,12 @@ namespace SharpCompress.Compressors.LZMA { private BitDecoder _choice = new BitDecoder(); private BitDecoder _choice2 = new BitDecoder(); - private readonly BitTreeDecoder[] _lowCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX]; - private readonly BitTreeDecoder[] _midCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX]; + private readonly BitTreeDecoder[] _lowCoder = new BitTreeDecoder[ + Base.K_NUM_POS_STATES_MAX + ]; + private readonly BitTreeDecoder[] _midCoder = new BitTreeDecoder[ + Base.K_NUM_POS_STATES_MAX + ]; private BitTreeDecoder _highCoder = new BitTreeDecoder(Base.K_NUM_HIGH_LEN_BITS); private uint _numPosStates; @@ -85,8 +89,7 @@ namespace SharpCompress.Compressors.LZMA do { symbol = (symbol << 1) | _decoders[symbol].Decode(rangeDecoder); - } - while (symbol < 0x100); + } while (symbol < 0x100); return (byte)symbol; } @@ -107,8 +110,7 @@ namespace SharpCompress.Compressors.LZMA } break; } - } - while (symbol < 0x100); + } while (symbol < 0x100); return (byte)symbol; } } @@ -120,8 +122,7 @@ namespace SharpCompress.Compressors.LZMA public void Create(int numPosBits, int numPrevBits) { - if (_coders != null && _numPrevBits == numPrevBits && - _numPosBits == numPosBits) + if (_coders != null && _numPrevBits == numPrevBits && _numPosBits == numPosBits) { return; } @@ -155,23 +156,39 @@ namespace SharpCompress.Compressors.LZMA return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); } - public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte) + public byte DecodeWithMatchByte( + RangeCoder.Decoder rangeDecoder, + uint pos, + byte prevByte, + byte matchByte + ) { - return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); + return _coders[GetState(pos, prevByte)].DecodeWithMatchByte( + rangeDecoder, + matchByte + ); } } private OutWindow _outWindow; - private readonly BitDecoder[] _isMatchDecoders = new BitDecoder[Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX]; + private readonly BitDecoder[] _isMatchDecoders = new BitDecoder[ + Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX + ]; private readonly BitDecoder[] _isRepDecoders = new BitDecoder[Base.K_NUM_STATES]; private readonly BitDecoder[] _isRepG0Decoders = new BitDecoder[Base.K_NUM_STATES]; private readonly BitDecoder[] _isRepG1Decoders = new BitDecoder[Base.K_NUM_STATES]; private readonly BitDecoder[] _isRepG2Decoders = new BitDecoder[Base.K_NUM_STATES]; - private readonly BitDecoder[] _isRep0LongDecoders = new BitDecoder[Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX]; + private readonly BitDecoder[] _isRep0LongDecoders = new BitDecoder[ + Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX + ]; - private readonly BitTreeDecoder[] _posSlotDecoder = new BitTreeDecoder[Base.K_NUM_LEN_TO_POS_STATES]; - private readonly BitDecoder[] _posDecoders = new BitDecoder[Base.K_NUM_FULL_DISTANCES - Base.K_END_POS_MODEL_INDEX]; + private readonly BitTreeDecoder[] _posSlotDecoder = new BitTreeDecoder[ + Base.K_NUM_LEN_TO_POS_STATES + ]; + private readonly BitDecoder[] _posDecoders = new BitDecoder[ + Base.K_NUM_FULL_DISTANCES - Base.K_END_POS_MODEL_INDEX + ]; private BitTreeDecoder _posAlignDecoder = new BitTreeDecoder(Base.K_NUM_ALIGN_BITS); @@ -185,7 +202,10 @@ namespace SharpCompress.Compressors.LZMA private uint _posStateMask; private Base.State _state = new Base.State(); - private uint _rep0, _rep1, _rep2, _rep3; + private uint _rep0, + _rep1, + _rep2, + _rep3; public Decoder() { @@ -272,8 +292,13 @@ namespace SharpCompress.Compressors.LZMA _rep3 = 0; } - public void Code(Stream inStream, Stream outStream, - Int64 inSize, Int64 outSize, ICodeProgress progress) + public void Code( + Stream inStream, + Stream outStream, + Int64 inSize, + Int64 outSize, + ICodeProgress progress + ) { if (_outWindow is null) { @@ -309,19 +334,30 @@ namespace SharpCompress.Compressors.LZMA while (outWindow.HasSpace) { uint posState = (uint)outWindow._total & _posStateMask; - if (_isMatchDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Decode(rangeDecoder) == 0) + if ( + _isMatchDecoders[ + (_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].Decode(rangeDecoder) == 0 + ) { byte b; byte prevByte = outWindow.GetByte(0); if (!_state.IsCharState()) { - b = _literalDecoder.DecodeWithMatchByte(rangeDecoder, - (uint)outWindow._total, prevByte, - outWindow.GetByte((int)_rep0)); + b = _literalDecoder.DecodeWithMatchByte( + rangeDecoder, + (uint)outWindow._total, + prevByte, + outWindow.GetByte((int)_rep0) + ); } else { - b = _literalDecoder.DecodeNormal(rangeDecoder, (uint)outWindow._total, prevByte); + b = _literalDecoder.DecodeNormal( + rangeDecoder, + (uint)outWindow._total, + prevByte + ); } outWindow.PutByte(b); _state.UpdateChar(); @@ -334,8 +370,10 @@ namespace SharpCompress.Compressors.LZMA if (_isRepG0Decoders[_state._index].Decode(rangeDecoder) == 0) { if ( - _isRep0LongDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Decode( - rangeDecoder) == 0) + _isRep0LongDecoders[ + (_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].Decode(rangeDecoder) == 0 + ) { _state.UpdateShortRep(); outWindow.PutByte(outWindow.GetByte((int)_rep0)); @@ -375,20 +413,29 @@ namespace SharpCompress.Compressors.LZMA _rep1 = _rep0; len = Base.K_MATCH_MIN_LEN + _lenDecoder.Decode(rangeDecoder, posState); _state.UpdateMatch(); - uint posSlot = _posSlotDecoder[Base.GetLenToPosState(len)].Decode(rangeDecoder); + uint posSlot = _posSlotDecoder[Base.GetLenToPosState(len)].Decode( + rangeDecoder + ); if (posSlot >= Base.K_START_POS_MODEL_INDEX) { int numDirectBits = (int)((posSlot >> 1) - 1); _rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < Base.K_END_POS_MODEL_INDEX) { - _rep0 += BitTreeDecoder.ReverseDecode(_posDecoders, - _rep0 - posSlot - 1, rangeDecoder, numDirectBits); + _rep0 += BitTreeDecoder.ReverseDecode( + _posDecoders, + _rep0 - posSlot - 1, + rangeDecoder, + numDirectBits + ); } else { - _rep0 += (rangeDecoder.DecodeDirectBits( - numDirectBits - Base.K_NUM_ALIGN_BITS) << Base.K_NUM_ALIGN_BITS); + _rep0 += ( + rangeDecoder.DecodeDirectBits( + numDirectBits - Base.K_NUM_ALIGN_BITS + ) << Base.K_NUM_ALIGN_BITS + ); _rep0 += _posAlignDecoder.ReverseDecode(rangeDecoder); } } @@ -458,7 +505,7 @@ namespace SharpCompress.Compressors.LZMA set { } } public override void Flush() { } - public override int Read(byte[] buffer, int offset, int count) + public override int Read(byte[] buffer, int offset, int count) { return 0; } diff --git a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs index 5dab5002..c1ab3b18 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs @@ -108,7 +108,11 @@ namespace SharpCompress.Compressors.LZMA } } - public void EncodeMatched(RangeCoder.Encoder rangeEncoder, byte matchByte, byte symbol) + public void EncodeMatched( + RangeCoder.Encoder rangeEncoder, + byte matchByte, + byte symbol + ) { uint context = 1; bool same = true; @@ -190,7 +194,9 @@ namespace SharpCompress.Compressors.LZMA public Encoder2 GetSubCoder(UInt32 pos, Byte prevByte) { - return _coders[((pos & _posMask) << _numPrevBits) + (uint)(prevByte >> (8 - _numPrevBits))]; + return _coders[ + ((pos & _posMask) << _numPrevBits) + (uint)(prevByte >> (8 - _numPrevBits)) + ]; } } @@ -198,8 +204,12 @@ namespace SharpCompress.Compressors.LZMA { private BitEncoder _choice = new BitEncoder(); private BitEncoder _choice2 = new BitEncoder(); - private readonly BitTreeEncoder[] _lowCoder = new BitTreeEncoder[Base.K_NUM_POS_STATES_ENCODING_MAX]; - private readonly BitTreeEncoder[] _midCoder = new BitTreeEncoder[Base.K_NUM_POS_STATES_ENCODING_MAX]; + private readonly BitTreeEncoder[] _lowCoder = new BitTreeEncoder[ + Base.K_NUM_POS_STATES_ENCODING_MAX + ]; + private readonly BitTreeEncoder[] _midCoder = new BitTreeEncoder[ + Base.K_NUM_POS_STATES_ENCODING_MAX + ]; private BitTreeEncoder _highCoder = new BitTreeEncoder(Base.K_NUM_HIGH_LEN_BITS); public LenEncoder() @@ -268,20 +278,28 @@ namespace SharpCompress.Compressors.LZMA { return; } - prices[st + i] = b0 + _midCoder[posState].GetPrice(i - Base.K_NUM_LOW_LEN_SYMBOLS); + prices[st + i] = + b0 + _midCoder[posState].GetPrice(i - Base.K_NUM_LOW_LEN_SYMBOLS); } for (; i < numSymbols; i++) { - prices[st + i] = b1 + _highCoder.GetPrice(i - Base.K_NUM_LOW_LEN_SYMBOLS - Base.K_NUM_MID_LEN_SYMBOLS); + prices[st + i] = + b1 + + _highCoder.GetPrice( + i - Base.K_NUM_LOW_LEN_SYMBOLS - Base.K_NUM_MID_LEN_SYMBOLS + ); } } } - private const UInt32 K_NUM_LEN_SPEC_SYMBOLS = Base.K_NUM_LOW_LEN_SYMBOLS + Base.K_NUM_MID_LEN_SYMBOLS; + private const UInt32 K_NUM_LEN_SPEC_SYMBOLS = + Base.K_NUM_LOW_LEN_SYMBOLS + Base.K_NUM_MID_LEN_SYMBOLS; private class LenPriceTableEncoder : LenEncoder { - private readonly UInt32[] _prices = new UInt32[Base.K_NUM_LEN_SYMBOLS << Base.K_NUM_POS_STATES_BITS_ENCODING_MAX]; + private readonly UInt32[] _prices = new UInt32[ + Base.K_NUM_LEN_SYMBOLS << Base.K_NUM_POS_STATES_BITS_ENCODING_MAX + ]; private UInt32 _tableSize; private readonly UInt32[] _counters = new UInt32[Base.K_NUM_POS_STATES_ENCODING_MAX]; @@ -363,21 +381,26 @@ namespace SharpCompress.Compressors.LZMA private BinTree _matchFinder; private readonly RangeCoder.Encoder _rangeEncoder = new RangeCoder.Encoder(); - private readonly BitEncoder[] _isMatch = - new BitEncoder[Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX]; + private readonly BitEncoder[] _isMatch = new BitEncoder[ + Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX + ]; private readonly BitEncoder[] _isRep = new BitEncoder[Base.K_NUM_STATES]; private readonly BitEncoder[] _isRepG0 = new BitEncoder[Base.K_NUM_STATES]; private readonly BitEncoder[] _isRepG1 = new BitEncoder[Base.K_NUM_STATES]; private readonly BitEncoder[] _isRepG2 = new BitEncoder[Base.K_NUM_STATES]; - private readonly BitEncoder[] _isRep0Long = - new BitEncoder[Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX]; + private readonly BitEncoder[] _isRep0Long = new BitEncoder[ + Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX + ]; - private readonly BitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[Base.K_NUM_LEN_TO_POS_STATES]; + private readonly BitTreeEncoder[] _posSlotEncoder = new BitTreeEncoder[ + Base.K_NUM_LEN_TO_POS_STATES + ]; - private readonly BitEncoder[] _posEncoders = - new BitEncoder[Base.K_NUM_FULL_DISTANCES - Base.K_END_POS_MODEL_INDEX]; + private readonly BitEncoder[] _posEncoders = new BitEncoder[ + Base.K_NUM_FULL_DISTANCES - Base.K_END_POS_MODEL_INDEX + ]; private BitTreeEncoder _posAlignEncoder = new BitTreeEncoder(Base.K_NUM_ALIGN_BITS); @@ -399,8 +422,12 @@ namespace SharpCompress.Compressors.LZMA private bool _longestMatchWasFound; - private readonly UInt32[] _posSlotPrices = new UInt32[1 << (Base.K_NUM_POS_SLOT_BITS + Base.K_NUM_LEN_TO_POS_STATES_BITS)]; - private readonly UInt32[] _distancesPrices = new UInt32[Base.K_NUM_FULL_DISTANCES << Base.K_NUM_LEN_TO_POS_STATES_BITS]; + private readonly UInt32[] _posSlotPrices = new UInt32[ + 1 << (Base.K_NUM_POS_SLOT_BITS + Base.K_NUM_LEN_TO_POS_STATES_BITS) + ]; + private readonly UInt32[] _distancesPrices = new UInt32[ + Base.K_NUM_FULL_DISTANCES << Base.K_NUM_LEN_TO_POS_STATES_BITS + ]; private readonly UInt32[] _alignPrices = new UInt32[Base.K_ALIGN_TABLE_SIZE]; private UInt32 _alignPriceCount; @@ -444,7 +471,12 @@ namespace SharpCompress.Compressors.LZMA { return; } - _matchFinder.Create(_dictionarySize, K_NUM_OPTS, _numFastBytes, Base.K_MATCH_MAX_LEN + 1 + K_NUM_OPTS); + _matchFinder.Create( + _dictionarySize, + K_NUM_OPTS, + _numFastBytes, + Base.K_MATCH_MAX_LEN + 1 + K_NUM_OPTS + ); _dictionarySizePrev = _dictionarySize; _numFastBytesPrev = _numFastBytes; } @@ -515,8 +547,11 @@ namespace SharpCompress.Compressors.LZMA lenRes = _matchDistances[numDistancePairs - 2]; if (lenRes == _numFastBytes) { - lenRes += _matchFinder.GetMatchLen((int)lenRes - 1, _matchDistances[numDistancePairs - 1], - Base.K_MATCH_MAX_LEN - lenRes); + lenRes += _matchFinder.GetMatchLen( + (int)lenRes - 1, + _matchDistances[numDistancePairs - 1], + Base.K_MATCH_MAX_LEN - lenRes + ); } } _additionalOffset++; @@ -533,8 +568,10 @@ namespace SharpCompress.Compressors.LZMA private UInt32 GetRepLen1Price(Base.State state, UInt32 posState) { - return _isRepG0[state._index].GetPrice0() + - _isRep0Long[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice0(); + return _isRepG0[state._index].GetPrice0() + + _isRep0Long[ + (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].GetPrice0(); } private UInt32 GetPureRepPrice(UInt32 repIndex, Base.State state, UInt32 posState) @@ -543,7 +580,9 @@ namespace SharpCompress.Compressors.LZMA if (repIndex == 0) { price = _isRepG0[state._index].GetPrice0(); - price += _isRep0Long[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice1(); + price += _isRep0Long[ + (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].GetPrice1(); } else { @@ -577,8 +616,9 @@ namespace SharpCompress.Compressors.LZMA } else { - price = _posSlotPrices[(lenToPosState << Base.K_NUM_POS_SLOT_BITS) + GetPosSlot2(pos)] + - _alignPrices[pos & Base.K_ALIGN_MASK]; + price = + _posSlotPrices[(lenToPosState << Base.K_NUM_POS_SLOT_BITS) + GetPosSlot2(pos)] + + _alignPrices[pos & Base.K_ALIGN_MASK]; } return price + _lenEncoder.GetPrice(len - Base.K_MATCH_MIN_LEN, posState); } @@ -610,8 +650,7 @@ namespace SharpCompress.Compressors.LZMA _optimum[posPrev]._backPrev = backCur; _optimum[posPrev]._posPrev = cur; cur = posPrev; - } - while (cur > 0); + } while (cur > 0); backRes = _optimum[0]._backPrev; _optimumCurrentIndex = _optimum[0]._posPrev; return _optimumCurrentIndex; @@ -631,7 +670,8 @@ namespace SharpCompress.Compressors.LZMA } _optimumCurrentIndex = _optimumEndIndex = 0; - UInt32 lenMain, numDistancePairs; + UInt32 lenMain, + numDistancePairs; if (!_longestMatchWasFound) { ReadMatchDistances(out lenMain, out numDistancePairs); @@ -693,12 +733,16 @@ namespace SharpCompress.Compressors.LZMA UInt32 posState = (position & _posStateMask); - _optimum[1]._price = _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice0() + - _literalEncoder.GetSubCoder(position, _previousByte) - .GetPrice(!_state.IsCharState(), matchByte, currentByte); + _optimum[1]._price = + _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice0() + + _literalEncoder + .GetSubCoder(position, _previousByte) + .GetPrice(!_state.IsCharState(), matchByte, currentByte); _optimum[1].MakeAsChar(); - UInt32 matchPrice = _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice1(); + UInt32 matchPrice = _isMatch[ + (_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].GetPrice1(); UInt32 repMatchPrice = matchPrice + _isRep[_state._index].GetPrice1(); if (matchByte == currentByte) @@ -730,8 +774,7 @@ namespace SharpCompress.Compressors.LZMA do { _optimum[len--]._price = K_IFINITY_PRICE; - } - while (len >= 2); + } while (len >= 2); for (i = 0; i < Base.K_NUM_REP_DISTANCES; i++) { @@ -743,7 +786,8 @@ namespace SharpCompress.Compressors.LZMA UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState); do { - UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState); + UInt32 curAndLenPrice = + price + _repMatchLenEncoder.GetPrice(repLen - 2, posState); Optimal optimum = _optimum[repLen]; if (curAndLenPrice < optimum._price) { @@ -752,8 +796,7 @@ namespace SharpCompress.Compressors.LZMA optimum._backPrev = i; optimum._prev1IsChar = false; } - } - while (--repLen >= 2); + } while (--repLen >= 2); } UInt32 normalMatchPrice = matchPrice + _isRep[_state._index].GetPrice0(); @@ -769,7 +812,8 @@ namespace SharpCompress.Compressors.LZMA for (; ; len++) { UInt32 distance = _matchDistances[offs + 1]; - UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState); + UInt32 curAndLenPrice = + normalMatchPrice + GetPosLenPrice(distance, len, posState); Optimal optimum = _optimum[len]; if (curAndLenPrice < optimum._price) { @@ -919,10 +963,14 @@ namespace SharpCompress.Compressors.LZMA posState = (position & _posStateMask); - UInt32 curAnd1Price = curPrice + - _isMatch[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice0() + - _literalEncoder.GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)). - GetPrice(!state.IsCharState(), matchByte, currentByte); + UInt32 curAnd1Price = + curPrice + + _isMatch[ + (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].GetPrice0() + + _literalEncoder + .GetSubCoder(position, _matchFinder.GetIndexByte(0 - 2)) + .GetPrice(!state.IsCharState(), matchByte, currentByte); Optimal nextOptimum = _optimum[cur + 1]; @@ -935,11 +983,17 @@ namespace SharpCompress.Compressors.LZMA nextIsChar = true; } - matchPrice = curPrice + _isMatch[(state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].GetPrice1(); + matchPrice = + curPrice + + _isMatch[ + (state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState + ].GetPrice1(); repMatchPrice = matchPrice + _isRep[state._index].GetPrice1(); - if (matchByte == currentByte && - !(nextOptimum._posPrev < cur && nextOptimum._backPrev == 0)) + if ( + matchByte == currentByte + && !(nextOptimum._posPrev < cur && nextOptimum._backPrev == 0) + ) { UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState); if (shortRepPrice <= nextOptimum._price) @@ -973,18 +1027,20 @@ namespace SharpCompress.Compressors.LZMA Base.State state2 = state; state2.UpdateChar(); UInt32 posStateNext = (position + 1) & _posStateMask; - UInt32 nextRepMatchPrice = curAnd1Price + - _isMatch[(state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext] - .GetPrice1() + - _isRep[state2._index].GetPrice1(); + UInt32 nextRepMatchPrice = + curAnd1Price + + _isMatch[ + (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext + ].GetPrice1() + + _isRep[state2._index].GetPrice1(); { UInt32 offset = cur + 1 + lenTest2; while (lenEnd < offset) { _optimum[++lenEnd]._price = K_IFINITY_PRICE; } - UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice( - 0, lenTest2, state2, posStateNext); + UInt32 curAndLenPrice = + nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext); Optimal optimum = _optimum[offset]; if (curAndLenPrice < optimum._price) { @@ -1002,7 +1058,11 @@ namespace SharpCompress.Compressors.LZMA for (UInt32 repIndex = 0; repIndex < Base.K_NUM_REP_DISTANCES; repIndex++) { - UInt32 lenTest = _matchFinder.GetMatchLen(0 - 1, _reps[repIndex], numAvailableBytes); + UInt32 lenTest = _matchFinder.GetMatchLen( + 0 - 1, + _reps[repIndex], + numAvailableBytes + ); if (lenTest < 2) { continue; @@ -1014,7 +1074,8 @@ namespace SharpCompress.Compressors.LZMA { _optimum[++lenEnd]._price = K_IFINITY_PRICE; } - UInt32 curAndLenPrice = repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState); + UInt32 curAndLenPrice = + repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState); Optimal optimum = _optimum[cur + lenTest]; if (curAndLenPrice < optimum._price) { @@ -1023,8 +1084,7 @@ namespace SharpCompress.Compressors.LZMA optimum._backPrev = repIndex; optimum._prev1IsChar = false; } - } - while (--lenTest >= 2); + } while (--lenTest >= 2); lenTest = lenTestTemp; if (repIndex == 0) @@ -1036,27 +1096,43 @@ namespace SharpCompress.Compressors.LZMA if (lenTest < numAvailableBytesFull) { UInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes); - UInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, _reps[repIndex], t); + UInt32 lenTest2 = _matchFinder.GetMatchLen( + (Int32)lenTest, + _reps[repIndex], + t + ); if (lenTest2 >= 2) { Base.State state2 = state; state2.UpdateRep(); UInt32 posStateNext = (position + lenTest) & _posStateMask; UInt32 curAndLenCharPrice = - repMatchPrice + GetRepPrice(repIndex, lenTest, state, posState) + - _isMatch[(state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext].GetPrice0() + - _literalEncoder.GetSubCoder(position + lenTest, - _matchFinder.GetIndexByte((Int32)lenTest - 1 - 1)) - .GetPrice(true, - _matchFinder.GetIndexByte( - (Int32)lenTest - 1 - (Int32)(_reps[repIndex] + 1)), - _matchFinder.GetIndexByte((Int32)lenTest - 1)); + repMatchPrice + + GetRepPrice(repIndex, lenTest, state, posState) + + _isMatch[ + (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext + ].GetPrice0() + + _literalEncoder + .GetSubCoder( + position + lenTest, + _matchFinder.GetIndexByte((Int32)lenTest - 1 - 1) + ) + .GetPrice( + true, + _matchFinder.GetIndexByte( + (Int32)lenTest - 1 - (Int32)(_reps[repIndex] + 1) + ), + _matchFinder.GetIndexByte((Int32)lenTest - 1) + ); state2.UpdateChar(); posStateNext = (position + lenTest + 1) & _posStateMask; - UInt32 nextMatchPrice = curAndLenCharPrice + - _isMatch[(state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext] - .GetPrice1(); - UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2._index].GetPrice1(); + UInt32 nextMatchPrice = + curAndLenCharPrice + + _isMatch[ + (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + posStateNext + ].GetPrice1(); + UInt32 nextRepMatchPrice = + nextMatchPrice + _isRep[state2._index].GetPrice1(); // for(; lenTest2 >= 2; lenTest2--) { @@ -1065,8 +1141,9 @@ namespace SharpCompress.Compressors.LZMA { _optimum[++lenEnd]._price = K_IFINITY_PRICE; } - UInt32 curAndLenPrice = nextRepMatchPrice + - GetRepPrice(0, lenTest2, state2, posStateNext); + UInt32 curAndLenPrice = + nextRepMatchPrice + + GetRepPrice(0, lenTest2, state2, posStateNext); Optimal optimum = _optimum[cur + offset]; if (curAndLenPrice < optimum._price) { @@ -1086,7 +1163,11 @@ namespace SharpCompress.Compressors.LZMA if (newLen > numAvailableBytes) { newLen = numAvailableBytes; - for (numDistancePairs = 0; newLen > _matchDistances[numDistancePairs]; numDistancePairs += 2) + for ( + numDistancePairs = 0; + newLen > _matchDistances[numDistancePairs]; + numDistancePairs += 2 + ) { ; } @@ -1110,7 +1191,8 @@ namespace SharpCompress.Compressors.LZMA for (UInt32 lenTest = startLen; ; lenTest++) { UInt32 curBack = _matchDistances[offs + 1]; - UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState); + UInt32 curAndLenPrice = + normalMatchPrice + GetPosLenPrice(curBack, lenTest, posState); Optimal optimum = _optimum[cur + lenTest]; if (curAndLenPrice < optimum._price) { @@ -1124,41 +1206,57 @@ namespace SharpCompress.Compressors.LZMA { if (lenTest < numAvailableBytesFull) { - UInt32 t = Math.Min(numAvailableBytesFull - 1 - lenTest, _numFastBytes); - UInt32 lenTest2 = _matchFinder.GetMatchLen((Int32)lenTest, curBack, t); + UInt32 t = Math.Min( + numAvailableBytesFull - 1 - lenTest, + _numFastBytes + ); + UInt32 lenTest2 = _matchFinder.GetMatchLen( + (Int32)lenTest, + curBack, + t + ); if (lenTest2 >= 2) { Base.State state2 = state; state2.UpdateMatch(); UInt32 posStateNext = (position + lenTest) & _posStateMask; - UInt32 curAndLenCharPrice = curAndLenPrice + - _isMatch[ - (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + - posStateNext].GetPrice0() + - _literalEncoder.GetSubCoder(position + lenTest, - _matchFinder.GetIndexByte( - (Int32)lenTest - 1 - 1)) - . - GetPrice(true, - _matchFinder.GetIndexByte( - (Int32)lenTest - - (Int32)(curBack + 1) - 1), - _matchFinder.GetIndexByte( - (Int32)lenTest - 1)); + UInt32 curAndLenCharPrice = + curAndLenPrice + + _isMatch[ + (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + + posStateNext + ].GetPrice0() + + _literalEncoder + .GetSubCoder( + position + lenTest, + _matchFinder.GetIndexByte((Int32)lenTest - 1 - 1) + ) + .GetPrice( + true, + _matchFinder.GetIndexByte( + (Int32)lenTest - (Int32)(curBack + 1) - 1 + ), + _matchFinder.GetIndexByte((Int32)lenTest - 1) + ); state2.UpdateChar(); posStateNext = (position + lenTest + 1) & _posStateMask; - UInt32 nextMatchPrice = curAndLenCharPrice + - _isMatch[ - (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + - posStateNext].GetPrice1(); - UInt32 nextRepMatchPrice = nextMatchPrice + _isRep[state2._index].GetPrice1(); + UInt32 nextMatchPrice = + curAndLenCharPrice + + _isMatch[ + (state2._index << Base.K_NUM_POS_STATES_BITS_MAX) + + posStateNext + ].GetPrice1(); + UInt32 nextRepMatchPrice = + nextMatchPrice + _isRep[state2._index].GetPrice1(); UInt32 offset = lenTest + 1 + lenTest2; while (lenEnd < cur + offset) { _optimum[++lenEnd]._price = K_IFINITY_PRICE; } - curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext); + curAndLenPrice = + nextRepMatchPrice + + GetRepPrice(0, lenTest2, state2, posStateNext); optimum = _optimum[cur + offset]; if (curAndLenPrice < optimum._price) { @@ -1196,7 +1294,10 @@ namespace SharpCompress.Compressors.LZMA return; } - _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Encode(_rangeEncoder, 1); + _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Encode( + _rangeEncoder, + 1 + ); _isRep[_state._index].Encode(_rangeEncoder, 0); _state.UpdateMatch(); UInt32 len = Base.K_MATCH_MIN_LEN; @@ -1206,7 +1307,10 @@ namespace SharpCompress.Compressors.LZMA _posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot); int footerBits = 30; UInt32 posReduced = (((UInt32)1) << footerBits) - 1; - _rangeEncoder.EncodeDirectBits(posReduced >> Base.K_NUM_ALIGN_BITS, footerBits - Base.K_NUM_ALIGN_BITS); + _rangeEncoder.EncodeDirectBits( + posReduced >> Base.K_NUM_ALIGN_BITS, + footerBits - Base.K_NUM_ALIGN_BITS + ); _posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.K_ALIGN_MASK); } @@ -1242,7 +1346,11 @@ namespace SharpCompress.Compressors.LZMA { if (_trainSize > 0) { - for (; _trainSize > 0 && (!_processingMode || !_matchFinder.IsDataStarved); _trainSize--) + for ( + ; + _trainSize > 0 && (!_processingMode || !_matchFinder.IsDataStarved); + _trainSize-- + ) { _matchFinder.Skip(1); } @@ -1261,13 +1369,19 @@ namespace SharpCompress.Compressors.LZMA Flush((UInt32)_nowPos64); return; } - UInt32 len, numDistancePairs; // it's not used + UInt32 len, + numDistancePairs; // it's not used ReadMatchDistances(out len, out numDistancePairs); UInt32 posState = (UInt32)(_nowPos64) & _posStateMask; - _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Encode(_rangeEncoder, 0); + _isMatch[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Encode( + _rangeEncoder, + 0 + ); _state.UpdateChar(); Byte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset)); - _literalEncoder.GetSubCoder((UInt32)(_nowPos64), _previousByte).Encode(_rangeEncoder, curByte); + _literalEncoder + .GetSubCoder((UInt32)(_nowPos64), _previousByte) + .Encode(_rangeEncoder, curByte); _previousByte = curByte; _additionalOffset--; _nowPos64++; @@ -1299,11 +1413,15 @@ namespace SharpCompress.Compressors.LZMA { _isMatch[complexState].Encode(_rangeEncoder, 0); Byte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset)); - LiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder((UInt32)_nowPos64, _previousByte); + LiteralEncoder.Encoder2 subCoder = _literalEncoder.GetSubCoder( + (UInt32)_nowPos64, + _previousByte + ); if (!_state.IsCharState()) { - Byte matchByte = - _matchFinder.GetIndexByte((Int32)(0 - _repDistances[0] - 1 - _additionalOffset)); + Byte matchByte = _matchFinder.GetIndexByte( + (Int32)(0 - _repDistances[0] - 1 - _additionalOffset) + ); subCoder.EncodeMatched(_rangeEncoder, matchByte, curByte); } else @@ -1350,7 +1468,11 @@ namespace SharpCompress.Compressors.LZMA } else { - _repMatchLenEncoder.Encode(_rangeEncoder, len - Base.K_MATCH_MIN_LEN, posState); + _repMatchLenEncoder.Encode( + _rangeEncoder, + len - Base.K_MATCH_MIN_LEN, + posState + ); _state.UpdateRep(); } UInt32 distance = _repDistances[pos]; @@ -1381,15 +1503,24 @@ namespace SharpCompress.Compressors.LZMA if (posSlot < Base.K_END_POS_MODEL_INDEX) { - BitTreeEncoder.ReverseEncode(_posEncoders, - baseVal - posSlot - 1, _rangeEncoder, footerBits, - posReduced); + BitTreeEncoder.ReverseEncode( + _posEncoders, + baseVal - posSlot - 1, + _rangeEncoder, + footerBits, + posReduced + ); } else { - _rangeEncoder.EncodeDirectBits(posReduced >> Base.K_NUM_ALIGN_BITS, - footerBits - Base.K_NUM_ALIGN_BITS); - _posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.K_ALIGN_MASK); + _rangeEncoder.EncodeDirectBits( + posReduced >> Base.K_NUM_ALIGN_BITS, + footerBits - Base.K_NUM_ALIGN_BITS + ); + _posAlignEncoder.ReverseEncode( + _rangeEncoder, + posReduced & Base.K_ALIGN_MASK + ); _alignPriceCount++; } } @@ -1464,8 +1595,7 @@ namespace SharpCompress.Compressors.LZMA ReleaseOutStream(); } - public void SetStreams(Stream inStream, Stream outStream, - Int64 inSize, Int64 outSize) + public void SetStreams(Stream inStream, Stream outStream, Int64 inSize, Int64 outSize) { _inStream = inStream; _finished = false; @@ -1488,8 +1618,13 @@ namespace SharpCompress.Compressors.LZMA _nowPos64 = 0; } - public void Code(Stream inStream, Stream outStream, - Int64 inSize, Int64 outSize, ICodeProgress progress) + public void Code( + Stream inStream, + Stream outStream, + Int64 inSize, + Int64 outSize, + ICodeProgress progress + ) { _needReleaseMfStream = false; _processingMode = false; @@ -1579,7 +1714,9 @@ namespace SharpCompress.Compressors.LZMA public void WriteCoderProperties(Span span) { - span[0] = (byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits); + span[0] = (byte)( + (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits + ); for (int i = 0; i < 4; i++) { span[1 + i] = (byte)((_dictionarySize >> (8 * i)) & 0xFF); @@ -1596,11 +1733,19 @@ namespace SharpCompress.Compressors.LZMA UInt32 posSlot = GetPosSlot(i); int footerBits = (int)((posSlot >> 1) - 1); UInt32 baseVal = ((2 | (posSlot & 1)) << footerBits); - _tempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders, - baseVal - posSlot - 1, footerBits, i - baseVal); + _tempPrices[i] = BitTreeEncoder.ReverseGetPrice( + _posEncoders, + baseVal - posSlot - 1, + footerBits, + i - baseVal + ); } - for (UInt32 lenToPosState = 0; lenToPosState < Base.K_NUM_LEN_TO_POS_STATES; lenToPosState++) + for ( + UInt32 lenToPosState = 0; + lenToPosState < Base.K_NUM_LEN_TO_POS_STATES; + lenToPosState++ + ) { UInt32 posSlot; BitTreeEncoder encoder = _posSlotEncoder[lenToPosState]; @@ -1612,8 +1757,10 @@ namespace SharpCompress.Compressors.LZMA } for (posSlot = Base.K_END_POS_MODEL_INDEX; posSlot < _distTableSize; posSlot++) { - _posSlotPrices[st + posSlot] += ((((posSlot >> 1) - 1) - Base.K_NUM_ALIGN_BITS) << - BitEncoder.K_NUM_BIT_PRICE_SHIFT_BITS); + _posSlotPrices[st + posSlot] += ( + (((posSlot >> 1) - 1) - Base.K_NUM_ALIGN_BITS) + << BitEncoder.K_NUM_BIT_PRICE_SHIFT_BITS + ); } UInt32 st2 = lenToPosState * Base.K_NUM_FULL_DISTANCES; @@ -1639,11 +1786,7 @@ namespace SharpCompress.Compressors.LZMA _alignPriceCount = 0; } - private static readonly string[] K_MATCH_FINDER_I_DS = - { - "BT2", - "BT4" - }; + private static readonly string[] K_MATCH_FINDER_I_DS = { "BT2", "BT4" }; private static int FindMatchFinder(string s) { @@ -1665,129 +1808,135 @@ namespace SharpCompress.Compressors.LZMA switch (propIDs[i]) { case CoderPropId.NumFastBytes: + { + if (!(prop is Int32)) { - if (!(prop is Int32)) - { - throw new InvalidParamException(); - } - Int32 numFastBytes = (Int32)prop; - if (numFastBytes < 5 || numFastBytes > Base.K_MATCH_MAX_LEN) - { - throw new InvalidParamException(); - } - _numFastBytes = (UInt32)numFastBytes; - break; + throw new InvalidParamException(); } + Int32 numFastBytes = (Int32)prop; + if (numFastBytes < 5 || numFastBytes > Base.K_MATCH_MAX_LEN) + { + throw new InvalidParamException(); + } + _numFastBytes = (UInt32)numFastBytes; + break; + } case CoderPropId.Algorithm: - { - /* - if (!(prop is Int32)) - throw new InvalidParamException(); - Int32 maximize = (Int32)prop; - _fastMode = (maximize == 0); - _maxMode = (maximize >= 2); - */ - break; - } + { + /* + if (!(prop is Int32)) + throw new InvalidParamException(); + Int32 maximize = (Int32)prop; + _fastMode = (maximize == 0); + _maxMode = (maximize >= 2); + */ + break; + } case CoderPropId.MatchFinder: + { + if (!(prop is String)) { - if (!(prop is String)) - { - throw new InvalidParamException(); - } - EMatchFinderType matchFinderIndexPrev = _matchFinderType; - int m = FindMatchFinder(((string)prop)); - if (m < 0) - { - throw new InvalidParamException(); - } - _matchFinderType = (EMatchFinderType)m; - if (_matchFinder != null && matchFinderIndexPrev != _matchFinderType) - { - _dictionarySizePrev = 0xFFFFFFFF; - _matchFinder = null; - } - break; + throw new InvalidParamException(); } + EMatchFinderType matchFinderIndexPrev = _matchFinderType; + int m = FindMatchFinder(((string)prop)); + if (m < 0) + { + throw new InvalidParamException(); + } + _matchFinderType = (EMatchFinderType)m; + if (_matchFinder != null && matchFinderIndexPrev != _matchFinderType) + { + _dictionarySizePrev = 0xFFFFFFFF; + _matchFinder = null; + } + break; + } case CoderPropId.DictionarySize: + { + const int kDicLogSizeMaxCompress = 30; + if (!(prop is Int32)) { - const int kDicLogSizeMaxCompress = 30; - if (!(prop is Int32)) - { - throw new InvalidParamException(); - } - ; - Int32 dictionarySize = (Int32)prop; - if (dictionarySize < (UInt32)(1 << Base.K_DIC_LOG_SIZE_MIN) || - dictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress)) - { - throw new InvalidParamException(); - } - _dictionarySize = (UInt32)dictionarySize; - int dicLogSize; - for (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++) - { - if (dictionarySize <= ((UInt32)(1) << dicLogSize)) - { - break; - } - } - _distTableSize = (UInt32)dicLogSize * 2; - break; + throw new InvalidParamException(); } + ; + Int32 dictionarySize = (Int32)prop; + if ( + dictionarySize < (UInt32)(1 << Base.K_DIC_LOG_SIZE_MIN) + || dictionarySize > (UInt32)(1 << kDicLogSizeMaxCompress) + ) + { + throw new InvalidParamException(); + } + _dictionarySize = (UInt32)dictionarySize; + int dicLogSize; + for ( + dicLogSize = 0; + dicLogSize < (UInt32)kDicLogSizeMaxCompress; + dicLogSize++ + ) + { + if (dictionarySize <= ((UInt32)(1) << dicLogSize)) + { + break; + } + } + _distTableSize = (UInt32)dicLogSize * 2; + break; + } case CoderPropId.PosStateBits: + { + if (!(prop is Int32)) { - if (!(prop is Int32)) - { - throw new InvalidParamException(); - } - Int32 v = (Int32)prop; - if (v < 0 || v > (UInt32)Base.K_NUM_POS_STATES_BITS_ENCODING_MAX) - { - throw new InvalidParamException(); - } - _posStateBits = v; - _posStateMask = (((UInt32)1) << _posStateBits) - 1; - break; + throw new InvalidParamException(); } + Int32 v = (Int32)prop; + if (v < 0 || v > (UInt32)Base.K_NUM_POS_STATES_BITS_ENCODING_MAX) + { + throw new InvalidParamException(); + } + _posStateBits = v; + _posStateMask = (((UInt32)1) << _posStateBits) - 1; + break; + } case CoderPropId.LitPosBits: + { + if (!(prop is Int32)) { - if (!(prop is Int32)) - { - throw new InvalidParamException(); - } - Int32 v = (Int32)prop; - if (v < 0 || v > Base.K_NUM_LIT_POS_STATES_BITS_ENCODING_MAX) - { - throw new InvalidParamException(); - } - _numLiteralPosStateBits = v; - break; + throw new InvalidParamException(); } + Int32 v = (Int32)prop; + if (v < 0 || v > Base.K_NUM_LIT_POS_STATES_BITS_ENCODING_MAX) + { + throw new InvalidParamException(); + } + _numLiteralPosStateBits = v; + break; + } case CoderPropId.LitContextBits: + { + if (!(prop is Int32)) { - if (!(prop is Int32)) - { - throw new InvalidParamException(); - } - Int32 v = (Int32)prop; - if (v < 0 || v > Base.K_NUM_LIT_CONTEXT_BITS_MAX) - { - throw new InvalidParamException(); - } + throw new InvalidParamException(); + } + Int32 v = (Int32)prop; + if (v < 0 || v > Base.K_NUM_LIT_CONTEXT_BITS_MAX) + { + throw new InvalidParamException(); + } ; - _numLiteralContextBits = v; - break; - } + _numLiteralContextBits = v; + break; + } case CoderPropId.EndMarker: + { + if (!(prop is Boolean)) { - if (!(prop is Boolean)) - { - throw new InvalidParamException(); - } - SetWriteEndMarkerMode((Boolean)prop); - break; + throw new InvalidParamException(); } + SetWriteEndMarkerMode((Boolean)prop); + break; + } default: throw new InvalidParamException(); } diff --git a/src/SharpCompress/Compressors/LZMA/LzmaEncoderProperties.cs b/src/SharpCompress/Compressors/LZMA/LzmaEncoderProperties.cs index de7fa6f1..395b2492 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaEncoderProperties.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaEncoderProperties.cs @@ -5,20 +5,11 @@ internal CoderPropId[] _propIDs; internal object[] _properties; - public LzmaEncoderProperties() - : this(false) - { - } + public LzmaEncoderProperties() : this(false) { } - public LzmaEncoderProperties(bool eos) - : this(eos, 1 << 20) - { - } + public LzmaEncoderProperties(bool eos) : this(eos, 1 << 20) { } - public LzmaEncoderProperties(bool eos, int dictionary) - : this(eos, dictionary, 32) - { - } + public LzmaEncoderProperties(bool eos, int dictionary) : this(eos, dictionary, 32) { } public LzmaEncoderProperties(bool eos, int dictionary, int numFastBytes) { @@ -29,27 +20,27 @@ string mf = "bt4"; _propIDs = new[] - { - CoderPropId.DictionarySize, - CoderPropId.PosStateBits, - CoderPropId.LitContextBits, - CoderPropId.LitPosBits, - CoderPropId.Algorithm, - CoderPropId.NumFastBytes, - CoderPropId.MatchFinder, - CoderPropId.EndMarker - }; + { + CoderPropId.DictionarySize, + CoderPropId.PosStateBits, + CoderPropId.LitContextBits, + CoderPropId.LitPosBits, + CoderPropId.Algorithm, + CoderPropId.NumFastBytes, + CoderPropId.MatchFinder, + CoderPropId.EndMarker + }; _properties = new object[] - { - dictionary, - posStateBits, - litContextBits, - litPosBits, - algorithm, - numFastBytes, - mf, - eos - }; + { + dictionary, + posStateBits, + litContextBits, + litPosBits, + algorithm, + numFastBytes, + mf, + eos + }; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/LzmaStream.cs b/src/SharpCompress/Compressors/LZMA/LzmaStream.cs index 53c77719..80238cdf 100644 --- a/src/SharpCompress/Compressors/LZMA/LzmaStream.cs +++ b/src/SharpCompress/Compressors/LZMA/LzmaStream.cs @@ -34,22 +34,22 @@ namespace SharpCompress.Compressors.LZMA private bool _isDisposed; public LzmaStream(byte[] properties, Stream inputStream) - : this(properties, inputStream, -1, -1, null, properties.Length < 5) - { - } + : this(properties, inputStream, -1, -1, null, properties.Length < 5) { } public LzmaStream(byte[] properties, Stream inputStream, long inputSize) - : this(properties, inputStream, inputSize, -1, null, properties.Length < 5) - { - } + : this(properties, inputStream, inputSize, -1, null, properties.Length < 5) { } public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize) - : this(properties, inputStream, inputSize, outputSize, null, properties.Length < 5) - { - } + : this(properties, inputStream, inputSize, outputSize, null, properties.Length < 5) { } - public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize, - Stream presetDictionary, bool isLzma2) + public LzmaStream( + byte[] properties, + Stream inputStream, + long inputSize, + long outputSize, + Stream presetDictionary, + bool isLzma2 + ) { _inputStream = inputStream; _inputSize = inputSize; @@ -92,11 +92,14 @@ namespace SharpCompress.Compressors.LZMA } public LzmaStream(LzmaEncoderProperties properties, bool isLzma2, Stream outputStream) - : this(properties, isLzma2, null, outputStream) - { - } + : this(properties, isLzma2, null, outputStream) { } - public LzmaStream(LzmaEncoderProperties properties, bool isLzma2, Stream presetDictionary, Stream outputStream) + public LzmaStream( + LzmaEncoderProperties properties, + bool isLzma2, + Stream presetDictionary, + Stream outputStream + ) { _isLzma2 = isLzma2; _availableBytes = 0; @@ -126,9 +129,7 @@ namespace SharpCompress.Compressors.LZMA public override bool CanWrite => _encoder != null; - public override void Flush() - { - } + public override void Flush() { } protected override void Dispose(bool disposing) { @@ -150,7 +151,11 @@ namespace SharpCompress.Compressors.LZMA public override long Length => _position + _availableBytes; - public override long Position { get => _position; set => throw new NotSupportedException(); } + public override long Position + { + get => _position; + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -189,8 +194,9 @@ namespace SharpCompress.Compressors.LZMA { _inputPosition += _outWindow.CopyStream(_inputStream, toProcess); } - else if (_decoder.Code(_dictionarySize, _outWindow, _rangeDecoder) - && _outputSize < 0) + else if ( + _decoder.Code(_dictionarySize, _outWindow, _rangeDecoder) && _outputSize < 0 + ) { _availableBytes = _outWindow.AvailableBytes; } @@ -204,7 +210,10 @@ namespace SharpCompress.Compressors.LZMA if (_availableBytes == 0 && !_uncompressedChunk) { _rangeDecoder.ReleaseStream(); - if (!_rangeDecoder.IsFinished || (_rangeDecoderLimit >= 0 && _rangeDecoder._total != _rangeDecoderLimit)) + if ( + !_rangeDecoder.IsFinished + || (_rangeDecoderLimit >= 0 && _rangeDecoder._total != _rangeDecoderLimit) + ) { throw new DataErrorException(); } diff --git a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs index 9ea026a9..36ba6842 100644 --- a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs +++ b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoder.cs @@ -76,8 +76,7 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder { _stream.WriteByte((byte)(temp + (_low >> 32))); temp = 0xFF; - } - while (--_cacheSize != 0); + } while (--_cacheSize != 0); _cache = (byte)(((uint)_low) >> 24); } _cacheSize++; @@ -251,4 +250,4 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder // ulong GetProcessedSize() {return Stream.GetProcessedSize(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs index 2ab53aff..80b30bd8 100644 --- a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs +++ b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBit.cs @@ -52,7 +52,9 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder } } - private static readonly UInt32[] PROB_PRICES = new UInt32[K_BIT_MODEL_TOTAL >> K_NUM_MOVE_REDUCING_BITS]; + private static readonly UInt32[] PROB_PRICES = new UInt32[ + K_BIT_MODEL_TOTAL >> K_NUM_MOVE_REDUCING_BITS + ]; static BitEncoder() { @@ -63,15 +65,19 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder UInt32 end = (UInt32)1 << (kNumBits - i); for (UInt32 j = start; j < end; j++) { - PROB_PRICES[j] = ((UInt32)i << K_NUM_BIT_PRICE_SHIFT_BITS) + - (((end - j) << K_NUM_BIT_PRICE_SHIFT_BITS) >> (kNumBits - i - 1)); + PROB_PRICES[j] = + ((UInt32)i << K_NUM_BIT_PRICE_SHIFT_BITS) + + (((end - j) << K_NUM_BIT_PRICE_SHIFT_BITS) >> (kNumBits - i - 1)); } } } public uint GetPrice(uint symbol) { - return PROB_PRICES[(((_prob - symbol) ^ ((-(int)symbol))) & (K_BIT_MODEL_TOTAL - 1)) >> K_NUM_MOVE_REDUCING_BITS]; + return PROB_PRICES[ + (((_prob - symbol) ^ ((-(int)symbol))) & (K_BIT_MODEL_TOTAL - 1)) + >> K_NUM_MOVE_REDUCING_BITS + ]; } public uint GetPrice0() @@ -119,7 +125,8 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder _prob += (K_BIT_MODEL_TOTAL - _prob) >> K_NUM_MOVE_BITS; if (rangeDecoder._range < Decoder.K_TOP_VALUE) { - rangeDecoder._code = (rangeDecoder._code << 8) | (byte)rangeDecoder._stream.ReadByte(); + rangeDecoder._code = + (rangeDecoder._code << 8) | (byte)rangeDecoder._stream.ReadByte(); rangeDecoder._range <<= 8; rangeDecoder._total++; } @@ -130,11 +137,12 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder _prob -= (_prob) >> K_NUM_MOVE_BITS; if (rangeDecoder._range < Decoder.K_TOP_VALUE) { - rangeDecoder._code = (rangeDecoder._code << 8) | (byte)rangeDecoder._stream.ReadByte(); + rangeDecoder._code = + (rangeDecoder._code << 8) | (byte)rangeDecoder._stream.ReadByte(); rangeDecoder._range <<= 8; rangeDecoder._total++; } return 1; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs index cc511603..a00a5135 100644 --- a/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs +++ b/src/SharpCompress/Compressors/LZMA/RangeCoder/RangeCoderBitTree.cs @@ -24,7 +24,7 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder public void Encode(Encoder rangeEncoder, UInt32 symbol) { UInt32 m = 1; - for (int bitIndex = _numBitLevels; bitIndex > 0;) + for (int bitIndex = _numBitLevels; bitIndex > 0; ) { bitIndex--; UInt32 bit = (symbol >> bitIndex) & 1; @@ -49,7 +49,7 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder { UInt32 price = 0; UInt32 m = 1; - for (int bitIndex = _numBitLevels; bitIndex > 0;) + for (int bitIndex = _numBitLevels; bitIndex > 0; ) { bitIndex--; UInt32 bit = (symbol >> bitIndex) & 1; @@ -73,8 +73,12 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder return price; } - public static UInt32 ReverseGetPrice(BitEncoder[] models, UInt32 startIndex, - int numBitLevels, UInt32 symbol) + public static UInt32 ReverseGetPrice( + BitEncoder[] models, + UInt32 startIndex, + int numBitLevels, + UInt32 symbol + ) { UInt32 price = 0; UInt32 m = 1; @@ -88,8 +92,13 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder return price; } - public static void ReverseEncode(BitEncoder[] models, UInt32 startIndex, - Encoder rangeEncoder, int numBitLevels, UInt32 symbol) + public static void ReverseEncode( + BitEncoder[] models, + UInt32 startIndex, + Encoder rangeEncoder, + int numBitLevels, + UInt32 symbol + ) { UInt32 m = 1; for (int i = 0; i < numBitLevels; i++) @@ -145,8 +154,12 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder return symbol; } - public static uint ReverseDecode(BitDecoder[] models, UInt32 startIndex, - Decoder rangeDecoder, int numBitLevels) + public static uint ReverseDecode( + BitDecoder[] models, + UInt32 startIndex, + Decoder rangeDecoder, + int numBitLevels + ) { uint m = 1; uint symbol = 0; @@ -160,4 +173,4 @@ namespace SharpCompress.Compressors.LZMA.RangeCoder return symbol; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/Registry.cs b/src/SharpCompress/Compressors/LZMA/Registry.cs index 8495c4bc..967d1fe7 100644 --- a/src/SharpCompress/Compressors/LZMA/Registry.cs +++ b/src/SharpCompress/Compressors/LZMA/Registry.cs @@ -22,8 +22,13 @@ namespace SharpCompress.Compressors.LZMA private const uint K_DEFLATE = 0x040108; private const uint K_B_ZIP2 = 0x040202; - internal static Stream CreateDecoderStream(CMethodId id, Stream[] inStreams, byte[] info, IPasswordProvider pass, - long limit) + internal static Stream CreateDecoderStream( + CMethodId id, + Stream[] inStreams, + byte[] info, + IPasswordProvider pass, + long limit + ) { switch (id._id) { @@ -53,4 +58,4 @@ namespace SharpCompress.Compressors.LZMA } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs b/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs index 4410dd9a..e72c715a 100644 --- a/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/Utilites/CrcBuilderStream.cs @@ -46,13 +46,15 @@ namespace SharpCompress.Compressors.LZMA.Utilites public override bool CanWrite => true; - public override void Flush() - { - } + public override void Flush() { } public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -81,4 +83,4 @@ namespace SharpCompress.Compressors.LZMA.Utilites _mTarget.Write(buffer, offset, count); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs b/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs index 9a59e26b..2f44bcc3 100644 --- a/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs +++ b/src/SharpCompress/Compressors/LZMA/Utilites/CrcCheckStream.cs @@ -74,13 +74,15 @@ namespace SharpCompress.Compressors.LZMA.Utilites public override bool CanWrite => true; - public override void Flush() - { - } + public override void Flush() { } public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/LZMA/Utilites/IPasswordProvider.cs b/src/SharpCompress/Compressors/LZMA/Utilites/IPasswordProvider.cs index 51dc389e..977c86bf 100644 --- a/src/SharpCompress/Compressors/LZMA/Utilites/IPasswordProvider.cs +++ b/src/SharpCompress/Compressors/LZMA/Utilites/IPasswordProvider.cs @@ -4,4 +4,4 @@ { string CryptoGetTextPassword(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/H/FreqData.cs b/src/SharpCompress/Compressors/PPMd/H/FreqData.cs index f4537c11..a139a449 100644 --- a/src/SharpCompress/Compressors/PPMd/H/FreqData.cs +++ b/src/SharpCompress/Compressors/PPMd/H/FreqData.cs @@ -14,10 +14,7 @@ namespace SharpCompress.Compressors.PPMd.H // STATE _PACK_ATTR * Stats; // }; - internal FreqData(byte[] memory) - : base(memory) - { - } + internal FreqData(byte[] memory) : base(memory) { } internal int SummFreq { diff --git a/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs b/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs index 8f0e6867..974a61ea 100644 --- a/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs +++ b/src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs @@ -28,19 +28,43 @@ namespace SharpCompress.Compressors.PPMd.H public virtual int InitRl => _initRl; - public virtual int EscCount { get => _escCount; set => _escCount = value & 0xff; } + public virtual int EscCount + { + get => _escCount; + set => _escCount = value & 0xff; + } public virtual int[] CharMask => _charMask; - public virtual int NumMasked { get => _numMasked; set => _numMasked = value; } + public virtual int NumMasked + { + get => _numMasked; + set => _numMasked = value; + } - public virtual int PrevSuccess { get => _prevSuccess; set => _prevSuccess = value & 0xff; } + public virtual int PrevSuccess + { + get => _prevSuccess; + set => _prevSuccess = value & 0xff; + } - public virtual int InitEsc { get => _initEsc; set => _initEsc = value; } + public virtual int InitEsc + { + get => _initEsc; + set => _initEsc = value; + } - public virtual int RunLength { get => _runLength; set => _runLength = value; } + public virtual int RunLength + { + get => _runLength; + set => _runLength = value; + } - public virtual int HiBitsFlag { get => _hiBitsFlag; set => _hiBitsFlag = value & 0xff; } + public virtual int HiBitsFlag + { + get => _hiBitsFlag; + set => _hiBitsFlag = value & 0xff; + } public virtual int[][] BinSumm => _binSumm; @@ -77,7 +101,12 @@ namespace SharpCompress.Compressors.PPMd.H private PpmContext _maxContext; - private int _numMasked, _initEsc, _orderFall, _maxOrder, _runLength, _initRl; + private int _numMasked, + _initEsc, + _orderFall, + _maxOrder, + _runLength, + _initRl; private readonly int[] _charMask = new int[256]; @@ -88,11 +117,23 @@ namespace SharpCompress.Compressors.PPMd.H private readonly int[] _hb2Flag = new int[256]; // byte EscCount, PrevSuccess, HiBitsFlag; - private int _escCount, _prevSuccess, _hiBitsFlag; + private int _escCount, + _prevSuccess, + _hiBitsFlag; private readonly int[][] _binSumm = new int[128][]; // binary SEE-contexts - private static readonly int[] INIT_BIN_ESC = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051 }; + private static readonly int[] INIT_BIN_ESC = + { + 0x3CDD, + 0x1F3F, + 0x59BF, + 0x48F3, + 0x64A1, + 0x5ABC, + 0x6632, + 0x6051 + }; // Temp fields //UPGRADE_NOTE: Final was removed from the declaration of 'tempState1 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" @@ -187,7 +228,10 @@ namespace SharpCompress.Compressors.PPMd.H private void StartModelRare(int maxOrder) { - int i, k, m, step; + int i, + k, + m, + step; _escCount = 1; _maxOrder = maxOrder; RestartModelRare(); @@ -299,8 +343,10 @@ namespace SharpCompress.Compressors.PPMd.H if (_minContext.NumStats != 1) { - if (_minContext.FreqData.GetStats() <= SubAlloc.PText || - _minContext.FreqData.GetStats() > SubAlloc.HeapEnd) + if ( + _minContext.FreqData.GetStats() <= SubAlloc.PText + || _minContext.FreqData.GetStats() > SubAlloc.HeapEnd + ) { return (-1); } @@ -321,12 +367,14 @@ namespace SharpCompress.Compressors.PPMd.H { _orderFall++; _minContext.Address = _minContext.GetSuffix(); // =MinContext->Suffix; - if (_minContext.Address <= SubAlloc.PText || _minContext.Address > SubAlloc.HeapEnd) + if ( + _minContext.Address <= SubAlloc.PText + || _minContext.Address > SubAlloc.HeapEnd + ) { return (-1); } - } - while (_minContext.NumStats == _numMasked); + } while (_minContext.NumStats == _numMasked); if (!_minContext.DecodeSymbol2(this)) { return (-1); @@ -433,8 +481,7 @@ namespace SharpCompress.Compressors.PPMd.H do { p.IncrementAddress(); - } - while (p.Symbol != FoundState.Symbol); + } while (p.Symbol != FoundState.Symbol); } } else @@ -449,8 +496,7 @@ namespace SharpCompress.Compressors.PPMd.H break; } _ps[pps++] = p.Address; - } - while (pc.GetSuffix() != 0); + } while (pc.GetSuffix() != 0); } // NO_LOOP: if (pps == 0) { @@ -473,14 +519,15 @@ namespace SharpCompress.Compressors.PPMd.H do { p.IncrementAddress(); - } - while (p.Symbol != upState.Symbol); + } while (p.Symbol != upState.Symbol); } int cf = p.Freq - 1; int s0 = pc.FreqData.SummFreq - pc.NumStats - cf; // UpState.Freq=1+((2*cf <= s0)?(5*cf > s0):((2*cf+3*s0-1)/(2*s0))); - upState.Freq = 1 + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0) : ((2 * cf + 3 * s0 - 1) / (2 * s0))); + upState.Freq = + 1 + + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0) : ((2 * cf + 3 * s0 - 1) / (2 * s0))); } else { @@ -495,8 +542,7 @@ namespace SharpCompress.Compressors.PPMd.H { return 0; } - } - while (pps != 0); + } while (pps != 0); return pc.Address; } @@ -518,7 +564,11 @@ namespace SharpCompress.Compressors.PPMd.H PpmContext pc = _tempPpmContext3.Initialize(Heap); PpmContext successor = _tempPpmContext4.Initialize(Heap); - int ns1, ns, cf, sf, s0; + int ns1, + ns, + cf, + sf, + s0; pc.Address = _minContext.GetSuffix(); if (fs.Freq < MAX_FREQ / 4 && pc.Address != 0) { @@ -530,8 +580,7 @@ namespace SharpCompress.Compressors.PPMd.H do { p.IncrementAddress(); - } - while (p.Symbol != fs.Symbol); + } while (p.Symbol != fs.Symbol); tempState.Address = p.Address - State.SIZE; if (p.Freq >= tempState.Freq) { @@ -607,14 +656,20 @@ namespace SharpCompress.Compressors.PPMd.H // subAlloc.dumpHeap(); ns = _minContext.NumStats; s0 = _minContext.FreqData.SummFreq - (ns) - (fs.Freq - 1); - for (pc.Address = _maxContext.Address; pc.Address != _minContext.Address; pc.Address = pc.GetSuffix()) + for ( + pc.Address = _maxContext.Address; + pc.Address != _minContext.Address; + pc.Address = pc.GetSuffix() + ) { if ((ns1 = pc.NumStats) != 1) { if ((ns1 & 1) == 0) { //System.out.println(ns1); - pc.FreqData.SetStats(SubAlloc.ExpandUnits(pc.FreqData.GetStats(), Utility.URShift(ns1, 1))); + pc.FreqData.SetStats( + SubAlloc.ExpandUnits(pc.FreqData.GetStats(), Utility.URShift(ns1, 1)) + ); if (pc.FreqData.GetStats() == 0) { UpdateModelRestart(); @@ -626,8 +681,13 @@ namespace SharpCompress.Compressors.PPMd.H // int sum = ((2 * ns1 < ns) ? 1 : 0) + // 2 * ((4 * ((ns1 <= ns) ? 1 : 0)) & ((pc.getFreqData() // .getSummFreq() <= 8 * ns1) ? 1 : 0)); - int sum = ((2 * ns1 < ns) ? 1 : 0) + - 2 * (((4 * ns1 <= ns) ? 1 : 0) & ((pc.FreqData.SummFreq <= 8 * ns1) ? 1 : 0)); + int sum = + ((2 * ns1 < ns) ? 1 : 0) + + 2 + * ( + ((4 * ns1 <= ns) ? 1 : 0) + & ((pc.FreqData.SummFreq <= 8 * ns1) ? 1 : 0) + ); pc.FreqData.IncrementSummFreq(sum); } else @@ -659,7 +719,11 @@ namespace SharpCompress.Compressors.PPMd.H } else { - cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0) + (cf >= 15 * sf ? 1 : 0); + cf = + 4 + + (cf >= 9 * sf ? 1 : 0) + + (cf >= 12 * sf ? 1 : 0) + + (cf >= 15 * sf ? 1 : 0); pc.FreqData.IncrementSummFreq(cf); } p.Address = pc.FreqData.GetStats() + ns1 * State.SIZE; @@ -770,8 +834,12 @@ namespace SharpCompress.Compressors.PPMd.H State s = _tempState1.Initialize(Heap); s.Address = _minContext.FreqData.GetStats(); int i; - int count, hiCnt; - if ((count = (int)decoder.GetThreshold((uint)_minContext.FreqData.SummFreq)) < (hiCnt = s.Freq)) + int count, + hiCnt; + if ( + (count = (int)decoder.GetThreshold((uint)_minContext.FreqData.SummFreq)) + < (hiCnt = s.Freq) + ) { byte symbol; decoder.Decode(0, (uint)s.Freq); @@ -794,8 +862,7 @@ namespace SharpCompress.Compressors.PPMd.H NextContext(); return symbol; } - } - while (--i > 0); + } while (--i > 0); if (count >= _minContext.FreqData.SummFreq) { return -2; @@ -812,8 +879,7 @@ namespace SharpCompress.Compressors.PPMd.H { s.DecrementAddress(); _charMask[s.Symbol] = 0; - } - while (--i > 0); + } while (--i > 0); } else { @@ -826,7 +892,8 @@ namespace SharpCompress.Compressors.PPMd.H if (decoder.DecodeBit((uint)bs, 14) == 0) { byte symbol; - _binSumm[off1][off2] = (bs + INTERVAL - _minContext.GetMean(bs, PERIOD_BITS, 2)) & 0xFFFF; + _binSumm[off1][off2] = + (bs + INTERVAL - _minContext.GetMean(bs, PERIOD_BITS, 2)) & 0xFFFF; FoundState.Address = rs.Address; symbol = (byte)rs.Symbol; rs.IncrementFreq((rs.Freq < 128) ? 1 : 0); @@ -850,19 +917,24 @@ namespace SharpCompress.Compressors.PPMd.H { State s = _tempState1.Initialize(Heap); int i; - int freqSum, count, hiCnt; + int freqSum, + count, + hiCnt; See2Context see; - int num, numMasked = _minContext.NumStats; + int num, + numMasked = _minContext.NumStats; do { _orderFall++; _minContext.Address = _minContext.GetSuffix(); - if (_minContext.Address <= SubAlloc.PText || _minContext.Address > SubAlloc.HeapEnd) + if ( + _minContext.Address <= SubAlloc.PText + || _minContext.Address > SubAlloc.HeapEnd + ) { return -1; } - } - while (_minContext.NumStats == numMasked); + } while (_minContext.NumStats == numMasked); hiCnt = 0; s.Address = _minContext.FreqData.GetStats(); i = 0; @@ -874,8 +946,7 @@ namespace SharpCompress.Compressors.PPMd.H _minContext._ps[i] = s.Address; s.IncrementAddress(); i -= k; - } - while (i != num); + } while (i != num); see = _minContext.MakeEscFreq(this, numMasked, out freqSum); freqSum += hiCnt; @@ -885,9 +956,11 @@ namespace SharpCompress.Compressors.PPMd.H { byte symbol; State ps = _tempState2.Initialize(Heap); - for (hiCnt = 0, i = 0, ps.Address = _minContext._ps[i]; - (hiCnt += ps.Freq) <= count; - i++, ps.Address = _minContext._ps[i]) + for ( + hiCnt = 0, i = 0, ps.Address = _minContext._ps[i]; + (hiCnt += ps.Freq) <= count; + i++, ps.Address = _minContext._ps[i] + ) { ; } @@ -909,8 +982,7 @@ namespace SharpCompress.Compressors.PPMd.H { s.Address = _minContext._ps[--i]; _charMask[s.Symbol] = 0; - } - while (i != 0); + } while (i != 0); } } } diff --git a/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs b/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs index 83340887..53d9cc7f 100644 --- a/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs +++ b/src/SharpCompress/Compressors/PPMd/H/PPMContext.cs @@ -24,11 +24,11 @@ namespace SharpCompress.Compressors.PPMd.H { if (Memory != null) { - _numStats = BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; + _numStats = + BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; } return _numStats; } - set { _numStats = value & 0xffff; @@ -61,7 +61,25 @@ namespace SharpCompress.Compressors.PPMd.H private int _suffix; // pointer ppmcontext //UPGRADE_NOTE: Final was removed from the declaration of 'ExpEscape'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" - public static readonly int[] EXP_ESCAPE = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; + public static readonly int[] EXP_ESCAPE = + { + 25, + 14, + 9, + 7, + 5, + 5, + 4, + 4, + 4, + 3, + 3, + 3, + 2, + 2, + 2, + 2 + }; // Temp fields //UPGRADE_NOTE: Final was removed from the declaration of 'tempState1 '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" @@ -83,8 +101,7 @@ namespace SharpCompress.Compressors.PPMd.H //UPGRADE_NOTE: Final was removed from the declaration of 'ps '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" internal int[] _ps = new int[256]; - public PpmContext(byte[] memory) - : base(memory) + public PpmContext(byte[] memory) : base(memory) { _oneState = new State(memory); _freqData = new FreqData(memory); @@ -166,14 +183,21 @@ namespace SharpCompress.Compressors.PPMd.H internal void Rescale(ModelPpm model) { - int oldNs = NumStats, i = NumStats - 1, adder, escFreq; + int oldNs = NumStats, + i = NumStats - 1, + adder, + escFreq; // STATE* p1, * p; State p1 = new State(model.Heap); State p = new State(model.Heap); State temp = new State(model.Heap); - for (p.Address = model.FoundState.Address; p.Address != _freqData.GetStats(); p.DecrementAddress()) + for ( + p.Address = model.FoundState.Address; + p.Address != _freqData.GetStats(); + p.DecrementAddress() + ) { temp.Address = p.Address - State.SIZE; State.PpmdSwap(p, temp); @@ -206,20 +230,17 @@ namespace SharpCompress.Compressors.PPMd.H p1.SetValues(temp2); p1.DecrementAddress(); temp3.Address = p1.Address - State.SIZE; - } - while (p1.Address != _freqData.GetStats() && tmp.Freq > temp3.Freq); + } while (p1.Address != _freqData.GetStats() && tmp.Freq > temp3.Freq); p1.SetValues(tmp); } - } - while (--i != 0); + } while (--i != 0); if (p.Freq == 0) { do { i++; p.DecrementAddress(); - } - while (p.Freq == 0); + } while (p.Freq == 0); escFreq += i; NumStats = NumStats - i; if (NumStats == 1) @@ -234,8 +255,7 @@ namespace SharpCompress.Compressors.PPMd.H // tmp.Freq-=(tmp.Freq >> 1) tmp.DecrementFreq(Utility.URShift(tmp.Freq, 1)); escFreq = Utility.URShift(escFreq, 1); - } - while (escFreq > 1); + } while (escFreq > 1); model.SubAlloc.FreeUnits(_freqData.GetStats(), Utility.URShift((oldNs + 1), 1)); _oneState.SetValues(tmp); model.FoundState.Address = _oneState.Address; @@ -244,7 +264,8 @@ namespace SharpCompress.Compressors.PPMd.H } escFreq -= Utility.URShift(escFreq, 1); _freqData.IncrementSummFreq(escFreq); - int n0 = Utility.URShift((oldNs + 1), 1), n1 = Utility.URShift((NumStats + 1), 1); + int n0 = Utility.URShift((oldNs + 1), 1), + n1 = Utility.URShift((NumStats + 1), 1); if (n0 != n1) { _freqData.SetStats(model.SubAlloc.ShrinkUnits(_freqData.GetStats(), n0, n1)); @@ -355,7 +376,8 @@ namespace SharpCompress.Compressors.PPMd.H internal bool DecodeSymbol2(ModelPpm model) { long count; - int hiCnt, i = NumStats - model.NumMasked; + int hiCnt, + i = NumStats - model.NumMasked; See2Context psee2C = MakeEscFreq2(model, i); RangeCoder coder = model.Coder; @@ -371,12 +393,10 @@ namespace SharpCompress.Compressors.PPMd.H do { p.IncrementAddress(); // p++; - } - while (model.CharMask[p.Symbol] == model.EscCount); + } while (model.CharMask[p.Symbol] == model.EscCount); hiCnt += p.Freq; _ps[pps++] = p.Address; - } - while (--i != 0); + } while (--i != 0); coder.SubRange.IncScale(hiCnt); count = coder.CurrentCount; if (count >= coder.SubRange.Scale) @@ -407,8 +427,7 @@ namespace SharpCompress.Compressors.PPMd.H { temp.Address = _ps[++pps]; // (*++pps) model.CharMask[temp.Symbol] = model.EscCount; - } - while (--i != 0); + } while (--i != 0); psee2C.IncSumm((int)coder.SubRange.Scale); model.NumMasked = NumStats; } @@ -487,7 +506,8 @@ namespace SharpCompress.Compressors.PPMd.H coder.SubRange.Scale = _freqData.SummFreq; State p = new State(model.Heap); p.Address = _freqData.GetStats(); - int i, hiCnt; + int i, + hiCnt; long count = coder.CurrentCount; if (count >= coder.SubRange.Scale) { @@ -529,8 +549,7 @@ namespace SharpCompress.Compressors.PPMd.H do { model.CharMask[p.DecrementAddress().Symbol] = model.EscCount; - } - while (--i != 0); + } while (--i != 0); coder.SubRange.HighCount = coder.SubRange.Scale; return (true); } diff --git a/src/SharpCompress/Compressors/PPMd/H/Pointer.cs b/src/SharpCompress/Compressors/PPMd/H/Pointer.cs index 98f0a9cb..40a15c30 100644 --- a/src/SharpCompress/Compressors/PPMd/H/Pointer.cs +++ b/src/SharpCompress/Compressors/PPMd/H/Pointer.cs @@ -16,12 +16,11 @@ namespace SharpCompress.Compressors.PPMd.H internal virtual int Address { get; set; } - protected T Initialize(byte[] mem) - where T : Pointer + protected T Initialize(byte[] mem) where T : Pointer { Memory = mem; Address = 0; return this as T; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs b/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs index ce778e19..1d87849b 100644 --- a/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs +++ b/src/SharpCompress/Compressors/PPMd/H/RangeCoder.cs @@ -14,7 +14,9 @@ namespace SharpCompress.Compressors.PPMd.H internal const long UINT_MASK = 0xFFFFffffL; // uint low, code, range; - private long _low, _code, _range; + private long _low, + _code, + _range; private readonly IRarUnpack _unpackRead; private readonly Stream _stream; @@ -126,18 +128,32 @@ namespace SharpCompress.Compressors.PPMd.H internal class SubRange { // uint LowCount, HighCount, scale; - private long _lowCount, _highCount, _scale; + private long _lowCount, + _highCount, + _scale; internal void IncScale(int dScale) { Scale = Scale + dScale; } - internal long HighCount { get => _highCount; set => _highCount = value & RangeCoder.UINT_MASK; } + internal long HighCount + { + get => _highCount; + set => _highCount = value & RangeCoder.UINT_MASK; + } - internal long LowCount { get => _lowCount & RangeCoder.UINT_MASK; set => _lowCount = value & RangeCoder.UINT_MASK; } + internal long LowCount + { + get => _lowCount & RangeCoder.UINT_MASK; + set => _lowCount = value & RangeCoder.UINT_MASK; + } - internal long Scale { get => _scale; set => _scale = value & RangeCoder.UINT_MASK; } + internal long Scale + { + get => _scale; + set => _scale = value & RangeCoder.UINT_MASK; + } // Debug public override String ToString() diff --git a/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs b/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs index 2c63811f..b067fac8 100644 --- a/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs +++ b/src/SharpCompress/Compressors/PPMd/H/RarMemBlock.cs @@ -7,14 +7,13 @@ namespace SharpCompress.Compressors.PPMd.H { public const int SIZE = 12; - private int _stamp, _nu; + private int _stamp, + _nu; - private int _next, _prev; // Pointer RarMemBlock + private int _next, + _prev; // Pointer RarMemBlock - public RarMemBlock(byte[] memory) - : base(memory) - { - } + public RarMemBlock(byte[] memory) : base(memory) { } internal int Stamp { @@ -22,11 +21,11 @@ namespace SharpCompress.Compressors.PPMd.H { if (Memory != null) { - _stamp = BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; + _stamp = + BinaryPrimitives.ReadInt16LittleEndian(Memory.AsSpan(Address)) & 0xffff; } return _stamp; } - set { _stamp = value; diff --git a/src/SharpCompress/Compressors/PPMd/H/RarNode.cs b/src/SharpCompress/Compressors/PPMd/H/RarNode.cs index f6db5cf7..15775229 100644 --- a/src/SharpCompress/Compressors/PPMd/H/RarNode.cs +++ b/src/SharpCompress/Compressors/PPMd/H/RarNode.cs @@ -10,10 +10,7 @@ namespace SharpCompress.Compressors.PPMd.H public const int SIZE = 4; - public RarNode(byte[] memory) - : base(memory) - { - } + public RarNode(byte[] memory) : base(memory) { } internal int GetNext() { diff --git a/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs b/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs index c97f0836..dd4fa7c6 100644 --- a/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs +++ b/src/SharpCompress/Compressors/PPMd/H/SEE2Context.cs @@ -15,11 +15,23 @@ namespace SharpCompress.Compressors.PPMd.H } } - public virtual int Count { get => _count; set => _count = value & 0xff; } + public virtual int Count + { + get => _count; + set => _count = value & 0xff; + } - public virtual int Shift { get => _shift; set => _shift = value & 0xff; } + public virtual int Shift + { + get => _shift; + set => _shift = value & 0xff; + } - public virtual int Summ { get => _summ; set => _summ = value & 0xffff; } + public virtual int Summ + { + get => _summ; + set => _summ = value & 0xffff; + } public const int SIZE = 4; @@ -72,4 +84,4 @@ namespace SharpCompress.Compressors.PPMd.H return buffer.ToString(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/H/State.cs b/src/SharpCompress/Compressors/PPMd/H/State.cs index e9d1a48c..6ce6d2d0 100644 --- a/src/SharpCompress/Compressors/PPMd/H/State.cs +++ b/src/SharpCompress/Compressors/PPMd/H/State.cs @@ -8,14 +8,19 @@ namespace SharpCompress.Compressors.PPMd.H { internal const int SIZE = 6; - internal State(byte[]? memory) - : base(memory) + internal State(byte[]? memory) : base(memory) { } + + internal int Symbol { + get => Memory[Address] & 0xff; + set => Memory[Address] = (byte)value; } - internal int Symbol { get => Memory[Address] & 0xff; set => Memory[Address] = (byte)value; } - - internal int Freq { get => Memory[Address + 1] & 0xff; set => Memory[Address + 1] = (byte)value; } + internal int Freq + { + get => Memory[Address + 1] & 0xff; + set => Memory[Address + 1] = (byte)value; + } internal State Initialize(byte[] mem) { @@ -68,7 +73,8 @@ namespace SharpCompress.Compressors.PPMd.H internal static void PpmdSwap(State ptr1, State ptr2) { - byte[] mem1 = ptr1.Memory, mem2 = ptr2.Memory; + byte[] mem1 = ptr1.Memory, + mem2 = ptr2.Memory; for (int i = 0, pos1 = ptr1.Address, pos2 = ptr2.Address; i < SIZE; i++, pos1++, pos2++) { byte temp = mem1[pos1]; diff --git a/src/SharpCompress/Compressors/PPMd/H/StateRef.cs b/src/SharpCompress/Compressors/PPMd/H/StateRef.cs index f1e8e90f..686c1128 100644 --- a/src/SharpCompress/Compressors/PPMd/H/StateRef.cs +++ b/src/SharpCompress/Compressors/PPMd/H/StateRef.cs @@ -11,9 +11,17 @@ namespace SharpCompress.Compressors.PPMd.H private int _successor; // pointer ppmcontext - internal int Symbol { get => _symbol; set => _symbol = value & 0xff; } + internal int Symbol + { + get => _symbol; + set => _symbol = value & 0xff; + } - internal int Freq { get => _freq; set => _freq = value & 0xff; } + internal int Freq + { + get => _freq; + set => _freq = value & 0xff; + } internal State Values { @@ -64,4 +72,4 @@ namespace SharpCompress.Compressors.PPMd.H return buffer.ToString(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs b/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs index 39a808d5..dba09739 100644 --- a/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs +++ b/src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs @@ -7,13 +7,25 @@ namespace SharpCompress.Compressors.PPMd.H { internal class SubAllocator { - public virtual int FakeUnitsStart { get => _fakeUnitsStart; set => _fakeUnitsStart = value; } + public virtual int FakeUnitsStart + { + get => _fakeUnitsStart; + set => _fakeUnitsStart = value; + } public virtual int HeapEnd => _heapEnd; - public virtual int PText { get => _pText; set => _pText = value; } + public virtual int PText + { + get => _pText; + set => _pText = value; + } - public virtual int UnitsStart { get => _unitsStart; set => _unitsStart = value; } + public virtual int UnitsStart + { + get => _unitsStart; + set => _unitsStart = value; + } public virtual byte[] Heap => _heap; @@ -40,13 +52,18 @@ namespace SharpCompress.Compressors.PPMd.H private int _glueCount; // byte *HeapStart,*LoUnit, *HiUnit; - private int _heapStart, _loUnit, _hiUnit; + private int _heapStart, + _loUnit, + _hiUnit; //UPGRADE_NOTE: Final was removed from the declaration of 'freeList '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" private readonly RarNode[] _freeList = new RarNode[N_INDEXES]; // byte *pText, *UnitsStart,*HeapEnd,*FakeUnitsStart; - private int _pText, _unitsStart, _heapEnd, _fakeUnitsStart; + private int _pText, + _unitsStart, + _heapEnd, + _fakeUnitsStart; private byte[] _heap; @@ -106,7 +123,8 @@ namespace SharpCompress.Compressors.PPMd.H private void SplitBlock(int pv, int oldIndx, int newIndx) { - int i, uDiff = _indx2Units[oldIndx] - _indx2Units[newIndx]; + int i, + uDiff = _indx2Units[oldIndx] - _indx2Units[newIndx]; int p = pv + U2B(_indx2Units[newIndx]); if (_indx2Units[i = _units2Indx[uDiff - 1]] != uDiff) { @@ -193,7 +211,9 @@ namespace SharpCompress.Compressors.PPMd.H s0.Address = _tempMemBlockPos; RarMemBlock p = _tempRarMemBlock2; RarMemBlock p1 = _tempRarMemBlock3; - int i, k, sz; + int i, + k, + sz; if (_loUnit != _hiUnit) { _heap[_loUnit] = 0; @@ -227,7 +247,11 @@ namespace SharpCompress.Compressors.PPMd.H p.Address = s0.GetNext(); while (p.Address != s0.Address) { - for (p.Remove(), sz = p.GetNu(); sz > 128; sz -= 128, p.Address = MbPtr(p.Address, 128)) + for ( + p.Remove(), sz = p.GetNu(); + sz > 128; + sz -= 128, p.Address = MbPtr(p.Address, 128) + ) { InsertNode(p.Address, N_INDEXES - 1); } @@ -268,8 +292,7 @@ namespace SharpCompress.Compressors.PPMd.H } return (0); } - } - while (_freeList[i].GetNext() == 0); + } while (_freeList[i].GetNext() == 0); int retVal = RemoveNode(i); SplitBlock(retVal, i, indx); return retVal; @@ -361,7 +384,8 @@ namespace SharpCompress.Compressors.PPMd.H public virtual void InitSubAllocator() { - int i, k; + int i, + k; new Span(_heap, _freeListPos, SizeOfFreeList()).Clear(); _pText = _heapStart; diff --git a/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs b/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs index 269e44c1..39a0c94d 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Allocator.cs @@ -102,7 +102,10 @@ namespace SharpCompress.Compressors.PPMd.I1 { for (int index = 0; index < INDEX_COUNT; index++) { - _memoryNodes[index] = new MemoryNode((uint)(NODE_OFFSET + index * MemoryNode.SIZE), _memory); + _memoryNodes[index] = new MemoryNode( + (uint)(NODE_OFFSET + index * MemoryNode.SIZE), + _memory + ); _memoryNodes[index].Stamp = 0; _memoryNodes[index].Next = MemoryNode.ZERO; _memoryNodes[index].UnitCount = 0; @@ -335,7 +338,11 @@ namespace SharpCompress.Compressors.PPMd.I1 for (uint index = 0; index < INDEX_COUNT; index++) { - for (memoryNode = _memoryNodes[index]; counts[index] != 0; memoryNode = memoryNode.Next) + for ( + memoryNode = _memoryNodes[index]; + counts[index] != 0; + memoryNode = memoryNode.Next + ) { while (memoryNode.Next.Stamp == 0) { @@ -374,8 +381,7 @@ namespace SharpCompress.Compressors.PPMd.I1 oldIndex = INDEX_TO_UNITS[index] * UNIT_SIZE; return (_baseUnit - _text > oldIndex) ? (_baseUnit -= oldIndex) : Pointer.ZERO; } - } - while (!_memoryNodes[oldIndex].Available); + } while (!_memoryNodes[oldIndex].Available); Pointer allocatedBlock = _memoryNodes[oldIndex].Remove(); SplitBlock(allocatedBlock, oldIndex, index); @@ -396,7 +402,10 @@ namespace SharpCompress.Compressors.PPMd.I1 unitCountDifference -= unitCount; } - _memoryNodes[UNITS_TO_INDEX[unitCountDifference - 1]].Insert(newPointer, unitCountDifference); + _memoryNodes[UNITS_TO_INDEX[unitCountDifference - 1]].Insert( + newPointer, + unitCountDifference + ); } private void GlueFreeBlocks() @@ -425,7 +434,10 @@ namespace SharpCompress.Compressors.PPMd.I1 memoryNode0 = _memoryNodes[index].Remove(); if (memoryNode0.UnitCount != 0) { - while ((memoryNode2 = memoryNode0 + memoryNode0.UnitCount).Stamp == uint.MaxValue) + while ( + (memoryNode2 = memoryNode0 + memoryNode0.UnitCount).Stamp + == uint.MaxValue + ) { memoryNode0.UnitCount = memoryNode0.UnitCount + memoryNode2.UnitCount; memoryNode2.UnitCount = 0; @@ -453,8 +465,10 @@ namespace SharpCompress.Compressors.PPMd.I1 if (INDEX_TO_UNITS[index] != unitCount) { uint unitCountDifference = unitCount - INDEX_TO_UNITS[--index]; - _memoryNodes[unitCountDifference - 1].Insert(memoryNode0 + (unitCount - unitCountDifference), - unitCountDifference); + _memoryNodes[unitCountDifference - 1].Insert( + memoryNode0 + (unitCount - unitCountDifference), + unitCountDifference + ); } _memoryNodes[index].Insert(memoryNode0, INDEX_TO_UNITS[index]); @@ -482,10 +496,9 @@ namespace SharpCompress.Compressors.PPMd.I1 target[11] = source[11]; target += UNIT_SIZE; source += UNIT_SIZE; - } - while (--unitCount != 0); + } while (--unitCount != 0); } #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/Coder.cs b/src/SharpCompress/Compressors/PPMd/I1/Coder.cs index a5c0d862..7f398284 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Coder.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Coder.cs @@ -33,8 +33,11 @@ namespace SharpCompress.Compressors.PPMd.I1 public void RangeEncoderNormalize(Stream stream) { - while ((_low ^ (_low + _range)) < RANGE_TOP || - _range < RANGE_BOTTOM && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true)) + while ( + (_low ^ (_low + _range)) < RANGE_TOP + || _range < RANGE_BOTTOM + && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true) + ) { stream.WriteByte((byte)(_low >> 24)); _range <<= 8; @@ -76,8 +79,11 @@ namespace SharpCompress.Compressors.PPMd.I1 public void RangeDecoderNormalize(Stream stream) { - while ((_low ^ (_low + _range)) < RANGE_TOP || - _range < RANGE_BOTTOM && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true)) + while ( + (_low ^ (_low + _range)) < RANGE_TOP + || _range < RANGE_BOTTOM + && ((_range = (uint)-_low & (RANGE_BOTTOM - 1)) != 0 || true) + ) { _code = (_code << 8) | (byte)stream.ReadByte(); _range <<= 8; @@ -101,4 +107,4 @@ namespace SharpCompress.Compressors.PPMd.I1 _range *= _highCount - _lowCount; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs b/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs index aee8b181..1c6429ad 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/MemoryNode.cs @@ -44,8 +44,11 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public uint Stamp { - get => _memory[_address] | ((uint)_memory[_address + 1]) << 8 | ((uint)_memory[_address + 2]) << 16 | - ((uint)_memory[_address + 3]) << 24; + get => + _memory[_address] + | ((uint)_memory[_address + 1]) << 8 + | ((uint)_memory[_address + 2]) << 16 + | ((uint)_memory[_address + 3]) << 24; set { _memory[_address] = (byte)value; @@ -60,9 +63,14 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public MemoryNode Next { - get => new MemoryNode( - _memory[_address + 4] | ((uint)_memory[_address + 5]) << 8 | - ((uint)_memory[_address + 6]) << 16 | ((uint)_memory[_address + 7]) << 24, _memory); + get => + new MemoryNode( + _memory[_address + 4] + | ((uint)_memory[_address + 5]) << 8 + | ((uint)_memory[_address + 6]) << 16 + | ((uint)_memory[_address + 7]) << 24, + _memory + ); set { _memory[_address + 4] = (byte)value._address; @@ -77,8 +85,11 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public uint UnitCount { - get => _memory[_address + 8] | ((uint)_memory[_address + 9]) << 8 | - ((uint)_memory[_address + 10]) << 16 | ((uint)_memory[_address + 11]) << 24; + get => + _memory[_address + 8] + | ((uint)_memory[_address + 9]) << 8 + | ((uint)_memory[_address + 10]) << 16 + | ((uint)_memory[_address + 11]) << 24; set { _memory[_address + 8] = (byte)value; @@ -240,4 +251,4 @@ namespace SharpCompress.Compressors.PPMd.I1 return _address.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/Model.cs b/src/SharpCompress/Compressors/PPMd/I1/Model.cs index 347057eb..d7f67b8b 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Model.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Model.cs @@ -52,11 +52,18 @@ namespace SharpCompress.Compressors.PPMd.I1 private static readonly ushort[] INITIAL_BINARY_ESCAPES = { - 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, + 0x3CDD, + 0x1F3F, + 0x59BF, + 0x48F3, + 0x64A1, + 0x5ABC, + 0x6632, 0x6051 }; - private static ReadOnlySpan EXPONENTIAL_ESCAPES => new byte[] { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; + private static ReadOnlySpan EXPONENTIAL_ESCAPES => + new byte[] { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; #region Public Methods @@ -200,8 +207,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { goto StopEncoding; } - } - while (_minimumContext.NumberStatistics == _numberMasked); + } while (_minimumContext.NumberStatistics == _numberMasked); EncodeSymbol2(c, _minimumContext); _coder.RangeEncodeSymbol(); } @@ -222,7 +228,7 @@ namespace SharpCompress.Compressors.PPMd.I1 _coder.RangeEncoderNormalize(target); } - StopEncoding: + StopEncoding: _coder.RangeEncoderFlush(target); } @@ -293,8 +299,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { goto StopDecoding; } - } - while (_minimumContext.NumberStatistics == _numberMasked); + } while (_minimumContext.NumberStatistics == _numberMasked); DecodeSymbol2(_minimumContext); _coder.RangeRemoveSubrange(); } @@ -321,7 +326,7 @@ namespace SharpCompress.Compressors.PPMd.I1 _coder.RangeDecoderNormalize(source); } - StopDecoding: + StopDecoding: return total; } @@ -344,7 +349,11 @@ namespace SharpCompress.Compressors.PPMd.I1 if (modelOrder < 2) { _orderFall = _modelOrder; - for (PpmContext context = _maximumContext; context.Suffix != PpmContext.ZERO; context = context.Suffix) + for ( + PpmContext context = _maximumContext; + context.Suffix != PpmContext.ZERO; + context = context.Suffix + ) { _orderFall--; } @@ -386,14 +395,18 @@ namespace SharpCompress.Compressors.PPMd.I1 } for (int index2 = 0; index2 < 8; index2++) { - _binarySummary[probability, index2] = - (ushort)(BINARY_SCALE - INITIAL_BINARY_ESCAPES[index2] / (index1 + 1)); + _binarySummary[probability, index2] = (ushort)( + BINARY_SCALE - INITIAL_BINARY_ESCAPES[index2] / (index1 + 1) + ); } for (int index2 = 8; index2 < 64; index2 += 8) { for (int index3 = 0; index3 < 8; index3++) { - _binarySummary[probability, index2 + index3] = _binarySummary[probability, index3]; + _binarySummary[probability, index2 + index3] = _binarySummary[ + probability, + index3 + ]; } } } @@ -441,8 +454,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { symbol = state[1].Symbol; state++; - } - while (symbol != foundStateSymbol); + } while (symbol != foundStateSymbol); if (state[0].Frequency >= state[-1].Frequency) { Swap(state[0], state[-1]); @@ -526,7 +538,9 @@ namespace SharpCompress.Compressors.PPMd.I1 } currentContext.Statistics = state; } - currentContext.SummaryFrequency += (ushort)((3 * ns1 + 1 < numberStatistics) ? 1 : 0); + currentContext.SummaryFrequency += (ushort)( + (3 * ns1 + 1 < numberStatistics) ? 1 : 0 + ); } else { @@ -545,8 +559,9 @@ namespace SharpCompress.Compressors.PPMd.I1 { state.Frequency = (byte)(MAXIMUM_FREQUENCY - 4); } - currentContext.SummaryFrequency = - (ushort)(state.Frequency + _initialEscape + ((numberStatistics > 2) ? 1 : 0)); + currentContext.SummaryFrequency = (ushort)( + state.Frequency + _initialEscape + ((numberStatistics > 2) ? 1 : 0) + ); } cf = (uint)(2 * foundStateFrequency * (currentContext.SummaryFrequency + 6)); @@ -559,7 +574,12 @@ namespace SharpCompress.Compressors.PPMd.I1 } else { - cf = (uint)(4 + ((cf > 9 * sf) ? 1 : 0) + ((cf > 12 * sf) ? 1 : 0) + ((cf > 15 * sf) ? 1 : 0)); + cf = (uint)( + 4 + + ((cf > 9 * sf) ? 1 : 0) + + ((cf > 12 * sf) ? 1 : 0) + + ((cf > 15 * sf) ? 1 : 0) + ); currentContext.SummaryFrequency += (ushort)cf; } @@ -573,7 +593,7 @@ namespace SharpCompress.Compressors.PPMd.I1 _maximumContext = foundStateSuccessor; return; - RestartModel: + RestartModel: RestoreModel(currentContext, minimumContext, foundStateSuccessor); } @@ -619,8 +639,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { temporary = state[1].Symbol; state++; - } - while (temporary != symbol); + } while (temporary != symbol); } temporary = (byte)((state.Frequency < MAXIMUM_FREQUENCY - 9) ? 1 : 0); state.Frequency += temporary; @@ -629,21 +648,22 @@ namespace SharpCompress.Compressors.PPMd.I1 else { state = context.FirstState; - state.Frequency += - (byte)(((context.Suffix.NumberStatistics == 0) ? 1 : 0) & ((state.Frequency < 24) ? 1 : 0)); + state.Frequency += (byte)( + ((context.Suffix.NumberStatistics == 0) ? 1 : 0) + & ((state.Frequency < 24) ? 1 : 0) + ); } - LoopEntry: + LoopEntry: if (state.Successor != upBranch) { context = state.Successor; break; } states[stateIndex++] = state; - } - while (context.Suffix != PpmContext.ZERO); + } while (context.Suffix != PpmContext.ZERO); - NoLoop: + NoLoop: if (stateIndex == 0) { return context; @@ -667,12 +687,13 @@ namespace SharpCompress.Compressors.PPMd.I1 { temporary = state[1].Symbol; state++; - } - while (temporary != symbol); + } while (temporary != symbol); } uint cf = (uint)(state.Frequency - 1); uint s0 = (uint)(context.SummaryFrequency - context.NumberStatistics - cf); - localFrequency = (byte)(1 + ((2 * cf <= s0) ? (uint)((5 * cf > s0) ? 1 : 0) : ((cf + 2 * s0 - 3) / s0))); + localFrequency = (byte)( + 1 + ((2 * cf <= s0) ? (uint)((5 * cf > s0) ? 1 : 0) : ((cf + 2 * s0 - 3) / s0)) + ); } else { @@ -694,8 +715,7 @@ namespace SharpCompress.Compressors.PPMd.I1 currentContext.Suffix = context; context = currentContext; states[--stateIndex].Successor = context; - } - while (stateIndex != 0); + } while (stateIndex != 0); return context; } @@ -736,8 +756,7 @@ namespace SharpCompress.Compressors.PPMd.I1 do { states[--stateIndex].Successor = context; - } - while (stateIndex != 0); + } while (stateIndex != 0); _allocator._text = _allocator._heap + 1; _orderFall = 1; } @@ -754,8 +773,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { temporary = state[1].Symbol; state++; - } - while (temporary != symbol); + } while (temporary != symbol); } temporary = (byte)((state.Frequency < MAXIMUM_FREQUENCY - 9) ? 2 : 0); state.Frequency += temporary; @@ -767,7 +785,7 @@ namespace SharpCompress.Compressors.PPMd.I1 state.Frequency += (byte)((state.Frequency < 32) ? 1 : 0); } - LoopEntry: + LoopEntry: if (state.Successor != PpmContext.ZERO) { break; @@ -783,8 +801,7 @@ namespace SharpCompress.Compressors.PPMd.I1 do { states[--stateIndex].Successor = context; - } - while (stateIndex != 0); + } while (stateIndex != 0); _allocator._text = _allocator._heap + 1; _orderFall = 1; return context; @@ -806,26 +823,41 @@ namespace SharpCompress.Compressors.PPMd.I1 return state.Successor; } - private void RestoreModel(PpmContext context, PpmContext minimumContext, PpmContext foundStateSuccessor) + private void RestoreModel( + PpmContext context, + PpmContext minimumContext, + PpmContext foundStateSuccessor + ) { PpmContext currentContext; _allocator._text = _allocator._heap; - for (currentContext = _maximumContext; currentContext != context; currentContext = currentContext.Suffix) + for ( + currentContext = _maximumContext; + currentContext != context; + currentContext = currentContext.Suffix + ) { if (--currentContext.NumberStatistics == 0) { - currentContext.Flags = - (byte) - ((currentContext.Flags & 0x10) + ((currentContext.Statistics.Symbol >= 0x40) ? 0x08 : 0x00)); + currentContext.Flags = (byte)( + (currentContext.Flags & 0x10) + + ((currentContext.Statistics.Symbol >= 0x40) ? 0x08 : 0x00) + ); PpmState state = currentContext.Statistics; Copy(currentContext.FirstState, state); _allocator.SpecialFreeUnits(state); - currentContext.FirstStateFrequency = (byte)((currentContext.FirstStateFrequency + 11) >> 3); + currentContext.FirstStateFrequency = (byte)( + (currentContext.FirstStateFrequency + 11) >> 3 + ); } else { - Refresh((uint)((currentContext.NumberStatistics + 3) >> 1), false, currentContext); + Refresh( + (uint)((currentContext.NumberStatistics + 3) >> 1), + false, + currentContext + ); } } @@ -833,18 +865,29 @@ namespace SharpCompress.Compressors.PPMd.I1 { if (currentContext.NumberStatistics == 0) { - currentContext.FirstStateFrequency -= (byte)(currentContext.FirstStateFrequency >> 1); + currentContext.FirstStateFrequency -= (byte)( + currentContext.FirstStateFrequency >> 1 + ); } - else if ((currentContext.SummaryFrequency += 4) > 128 + 4 * currentContext.NumberStatistics) + else if ( + (currentContext.SummaryFrequency += 4) + > 128 + 4 * currentContext.NumberStatistics + ) { - Refresh((uint)((currentContext.NumberStatistics + 2) >> 1), true, currentContext); + Refresh( + (uint)((currentContext.NumberStatistics + 2) >> 1), + true, + currentContext + ); } } if (_method > ModelRestorationMethod.Freeze) { _maximumContext = foundStateSuccessor; - _allocator._glueCount += (uint)(((_allocator._memoryNodes[1].Stamp & 1) == 0) ? 1 : 0); + _allocator._glueCount += (uint)( + ((_allocator._memoryNodes[1].Stamp & 1) == 0) ? 1 : 0 + ); } else if (_method == ModelRestorationMethod.Freeze) { @@ -858,8 +901,10 @@ namespace SharpCompress.Compressors.PPMd.I1 _allocator._glueCount = 0; _orderFall = _modelOrder; } - else if (_method == ModelRestorationMethod.Restart || - _allocator.GetMemoryUsed() < (_allocator._allocatorSize >> 1)) + else if ( + _method == ModelRestorationMethod.Restart + || _allocator.GetMemoryUsed() < (_allocator._allocatorSize >> 1) + ) { StartModel(_modelOrder, _method); _escapeCount = 0; @@ -875,8 +920,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { CutOff(0, _maximumContext); _allocator.ExpandText(); - } - while (_allocator.GetMemoryUsed() > 3 * (_allocator._allocatorSize >> 2)); + } while (_allocator.GetMemoryUsed() > 3 * (_allocator._allocatorSize >> 2)); _allocator._glueCount = 0; _orderFall = _modelOrder; @@ -918,4 +962,4 @@ namespace SharpCompress.Compressors.PPMd.I1 #endregion } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/ModelRestorationMethod.cs b/src/SharpCompress/Compressors/PPMd/I1/ModelRestorationMethod.cs index 720e9d99..9e89d9da 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/ModelRestorationMethod.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/ModelRestorationMethod.cs @@ -26,4 +26,4 @@ namespace SharpCompress.Compressors.PPMd.I1 /// Freeze = 2 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs b/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs index b17343e7..05748848 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/Pointer.cs @@ -46,7 +46,9 @@ namespace SharpCompress.Compressors.PPMd.I1 #if DEBUG if (_address == 0) { - throw new InvalidOperationException("The pointer being indexed is a null pointer."); + throw new InvalidOperationException( + "The pointer being indexed is a null pointer." + ); } #endif return _memory[_address + offset]; @@ -56,7 +58,9 @@ namespace SharpCompress.Compressors.PPMd.I1 #if DEBUG if (_address == 0) { - throw new InvalidOperationException("The pointer being indexed is a null pointer."); + throw new InvalidOperationException( + "The pointer being indexed is a null pointer." + ); } #endif _memory[_address + offset] = value; @@ -139,7 +143,9 @@ namespace SharpCompress.Compressors.PPMd.I1 #if DEBUG if (pointer._address == 0) { - throw new InvalidOperationException("The pointer being incremented is a null pointer."); + throw new InvalidOperationException( + "The pointer being incremented is a null pointer." + ); } #endif pointer._address++; @@ -192,7 +198,9 @@ namespace SharpCompress.Compressors.PPMd.I1 #if DEBUG if (pointer._address == 0) { - throw new InvalidOperationException("The pointer being decremented is a null pointer."); + throw new InvalidOperationException( + "The pointer being decremented is a null pointer." + ); } #endif pointer._address--; @@ -211,12 +219,14 @@ namespace SharpCompress.Compressors.PPMd.I1 if (pointer1._address == 0) { throw new InvalidOperationException( - "The pointer to the left of the subtraction operator is a null pointer."); + "The pointer to the left of the subtraction operator is a null pointer." + ); } if (pointer2._address == 0) { throw new InvalidOperationException( - "The pointer to the right of the subtraction operator is a null pointer."); + "The pointer to the right of the subtraction operator is a null pointer." + ); } #endif return pointer1._address - pointer2._address; @@ -234,12 +244,14 @@ namespace SharpCompress.Compressors.PPMd.I1 if (pointer1._address == 0) { throw new InvalidOperationException( - "The pointer to the left of the less than operator is a null pointer."); + "The pointer to the left of the less than operator is a null pointer." + ); } if (pointer2._address == 0) { throw new InvalidOperationException( - "The pointer to the right of the less than operator is a null pointer."); + "The pointer to the right of the less than operator is a null pointer." + ); } #endif return pointer1._address < pointer2._address; @@ -257,12 +269,14 @@ namespace SharpCompress.Compressors.PPMd.I1 if (pointer1._address == 0) { throw new InvalidOperationException( - "The pointer to the left of the less than or equal to operator is a null pointer."); + "The pointer to the left of the less than or equal to operator is a null pointer." + ); } if (pointer2._address == 0) { throw new InvalidOperationException( - "The pointer to the right of the less than or equal to operator is a null pointer."); + "The pointer to the right of the less than or equal to operator is a null pointer." + ); } #endif return pointer1._address <= pointer2._address; @@ -280,12 +294,14 @@ namespace SharpCompress.Compressors.PPMd.I1 if (pointer1._address == 0) { throw new InvalidOperationException( - "The pointer to the left of the greater than operator is a null pointer."); + "The pointer to the left of the greater than operator is a null pointer." + ); } if (pointer2._address == 0) { throw new InvalidOperationException( - "The pointer to the right of the greater than operator is a null pointer."); + "The pointer to the right of the greater than operator is a null pointer." + ); } #endif return pointer1._address > pointer2._address; @@ -303,12 +319,14 @@ namespace SharpCompress.Compressors.PPMd.I1 if (pointer1._address == 0) { throw new InvalidOperationException( - "The pointer to the left of the greater than or equal to operator is a null pointer."); + "The pointer to the left of the greater than or equal to operator is a null pointer." + ); } if (pointer2._address == 0) { throw new InvalidOperationException( - "The pointer to the right of the greater than or equal to operator is a null pointer."); + "The pointer to the right of the greater than or equal to operator is a null pointer." + ); } #endif return pointer1._address >= pointer2._address; @@ -360,4 +378,4 @@ namespace SharpCompress.Compressors.PPMd.I1 return _address.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs b/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs index f75cbd3a..35d020b6 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/PpmContext.cs @@ -36,12 +36,20 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// Gets or sets the number statistics. /// - public byte NumberStatistics { get => _memory[_address]; set => _memory[_address] = value; } + public byte NumberStatistics + { + get => _memory[_address]; + set => _memory[_address] = value; + } /// /// Gets or sets the flags. /// - public byte Flags { get => _memory[_address + 1]; set => _memory[_address + 1] = value; } + public byte Flags + { + get => _memory[_address + 1]; + set => _memory[_address + 1] = value; + } /// /// Gets or sets the summary frequency. @@ -61,9 +69,14 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public PpmState Statistics { - get => new PpmState( - _memory[_address + 4] | ((uint)_memory[_address + 5]) << 8 | - ((uint)_memory[_address + 6]) << 16 | ((uint)_memory[_address + 7]) << 24, _memory); + get => + new PpmState( + _memory[_address + 4] + | ((uint)_memory[_address + 5]) << 8 + | ((uint)_memory[_address + 6]) << 16 + | ((uint)_memory[_address + 7]) << 24, + _memory + ); set { _memory[_address + 4] = (byte)value._address; @@ -78,9 +91,14 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public PpmContext Suffix { - get => new PpmContext( - _memory[_address + 8] | ((uint)_memory[_address + 9]) << 8 | - ((uint)_memory[_address + 10]) << 16 | ((uint)_memory[_address + 11]) << 24, _memory); + get => + new PpmContext( + _memory[_address + 8] + | ((uint)_memory[_address + 9]) << 8 + | ((uint)_memory[_address + 10]) << 16 + | ((uint)_memory[_address + 11]) << 24, + _memory + ); set { _memory[_address + 8] = (byte)value._address; @@ -122,14 +140,22 @@ namespace SharpCompress.Compressors.PPMd.I1 /// information can be obtained using the Symbol property on the PPM state provided by the /// property. /// - public byte FirstStateSymbol { get => _memory[_address + 2]; set => _memory[_address + 2] = value; } + public byte FirstStateSymbol + { + get => _memory[_address + 2]; + set => _memory[_address + 2] = value; + } /// /// Gets or sets the frequency of the first PPM state. This is provided for convenience. The same /// information can be obtained using the Frequency property on the PPM state provided by the ///context.FirstState property. /// - public byte FirstStateFrequency { get => _memory[_address + 3]; set => _memory[_address + 3] = value; } + public byte FirstStateFrequency + { + get => _memory[_address + 3]; + set => _memory[_address + 3] = value; + } /// /// Gets or sets the successor of the first PPM state. This is provided for convenience. The same @@ -137,9 +163,14 @@ namespace SharpCompress.Compressors.PPMd.I1 /// public PpmContext FirstStateSuccessor { - get => new PpmContext( - _memory[_address + 4] | ((uint)_memory[_address + 5]) << 8 | - ((uint)_memory[_address + 6]) << 16 | ((uint)_memory[_address + 7]) << 24, _memory); + get => + new PpmContext( + _memory[_address + 4] + | ((uint)_memory[_address + 5]) << 8 + | ((uint)_memory[_address + 6]) << 16 + | ((uint)_memory[_address + 7]) << 24, + _memory + ); set { _memory[_address + 4] = (byte)value._address; @@ -256,8 +287,11 @@ namespace SharpCompress.Compressors.PPMd.I1 { PpmState state = context.FirstState; int index1 = _probabilities[state.Frequency - 1]; - int index2 = _numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + _previousSuccess + - context.Flags + ((_runLength >> 26) & 0x20); + int index2 = + _numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + + _previousSuccess + + context.Flags + + ((_runLength >> 26) & 0x20); if (state.Symbol == symbol) { @@ -265,15 +299,20 @@ namespace SharpCompress.Compressors.PPMd.I1 state.Frequency += (byte)((state.Frequency < 196) ? 1 : 0); _coder._lowCount = 0; _coder._highCount = _binarySummary[index1, index2]; - _binarySummary[index1, index2] += - (ushort)(INTERVAL - Mean(_binarySummary[index1, index2], PERIOD_BIT_COUNT, 2)); + _binarySummary[index1, index2] += (ushort)( + INTERVAL - Mean(_binarySummary[index1, index2], PERIOD_BIT_COUNT, 2) + ); _previousSuccess = 1; _runLength++; } else { _coder._lowCount = _binarySummary[index1, index2]; - _binarySummary[index1, index2] -= (ushort)Mean(_binarySummary[index1, index2], PERIOD_BIT_COUNT, 2); + _binarySummary[index1, index2] -= (ushort)Mean( + _binarySummary[index1, index2], + PERIOD_BIT_COUNT, + 2 + ); _coder._highCount = BINARY_SCALE; _initialEscape = EXPONENTIAL_ESCAPES[_binarySummary[index1, index2] >> 10]; _characterMask[state.Symbol] = _escapeCount; @@ -321,8 +360,7 @@ namespace SharpCompress.Compressors.PPMd.I1 do { _characterMask[(--state).Symbol] = _escapeCount; - } - while (--index != 0); + } while (--index != 0); _coder._highCount = _coder._scale; return; } @@ -345,16 +383,14 @@ namespace SharpCompress.Compressors.PPMd.I1 { currentSymbol = state[1].Symbol; state++; - } - while (_characterMask[currentSymbol] == _escapeCount); + } while (_characterMask[currentSymbol] == _escapeCount); _characterMask[currentSymbol] = _escapeCount; if (currentSymbol == symbol) { goto SymbolFound; } lowCount += state.Frequency; - } - while (--index != 0); + } while (--index != 0); _coder._lowCount = lowCount; _coder._scale += _coder._lowCount; @@ -363,18 +399,17 @@ namespace SharpCompress.Compressors.PPMd.I1 _numberMasked = context.NumberStatistics; return; - SymbolFound: + SymbolFound: _coder._lowCount = lowCount; lowCount += state.Frequency; _coder._highCount = lowCount; - for (PpmState p1 = state; --index != 0;) + for (PpmState p1 = state; --index != 0; ) { do { currentSymbol = p1[1].Symbol; p1++; - } - while (_characterMask[currentSymbol] == _escapeCount); + } while (_characterMask[currentSymbol] == _escapeCount); lowCount += p1.Frequency; } _coder._scale += lowCount; @@ -386,8 +421,11 @@ namespace SharpCompress.Compressors.PPMd.I1 { PpmState state = context.FirstState; int index1 = _probabilities[state.Frequency - 1]; - int index2 = _numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + _previousSuccess + - context.Flags + ((_runLength >> 26) & 0x20); + int index2 = + _numberStatisticsToBinarySummaryIndex[context.Suffix.NumberStatistics] + + _previousSuccess + + context.Flags + + ((_runLength >> 26) & 0x20); if (_coder.RangeGetCurrentShiftCount(TOTAL_BIT_COUNT) < _binarySummary[index1, index2]) { @@ -395,15 +433,20 @@ namespace SharpCompress.Compressors.PPMd.I1 state.Frequency += (byte)((state.Frequency < 196) ? 1 : 0); _coder._lowCount = 0; _coder._highCount = _binarySummary[index1, index2]; - _binarySummary[index1, index2] += - (ushort)(INTERVAL - Mean(_binarySummary[index1, index2], PERIOD_BIT_COUNT, 2)); + _binarySummary[index1, index2] += (ushort)( + INTERVAL - Mean(_binarySummary[index1, index2], PERIOD_BIT_COUNT, 2) + ); _previousSuccess = 1; _runLength++; } else { _coder._lowCount = _binarySummary[index1, index2]; - _binarySummary[index1, index2] -= (ushort)Mean(_binarySummary[index1, index2], PERIOD_BIT_COUNT, 2); + _binarySummary[index1, index2] -= (ushort)Mean( + _binarySummary[index1, index2], + PERIOD_BIT_COUNT, + 2 + ); _coder._highCount = BINARY_SCALE; _initialEscape = EXPONENTIAL_ESCAPES[_binarySummary[index1, index2] >> 10]; _characterMask[state.Symbol] = _escapeCount; @@ -453,8 +496,7 @@ namespace SharpCompress.Compressors.PPMd.I1 do { _characterMask[(--state).Symbol] = _escapeCount; - } - while (--index != 0); + } while (--index != 0); _coder._highCount = _coder._scale; return; } @@ -480,14 +522,12 @@ namespace SharpCompress.Compressors.PPMd.I1 { currentSymbol = state[1].Symbol; state++; - } - while (_characterMask[currentSymbol] == _escapeCount); + } while (_characterMask[currentSymbol] == _escapeCount); highCount += state.Frequency; _decodeStates[stateIndex++] = state; // note that decodeStates is a static array that is re-used on each call to this method (for performance reasons) - } - while (--index != 0); + } while (--index != 0); _coder._scale += highCount; count = _coder.RangeGetCurrentCount(); @@ -515,8 +555,7 @@ namespace SharpCompress.Compressors.PPMd.I1 { _characterMask[_decodeStates[stateIndex].Symbol] = _escapeCount; stateIndex++; - } - while (--index != 0); + } while (--index != 0); see2Context._summary += (ushort)_coder._scale; } } @@ -562,8 +601,10 @@ namespace SharpCompress.Compressors.PPMd.I1 numberStatistics = context.Suffix.NumberStatistics; int index1 = _probabilities[context.NumberStatistics + 2] - 3; - int index2 = ((context.SummaryFrequency > 11 * (context.NumberStatistics + 1)) ? 1 : 0) + - ((2 * context.NumberStatistics < numberStatistics + _numberMasked) ? 2 : 0) + context.Flags; + int index2 = + ((context.SummaryFrequency > 11 * (context.NumberStatistics + 1)) ? 1 : 0) + + ((2 * context.NumberStatistics < numberStatistics + _numberMasked) ? 2 : 0) + + context.Flags; see2Context = _see2Contexts[index1, index2]; _coder._scale = see2Context.Mean(); } @@ -615,22 +656,19 @@ namespace SharpCompress.Compressors.PPMd.I1 do { Copy(p1[0], p1[-1]); - } - while (localFrequency > (--p1)[-1].Frequency); + } while (localFrequency > (--p1)[-1].Frequency); p1.Symbol = localSymbol; p1.Frequency = localFrequency; p1.Successor = localSuccessor; } - } - while (--index != 0); + } while (--index != 0); if (state.Frequency == 0) { do { index++; - } - while ((--state).Frequency == 0); + } while ((--state).Frequency == 0); escapeFrequency += index; oldUnitCount = (uint)((context.NumberStatistics + 2) >> 1); @@ -640,7 +678,9 @@ namespace SharpCompress.Compressors.PPMd.I1 localSymbol = context.Statistics.Symbol; localFrequency = context.Statistics.Frequency; localSuccessor = context.Statistics.Successor; - localFrequency = (byte)((2 * localFrequency + escapeFrequency - 1) / escapeFrequency); + localFrequency = (byte)( + (2 * localFrequency + escapeFrequency - 1) / escapeFrequency + ); if (localFrequency > MAXIMUM_FREQUENCY / 3) { localFrequency = (byte)(MAXIMUM_FREQUENCY / 3); @@ -649,13 +689,18 @@ namespace SharpCompress.Compressors.PPMd.I1 context.FirstStateSymbol = localSymbol; context.FirstStateFrequency = localFrequency; context.FirstStateSuccessor = localSuccessor; - context.Flags = (byte)((context.Flags & 0x10) + ((localSymbol >= 0x40) ? 0x08 : 0x00)); + context.Flags = (byte)( + (context.Flags & 0x10) + ((localSymbol >= 0x40) ? 0x08 : 0x00) + ); _foundState = context.FirstState; return; } - context.Statistics = _allocator.ShrinkUnits(context.Statistics, oldUnitCount, - (uint)((context.NumberStatistics + 2) >> 1)); + context.Statistics = _allocator.ShrinkUnits( + context.Statistics, + oldUnitCount, + (uint)((context.NumberStatistics + 2) >> 1) + ); context.Flags &= 0xf7; index = context.NumberStatistics; state = context.Statistics; @@ -663,8 +708,7 @@ namespace SharpCompress.Compressors.PPMd.I1 do { context.Flags |= (byte)(((++state).Symbol >= 0x40) ? 0x08 : 0x00); - } - while (--index != 0); + } while (--index != 0); } escapeFrequency -= (escapeFrequency >> 1); @@ -679,10 +723,16 @@ namespace SharpCompress.Compressors.PPMd.I1 int escapeFrequency; int scaleValue = (scale ? 1 : 0); - context.Statistics = _allocator.ShrinkUnits(context.Statistics, oldUnitCount, (uint)((index + 2) >> 1)); + context.Statistics = _allocator.ShrinkUnits( + context.Statistics, + oldUnitCount, + (uint)((index + 2) >> 1) + ); PpmState statistics = context.Statistics; - context.Flags = - (byte)((context.Flags & (0x10 + (scale ? 0x04 : 0x00))) + ((statistics.Symbol >= 0x40) ? 0x08 : 0x00)); + context.Flags = (byte)( + (context.Flags & (0x10 + (scale ? 0x04 : 0x00))) + + ((statistics.Symbol >= 0x40) ? 0x08 : 0x00) + ); escapeFrequency = context.SummaryFrequency - statistics.Frequency; statistics.Frequency = (byte)((statistics.Frequency + scaleValue) >> scaleValue); context.SummaryFrequency = statistics.Frequency; @@ -693,8 +743,7 @@ namespace SharpCompress.Compressors.PPMd.I1 statistics.Frequency = (byte)((statistics.Frequency + scaleValue) >> scaleValue); context.SummaryFrequency += statistics.Frequency; context.Flags |= (byte)((statistics.Symbol >= 0x40) ? 0x08 : 0x00); - } - while (--index != 0); + } while (--index != 0); escapeFrequency = (escapeFrequency + scaleValue) >> scaleValue; context.SummaryFrequency += (ushort)escapeFrequency; @@ -763,7 +812,9 @@ namespace SharpCompress.Compressors.PPMd.I1 } if (index == 0) { - context.Flags = (byte)((context.Flags & 0x10) + ((state.Symbol >= 0x40) ? 0x08 : 0x00)); + context.Flags = (byte)( + (context.Flags & 0x10) + ((state.Symbol >= 0x40) ? 0x08 : 0x00) + ); Copy(context.FirstState, state); _allocator.FreeUnits(state, unitCount); context.FirstStateFrequency = (byte)((context.FirstStateFrequency + 11) >> 3); @@ -790,8 +841,10 @@ namespace SharpCompress.Compressors.PPMd.I1 { state.Successor = PpmContext.ZERO; } - if ((state.Successor == PpmContext.ZERO) && - (context.Suffix.NumberStatistics == 0 || context.Suffix.Flags == 0xff)) + if ( + (state.Successor == PpmContext.ZERO) + && (context.Suffix.NumberStatistics == 0 || context.Suffix.Flags == 0xff) + ) { _allocator.FreeUnits(context, 1); return PpmContext.ZERO; @@ -799,7 +852,11 @@ namespace SharpCompress.Compressors.PPMd.I1 return context; } - for (PpmState state = context.Statistics + context.NumberStatistics; state >= context.Statistics; state--) + for ( + PpmState state = context.Statistics + context.NumberStatistics; + state >= context.Statistics; + state-- + ) { if ((Pointer)state.Successor >= _allocator._baseUnit && order < _modelOrder) { @@ -814,4 +871,4 @@ namespace SharpCompress.Compressors.PPMd.I1 return context; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs b/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs index dc72009d..de88fea1 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/PpmState.cs @@ -34,21 +34,34 @@ namespace SharpCompress.Compressors.PPMd.I1 /// /// Gets or sets the symbol. /// - public byte Symbol { get => _memory[_address]; set => _memory[_address] = value; } + public byte Symbol + { + get => _memory[_address]; + set => _memory[_address] = value; + } /// /// Gets or sets the frequency. /// - public byte Frequency { get => _memory[_address + 1]; set => _memory[_address + 1] = value; } + public byte Frequency + { + get => _memory[_address + 1]; + set => _memory[_address + 1] = value; + } /// /// Gets or sets the successor. /// public Model.PpmContext Successor { - get => new Model.PpmContext( - _memory[_address + 2] | ((uint)_memory[_address + 3]) << 8 | - ((uint)_memory[_address + 4]) << 16 | ((uint)_memory[_address + 5]) << 24, _memory); + get => + new Model.PpmContext( + _memory[_address + 2] + | ((uint)_memory[_address + 3]) << 8 + | ((uint)_memory[_address + 4]) << 16 + | ((uint)_memory[_address + 5]) << 24, + _memory + ); set { _memory[_address + 2] = (byte)value._address; @@ -190,4 +203,4 @@ namespace SharpCompress.Compressors.PPMd.I1 return _address.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/I1/See2Context.cs b/src/SharpCompress/Compressors/PPMd/I1/See2Context.cs index 3029d85b..68e09cca 100644 --- a/src/SharpCompress/Compressors/PPMd/I1/See2Context.cs +++ b/src/SharpCompress/Compressors/PPMd/I1/See2Context.cs @@ -52,4 +52,4 @@ namespace SharpCompress.Compressors.PPMd.I1 } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs b/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs index 08eef12c..326b6019 100644 --- a/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs +++ b/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs @@ -6,21 +6,19 @@ namespace SharpCompress.Compressors.PPMd { public class PpmdProperties { - private int _allocatorSize; internal Allocator? _allocator; - public PpmdProperties() - : this(16 << 20, 6) - { - } + public PpmdProperties() : this(16 << 20, 6) { } public PpmdProperties(int allocatorSize, int modelOrder) - : this(allocatorSize, modelOrder, ModelRestorationMethod.Restart) - { - } + : this(allocatorSize, modelOrder, ModelRestorationMethod.Restart) { } - internal PpmdProperties(int allocatorSize, int modelOrder, ModelRestorationMethod modelRestorationMethod) + internal PpmdProperties( + int allocatorSize, + int modelOrder, + ModelRestorationMethod modelRestorationMethod + ) { AllocatorSize = allocatorSize; ModelOrder = modelOrder; @@ -31,9 +29,7 @@ namespace SharpCompress.Compressors.PPMd public PpmdVersion Version { get; } = PpmdVersion.I1; internal ModelRestorationMethod RestorationMethod { get; } - public PpmdProperties(byte[] properties) : this(properties.AsSpan()) - { - } + public PpmdProperties(byte[] properties) : this(properties.AsSpan()) { } public PpmdProperties(ReadOnlySpan properties) { @@ -74,7 +70,12 @@ namespace SharpCompress.Compressors.PPMd byte[] bytes = new byte[2]; BinaryPrimitives.WriteUInt16LittleEndian( bytes, - (ushort)((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort)RestorationMethod << 12))); + (ushort)( + (ModelOrder - 1) + + (((AllocatorSize >> 20) - 1) << 4) + + ((ushort)RestorationMethod << 12) + ) + ); return bytes; } } diff --git a/src/SharpCompress/Compressors/PPMd/PpmdStream.cs b/src/SharpCompress/Compressors/PPMd/PpmdStream.cs index 33715c3a..4e48d71a 100644 --- a/src/SharpCompress/Compressors/PPMd/PpmdStream.cs +++ b/src/SharpCompress/Compressors/PPMd/PpmdStream.cs @@ -65,9 +65,7 @@ namespace SharpCompress.Compressors.PPMd public override bool CanWrite => _compress; - public override void Flush() - { - } + public override void Flush() { } protected override void Dispose(bool isDisposing) { @@ -88,7 +86,11 @@ namespace SharpCompress.Compressors.PPMd public override long Length => throw new NotSupportedException(); - public override long Position { get => _position; set => throw new NotSupportedException(); } + public override long Position + { + get => _position; + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -141,4 +143,4 @@ namespace SharpCompress.Compressors.PPMd } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs b/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs index 8ab1aa38..cd0d6f46 100644 --- a/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs +++ b/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs @@ -6,4 +6,4 @@ H7Z, I1 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs b/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs index 61201b62..db406df9 100644 --- a/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs +++ b/src/SharpCompress/Compressors/Rar/MultiVolumeReadOnlyStream.cs @@ -21,7 +21,10 @@ namespace SharpCompress.Compressors.Rar private long currentPartTotalReadBytes; private long currentEntryTotalReadBytes; - internal MultiVolumeReadOnlyStream(IEnumerable parts, IExtractionListener streamListener) + internal MultiVolumeReadOnlyStream( + IEnumerable parts, + IExtractionListener streamListener + ) { this.streamListener = streamListener; @@ -54,9 +57,11 @@ namespace SharpCompress.Compressors.Rar CurrentCrc = filePartEnumerator.Current.FileHeader.FileCrc; - streamListener.FireFilePartExtractionBegin(filePartEnumerator.Current.FilePartName, - filePartEnumerator.Current.FileHeader.CompressedSize, - filePartEnumerator.Current.FileHeader.UncompressedSize); + streamListener.FireFilePartExtractionBegin( + filePartEnumerator.Current.FilePartName, + filePartEnumerator.Current.FileHeader.CompressedSize, + filePartEnumerator.Current.FileHeader.UncompressedSize + ); } public override int Read(byte[] buffer, int offset, int count) @@ -82,18 +87,24 @@ namespace SharpCompress.Compressors.Rar currentOffset += read; currentCount -= read; totalRead += read; - if (((maxPosition - currentPosition) == 0) - && filePartEnumerator.Current.FileHeader.IsSplitAfter) + if ( + ((maxPosition - currentPosition) == 0) + && filePartEnumerator.Current.FileHeader.IsSplitAfter + ) { if (filePartEnumerator.Current.FileHeader.R4Salt != null) { - throw new InvalidFormatException("Sharpcompress currently does not support multi-volume decryption."); + throw new InvalidFormatException( + "Sharpcompress currently does not support multi-volume decryption." + ); } string fileName = filePartEnumerator.Current.FileHeader.FileName; if (!filePartEnumerator.MoveNext()) { throw new InvalidFormatException( - "Multi-part rar file is incomplete. Entry expects a new volume: " + fileName); + "Multi-part rar file is incomplete. Entry expects a new volume: " + + fileName + ); } InitializeNextFilePart(); } @@ -104,7 +115,10 @@ namespace SharpCompress.Compressors.Rar } currentPartTotalReadBytes += totalRead; currentEntryTotalReadBytes += totalRead; - streamListener.FireCompressedBytesRead(currentPartTotalReadBytes, currentEntryTotalReadBytes); + streamListener.FireCompressedBytesRead( + currentPartTotalReadBytes, + currentEntryTotalReadBytes + ); return totalRead; } @@ -123,7 +137,11 @@ namespace SharpCompress.Compressors.Rar public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override long Seek(long offset, SeekOrigin origin) { @@ -140,4 +158,4 @@ namespace SharpCompress.Compressors.Rar throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/RarCRC.cs b/src/SharpCompress/Compressors/Rar/RarCRC.cs index c9e8159c..a7e565a4 100644 --- a/src/SharpCompress/Compressors/Rar/RarCRC.cs +++ b/src/SharpCompress/Compressors/Rar/RarCRC.cs @@ -46,4 +46,4 @@ namespace SharpCompress.Compressors.Rar } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/RarCrcStream.cs b/src/SharpCompress/Compressors/Rar/RarCrcStream.cs index 127cef25..120d8c3e 100644 --- a/src/SharpCompress/Compressors/Rar/RarCrcStream.cs +++ b/src/SharpCompress/Compressors/Rar/RarCrcStream.cs @@ -8,8 +8,11 @@ namespace SharpCompress.Compressors.Rar private readonly MultiVolumeReadOnlyStream readStream; private uint currentCrc; - public RarCrcStream(IRarUnpack unpack, FileHeader fileHeader, MultiVolumeReadOnlyStream readStream) - : base(unpack, fileHeader, readStream) + public RarCrcStream( + IRarUnpack unpack, + FileHeader fileHeader, + MultiVolumeReadOnlyStream readStream + ) : base(unpack, fileHeader, readStream) { this.readStream = readStream; ResetCrc(); @@ -41,4 +44,4 @@ namespace SharpCompress.Compressors.Rar return result; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/RarStream.cs b/src/SharpCompress/Compressors/Rar/RarStream.cs index 2ad3c9b8..9c470fbd 100644 --- a/src/SharpCompress/Compressors/Rar/RarStream.cs +++ b/src/SharpCompress/Compressors/Rar/RarStream.cs @@ -52,14 +52,16 @@ namespace SharpCompress.Compressors.Rar public override bool CanWrite => false; - public override void Flush() - { - } + public override void Flush() { } public override long Length => fileHeader.UncompressedSize; //commented out code always returned the length of the file - public override long Position { get => _position; /* fileHeader.UncompressedSize - unpack.DestSize;*/ set => throw new NotSupportedException(); } + public override long Position + { + get => _position; /* fileHeader.UncompressedSize - unpack.DestSize;*/ + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -117,8 +119,11 @@ namespace SharpCompress.Compressors.Rar { if (tmpBuffer.Length < tmpCount + count) { - byte[] newBuffer = - new byte[tmpBuffer.Length * 2 > tmpCount + count ? tmpBuffer.Length * 2 : tmpCount + count]; + byte[] newBuffer = new byte[ + tmpBuffer.Length * 2 > tmpCount + count + ? tmpBuffer.Length * 2 + : tmpCount + count + ]; Buffer.BlockCopy(tmpBuffer, 0, newBuffer, 0, tmpCount); tmpBuffer = newBuffer; } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/AudioVariables.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/AudioVariables.cs index c2510617..3e7319f3 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/AudioVariables.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/AudioVariables.cs @@ -23,4 +23,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode internal int LastChar { get; set; } internal int LastDelta { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/BitDecode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/BitDecode.cs index a8d499b5..aa8ff4dd 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/BitDecode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/BitDecode.cs @@ -2,9 +2,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class BitDecode : Decode { - internal BitDecode() - : base(new int[PackDef.BC]) - { - } + internal BitDecode() : base(new int[PackDef.BC]) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/CodeType.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/CodeType.cs index e9703ff1..a0f31371 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/CodeType.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/CodeType.cs @@ -12,4 +12,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode CODE_VM, CODE_VMDATA } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/Decode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/Decode.cs index ceed74de..7634dc7e 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/Decode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/Decode.cs @@ -2,10 +2,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class Decode { - internal Decode() - : this(new int[2]) - { - } + internal Decode() : this(new int[2]) { } protected Decode(int[] customDecodeNum) { @@ -31,4 +28,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode internal int MaxNum { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/DistDecode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/DistDecode.cs index 1a0b666b..9b49acc3 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/DistDecode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/DistDecode.cs @@ -2,9 +2,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class DistDecode : Decode { - internal DistDecode() - : base(new int[PackDef.DC]) - { - } + internal DistDecode() : base(new int[PackDef.DC]) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/FilterType.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/FilterType.cs index 32166837..1a6360dc 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/FilterType.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/FilterType.cs @@ -4,7 +4,14 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { // These values must not be changed, because we use them directly // in RAR5 compression and decompression code. - FILTER_DELTA = 0, FILTER_E8, FILTER_E8E9, FILTER_ARM, - FILTER_AUDIO, FILTER_RGB, FILTER_ITANIUM, FILTER_PPM, FILTER_NONE + FILTER_DELTA = 0, + FILTER_E8, + FILTER_E8E9, + FILTER_ARM, + FILTER_AUDIO, + FILTER_RGB, + FILTER_ITANIUM, + FILTER_PPM, + FILTER_NONE } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LitDecode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LitDecode.cs index 8316c261..035e7ce4 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LitDecode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LitDecode.cs @@ -2,9 +2,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class LitDecode : Decode { - internal LitDecode() - : base(new int[PackDef.NC]) - { - } + internal LitDecode() : base(new int[PackDef.NC]) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LowDistDecode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LowDistDecode.cs index a2095bd4..d3f358e8 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LowDistDecode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/LowDistDecode.cs @@ -2,9 +2,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class LowDistDecode : Decode { - internal LowDistDecode() - : base(new int[PackDef.LDC]) - { - } + internal LowDistDecode() : base(new int[PackDef.LDC]) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/MultDecode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/MultDecode.cs index e6df223c..6342ac1f 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/MultDecode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/MultDecode.cs @@ -2,9 +2,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class MultDecode : Decode { - internal MultDecode() - : base(new int[PackDef.MC20]) - { - } + internal MultDecode() : base(new int[PackDef.MC20]) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/PackDef.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/PackDef.cs index 163ba5f3..00ee5bb6 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/PackDef.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/PackDef.cs @@ -15,6 +15,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode public const int DC = 60; public const int LDC = 17; public const int RC = 28; + // 20171217: NOTE: these constants seem to have been updated in the unrar src code // at some unknown point. updating causes decompression failure, not sure why. // public const int NC = 306; /* alphabet = {0, 1, 2, ..., NC - 1} */ @@ -45,4 +46,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode // CODE_ENDFILE, CODE_FILTER, CODE_FILTERDATA //} } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/RepDecode.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/RepDecode.cs index 24d72d16..648630e1 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/RepDecode.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Decode/RepDecode.cs @@ -2,9 +2,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.Decode { internal class RepDecode : Decode { - internal RepDecode() - : base(new int[PackDef.RC]) - { - } + internal RepDecode() : base(new int[PackDef.RC]) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/PPM/BlockTypes.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/PPM/BlockTypes.cs index b3f79fdc..c25fae4e 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/PPM/BlockTypes.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/PPM/BlockTypes.cs @@ -5,4 +5,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1.PPM BLOCK_LZ = 0, BLOCK_PPM = 1 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs index cc33b25f..63dd4875 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs @@ -22,7 +22,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 Inp = this; } - public bool FileExtracted { get; private set; } public long DestSize @@ -87,7 +86,28 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private int lowDistRepCount; - private static readonly int[] DBitLengthCounts = { 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 0, 12 }; + private static readonly int[] DBitLengthCounts = + { + 4, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 14, + 0, + 12 + }; private FileHeader fileHeader; @@ -149,7 +169,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 break; default: - throw new InvalidFormatException("unknown rar compression version " + fileHeader.CompressionAlgorithm); + throw new InvalidFormatException( + "unknown rar compression version " + fileHeader.CompressionAlgorithm + ); } } @@ -185,7 +207,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 if (DDecode[1] == 0) { - int Dist = 0, BitLength = 0, Slot = 0; + int Dist = 0, + BitLength = 0, + Slot = 0; for (int I = 0; I < DBitLengthCounts.Length; I++, BitLength++) { int count = DBitLengthCounts[I]; @@ -277,7 +301,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } if (NextCh == 4) { - int Distance = 0, Length = 0; + int Distance = 0, + Length = 0; bool failed = false; for (int I = 0; I < 4 && !failed; I++) { @@ -506,10 +531,15 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // Prg->GlobalData.Alloc(ParentPrg->GlobalData.Size()); // memcpy(&Prg->GlobalData[VM_FIXEDGLOBALSIZE],&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],ParentPrg->GlobalData.Size()-VM_FIXEDGLOBALSIZE); Prg.GlobalData.Clear(); - for (int i = 0; i < ParentPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++) + for ( + int i = 0; + i < ParentPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; + i++ + ) { - Prg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = - ParentPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i]; + Prg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = ParentPrg.GlobalData[ + RarVM.VM_FIXEDGLOBALSIZE + i + ]; } } @@ -525,10 +555,15 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } // memcpy(&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],&Prg->GlobalData[VM_FIXEDGLOBALSIZE],Prg->GlobalData.Size()-VM_FIXEDGLOBALSIZE); - for (int i = 0; i < Prg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++) + for ( + int i = 0; + i < Prg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; + i++ + ) { - ParentPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = - Prg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i]; + ParentPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = Prg.GlobalData[ + RarVM.VM_FIXEDGLOBALSIZE + i + ]; } } else @@ -553,8 +588,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 while (I + 1 < prgStack.Count) { UnpackFilter NextFilter = prgStack[I + 1]; - if (NextFilter is null || NextFilter.BlockStart != BlockStart || - NextFilter.BlockLength != FilteredDataSize || NextFilter.NextWindow) + if ( + NextFilter is null + || NextFilter.BlockStart != BlockStart + || NextFilter.BlockLength != FilteredDataSize + || NextFilter.NextWindow + ) { break; } @@ -576,7 +615,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 NextPrg.GlobalData.SetSize(pPrg.GlobalData.Count); // memcpy(&NextPrg->GlobalData[VM_FIXEDGLOBALSIZE],&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],ParentPrg->GlobalData.Size()-VM_FIXEDGLOBALSIZE); - for (int i = 0; i < pPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++) + for ( + int i = 0; + i < pPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; + i++ + ) { NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i]; @@ -594,7 +637,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } // memcpy(&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],&NextPrg->GlobalData[VM_FIXEDGLOBALSIZE],NextPrg->GlobalData.Size()-VM_FIXEDGLOBALSIZE); - for (int i = 0; i < NextPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++) + for ( + int i = 0; + i < NextPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; + i++ + ) { pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i]; @@ -711,7 +758,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 int destPtr = unpPtr - distance; // System.out.println(unpPtr+":"+distance); - if (destPtr >= 0 && destPtr < PackDef.MAXWINSIZE - 260 && unpPtr < PackDef.MAXWINSIZE - 260) + if ( + destPtr >= 0 + && destPtr < PackDef.MAXWINSIZE - 260 + && unpPtr < PackDef.MAXWINSIZE - 260 + ) { window[unpPtr++] = window[destPtr++]; @@ -801,7 +852,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private bool ReadEndOfBlock() { int BitField = GetBits(); - bool NewTable, NewFile = false; + bool NewTable, + NewFile = false; if ((BitField & 0x8000) != 0) { NewTable = true; @@ -879,7 +931,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 int TableSize = PackDef.HUFF_TABLE_SIZE; - for (int i = 0; i < TableSize;) + for (int i = 0; i < TableSize; ) { if (inAddr > readTop - 5) { @@ -940,7 +992,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 UnpackUtility.makeDecodeTables(table, 0, LD, PackDef.NC); UnpackUtility.makeDecodeTables(table, PackDef.NC, DD, PackDef.DC); UnpackUtility.makeDecodeTables(table, PackDef.NC + PackDef.DC, LDD, PackDef.LDC); - UnpackUtility.makeDecodeTables(table, PackDef.NC + PackDef.DC + PackDef.LDC, RD, PackDef.RC); + UnpackUtility.makeDecodeTables( + table, + PackDef.NC + PackDef.DC + PackDef.LDC, + RD, + PackDef.RC + ); // memcpy(unpOldTable,table,sizeof(unpOldTable)); @@ -1065,7 +1122,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 UnpackFilter Filter; if (NewFilter) - // new filter code, never used before since VM reset { // too many different filters, corrupt archive @@ -1081,7 +1137,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 oldFilterLengths.Add(0); Filter.ExecCount = 0; } - // filter was used in the past else { @@ -1105,9 +1160,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } else { - StackFilter.BlockLength = FiltPos < oldFilterLengths.Count ? oldFilterLengths[FiltPos] : 0; + StackFilter.BlockLength = + FiltPos < oldFilterLengths.Count ? oldFilterLengths[FiltPos] : 0; } - StackFilter.NextWindow = (wrPtr != unpPtr) && ((wrPtr - unpPtr) & PackDef.MAXWINMASK) <= BlockStart; + StackFilter.NextWindow = + (wrPtr != unpPtr) && ((wrPtr - unpPtr) & PackDef.MAXWINMASK) <= BlockStart; // DebugLog("\nNextWindow: UnpPtr=%08x WrPtr=%08x // BlockStart=%08x",UnpPtr,WrPtr,BlockStart); @@ -1123,7 +1180,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 StackFilter.Program.InitR[5] = StackFilter.ExecCount; // StackFilter->Prg.InitR[5]=StackFilter->ExecCount; if ((firstByte & 0x10) != 0) - // set registers to optional parameters // if any { @@ -1210,7 +1266,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 globalData[0x30 + i] = 0x0; } if ((firstByte & 8) != 0) - // put data block passed as parameter if any { if (Inp.Overflow(3)) @@ -1226,7 +1281,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 if (CurSize < DataSize + RarVM.VM_FIXEDGLOBALSIZE) { // StackFilter->Prg.GlobalData.Add(DataSize+VM_FIXEDGLOBALSIZE-CurSize); - StackFilter.Program.GlobalData.SetSize(DataSize + RarVM.VM_FIXEDGLOBALSIZE - CurSize); + StackFilter.Program.GlobalData.SetSize( + DataSize + RarVM.VM_FIXEDGLOBALSIZE - CurSize + ); } int offset = RarVM.VM_FIXEDGLOBALSIZE; globalData = StackFilter.Program.GlobalData; @@ -1256,7 +1313,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // rarVM.SetLowEndianValue((uint // *)&Prg->GlobalData[0x28],int64to32(WrittenFileSize>>32)); - rarVM.SetLowEndianValue(Prg.GlobalData, 0x28, (int)(Utility.URShift(writtenFileSize, 32))); + rarVM.SetLowEndianValue( + Prg.GlobalData, + 0x28, + (int)(Utility.URShift(writtenFileSize, 32)) + ); rarVM.execute(Prg); } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs index 7a0ae2bd..d463a020 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs @@ -35,36 +35,60 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private readonly int[] oldDist = new int[4]; - private int unpPtr, wrPtr; + private int unpPtr, + wrPtr; private int oldDistPtr; private readonly int[] ChSet = new int[256], - ChSetA = new int[256], - ChSetB = new int[256], - ChSetC = new int[256]; + ChSetA = new int[256], + ChSetB = new int[256], + ChSetC = new int[256]; private readonly int[] Place = new int[256], - PlaceA = new int[256], - PlaceB = new int[256], - PlaceC = new int[256]; + PlaceA = new int[256], + PlaceB = new int[256], + PlaceC = new int[256]; - private readonly int[] NToPl = new int[256], NToPlB = new int[256], NToPlC = new int[256]; + private readonly int[] NToPl = new int[256], + NToPlB = new int[256], + NToPlC = new int[256]; - private int FlagBuf, AvrPlc, AvrPlcB, AvrLn1, AvrLn2, AvrLn3; + private int FlagBuf, + AvrPlc, + AvrPlcB, + AvrLn1, + AvrLn2, + AvrLn3; - private int Buf60, NumHuf, StMode, LCount, FlagsCnt; + private int Buf60, + NumHuf, + StMode, + LCount, + FlagsCnt; - private int Nhfb, Nlzb, MaxDist3; + private int Nhfb, + Nlzb, + MaxDist3; - private int lastDist, lastLength; + private int lastDist, + lastLength; private const int STARTL1 = 2; private static readonly int[] DecL1 = { - 0x8000, 0xa000, 0xc000, 0xd000, 0xe000, 0xea00, 0xee00, 0xf000, 0xf200, 0xf200 - , 0xffff + 0x8000, + 0xa000, + 0xc000, + 0xd000, + 0xe000, + 0xea00, + 0xee00, + 0xf000, + 0xf200, + 0xf200, + 0xffff }; private static readonly int[] PosL1 = { 0, 0, 0, 2, 3, 5, 7, 11, 16, 20, 24, 32, 32 }; @@ -73,32 +97,81 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private static readonly int[] DecL2 = { - 0xa000, 0xc000, 0xd000, 0xe000, 0xea00, 0xee00, 0xf000, 0xf200, 0xf240, 0xffff + 0xa000, + 0xc000, + 0xd000, + 0xe000, + 0xea00, + 0xee00, + 0xf000, + 0xf200, + 0xf240, + 0xffff }; private static readonly int[] PosL2 = { 0, 0, 0, 0, 5, 7, 9, 13, 18, 22, 26, 34, 36 }; private const int STARTHF0 = 4; - private static readonly int[] DecHf0 = { 0x8000, 0xc000, 0xe000, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xffff }; + private static readonly int[] DecHf0 = + { + 0x8000, + 0xc000, + 0xe000, + 0xf200, + 0xf200, + 0xf200, + 0xf200, + 0xf200, + 0xffff + }; private static readonly int[] PosHf0 = { 0, 0, 0, 0, 0, 8, 16, 24, 33, 33, 33, 33, 33 }; private const int STARTHF1 = 5; - private static readonly int[] DecHf1 = { 0x2000, 0xc000, 0xe000, 0xf000, 0xf200, 0xf200, 0xf7e0, 0xffff }; + private static readonly int[] DecHf1 = + { + 0x2000, + 0xc000, + 0xe000, + 0xf000, + 0xf200, + 0xf200, + 0xf7e0, + 0xffff + }; private static readonly int[] PosHf1 = { 0, 0, 0, 0, 0, 0, 4, 44, 60, 76, 80, 80, 127 }; private const int STARTHF2 = 5; - private static readonly int[] DecHf2 = { 0x1000, 0x2400, 0x8000, 0xc000, 0xfa00, 0xffff, 0xffff, 0xffff }; + private static readonly int[] DecHf2 = + { + 0x1000, + 0x2400, + 0x8000, + 0xc000, + 0xfa00, + 0xffff, + 0xffff, + 0xffff + }; private static readonly int[] PosHf2 = { 0, 0, 0, 0, 0, 0, 2, 7, 53, 117, 233, 0, 0 }; private const int STARTHF3 = 6; - private static readonly int[] DecHf3 = { 0x800, 0x2400, 0xee00, 0xfe80, 0xffff, 0xffff, 0xffff }; + private static readonly int[] DecHf3 = + { + 0x800, + 0x2400, + 0xee00, + 0xfe80, + 0xffff, + 0xffff, + 0xffff + }; private static readonly int[] PosHf3 = { 0, 0, 0, 0, 0, 0, 0, 2, 16, 218, 251, 0, 0 }; @@ -108,20 +181,82 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private static readonly int[] PosHf4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0 }; - private static readonly int[] ShortLen1 = { 1, 3, 4, 4, 5, 6, 7, 8, 8, 4, 4, 5, 6, 6, 4, 0 }; + private static readonly int[] ShortLen1 = + { + 1, + 3, + 4, + 4, + 5, + 6, + 7, + 8, + 8, + 4, + 4, + 5, + 6, + 6, + 4, + 0 + }; private static readonly int[] ShortXor1 = { - 0, 0xa0, 0xd0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff, 0xc0, 0x80, 0x90, 0x98 - , 0x9c, 0xb0 + 0, + 0xa0, + 0xd0, + 0xe0, + 0xf0, + 0xf8, + 0xfc, + 0xfe, + 0xff, + 0xc0, + 0x80, + 0x90, + 0x98, + 0x9c, + 0xb0 }; - private static readonly int[] ShortLen2 = { 2, 3, 3, 3, 4, 4, 5, 6, 6, 4, 4, 5, 6, 6, 4, 0 }; + private static readonly int[] ShortLen2 = + { + 2, + 3, + 3, + 3, + 4, + 4, + 5, + 6, + 6, + 4, + 4, + 5, + 6, + 6, + 4, + 0 + }; private static readonly int[] ShortXor2 = { - 0, 0x40, 0x60, 0xa0, 0xd0, 0xe0, 0xf0, 0xf8, 0xfc, 0xc0, 0x80, 0x90, 0x98 - , 0x9c, 0xb0 + 0, + 0x40, + 0x60, + 0xa0, + 0xd0, + 0xe0, + 0xf0, + 0xf8, + 0xfc, + 0xc0, + 0x80, + 0x90, + 0x98, + 0x9c, + 0xb0 }; private void unpack15(bool solid) @@ -269,7 +404,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private void shortLZ() { - int Length, SaveLength; + int Length, + SaveLength; int LastDistance; int Distance; int DistancePlace; @@ -292,7 +428,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { for (Length = 0; ; Length++) { - if (((BitField ^ ShortXor1[Length]) & (~(Utility.URShift(0xff, getShortLen1(Length))))) == 0) + if ( + ( + (BitField ^ ShortXor1[Length]) + & (~(Utility.URShift(0xff, getShortLen1(Length)))) + ) == 0 + ) { break; } @@ -383,8 +524,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { int Length; int Distance; - int DistancePlace, NewDistancePlace; - int OldAvr2, OldAvr3; + int DistancePlace, + NewDistancePlace; + int OldAvr2, + OldAvr3; NumHuf = 0; Nlzb += 16; @@ -506,7 +649,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private void huffDecode() { - int CurByte, NewBytePlace; + int CurByte, + NewBytePlace; int Length; int Distance; int BytePlace; @@ -606,7 +750,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private void getFlagsBuf() { - int Flags, NewFlagsPlace; + int Flags, + NewFlagsPlace; int FlagsPlace = decodeNum(GetBits(), STARTHF2, DecHf2, PosHf2); while (true) @@ -660,7 +805,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private void corrHuff(int[] CharSet, int[] NumToPlace) { - int I, J, pos = 0; + int I, + J, + pos = 0; for (I = 7; I >= 0; I--) { for (J = 0; J < 32; J++, pos++) @@ -695,7 +842,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 StartPos++; } AddBits(StartPos); - return ((Utility.URShift((Num - (I != 0 ? DecTab[I - 1] : 0)), (16 - StartPos))) + PosTab[StartPos]); + return ( + (Utility.URShift((Num - (I != 0 ? DecTab[I - 1] : 0)), (16 - StartPos))) + + PosTab[StartPos] + ); } private void oldUnpWriteBuf() diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs index eb0ce540..fa28fc0d 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs @@ -18,7 +18,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private readonly byte[] UnpOldTable20 = new byte[PackDef.MC20 * 4]; - private int UnpAudioBlock, UnpChannels, UnpCurChannel, UnpChannelDelta; + private int UnpAudioBlock, + UnpChannels, + UnpCurChannel, + UnpChannelDelta; private readonly AudioVariables[] AudV = new AudioVariables[4]; @@ -34,30 +37,171 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private static readonly int[] LDecode = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, - 56, 64, 80, 96, 112, 128, 160, 192, 224 + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 10, + 12, + 14, + 16, + 20, + 24, + 28, + 32, + 40, + 48, + 56, + 64, + 80, + 96, + 112, + 128, + 160, + 192, + 224 }; - private static ReadOnlySpan LBits => new byte[] - { - 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 - }; + private static ReadOnlySpan LBits => + new byte[] + { + 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 + }; private static readonly int[] DDecode = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, - 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, - 24576, 32768, 49152, 65536, 98304, 131072, 196608, 262144, 327680, - 393216, 458752, 524288, 589824, 655360, 720896, 786432, 851968, - 917504, 983040 + 0, + 1, + 2, + 3, + 4, + 6, + 8, + 12, + 16, + 24, + 32, + 48, + 64, + 96, + 128, + 192, + 256, + 384, + 512, + 768, + 1024, + 1536, + 2048, + 3072, + 4096, + 6144, + 8192, + 12288, + 16384, + 24576, + 32768, + 49152, + 65536, + 98304, + 131072, + 196608, + 262144, + 327680, + 393216, + 458752, + 524288, + 589824, + 655360, + 720896, + 786432, + 851968, + 917504, + 983040 }; private static readonly int[] DBits = { - 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, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16 - , 16, 16, 16, 16, 16, 16, 16 + 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, + 14, + 14, + 15, + 15, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16 }; private static readonly int[] SDDecode = { 0, 4, 8, 16, 32, 64, 128, 192 }; @@ -249,7 +393,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { byte[] BitLength = new byte[PackDef.BC20]; byte[] Table = new byte[PackDef.MC20 * 4]; - int TableSize, N, I; + int TableSize, + N, + I; if (inAddr > readTop - 25) { if (!unpReadBuf()) @@ -346,7 +492,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { UnpackUtility.makeDecodeTables(Table, 0, LD, PackDef.NC20); UnpackUtility.makeDecodeTables(Table, PackDef.NC20, DD, PackDef.DC20); - UnpackUtility.makeDecodeTables(Table, PackDef.NC20 + PackDef.DC20, RD, PackDef.RC20); + UnpackUtility.makeDecodeTables( + Table, + PackDef.NC20 + PackDef.DC20, + RD, + PackDef.RC20 + ); } // memcpy(UnpOldTable20,Table,sizeof(UnpOldTable20)); @@ -434,7 +585,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 if ((v.ByteCount & 0x1F) == 0) { - int MinDif = v.Dif[0], NumMinDif = 0; + int MinDif = v.Dif[0], + NumMinDif = 0; v.Dif[0] = 0; // ->Dif[0]=0; for (int I = 1; I < v.Dif.Length; I++) { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs index d9e68205..a7cc9408 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/Unpack50.cs @@ -9,7 +9,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { internal partial class Unpack { - // Maximum allowed number of compressed bits processed in quick mode. private const int MAX_QUICK_DECODE_BITS = 10; @@ -108,19 +107,68 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 private const int MaxWinMask = PackDef.MAXWINMASK; // TODO: rename var - private int UnpPtr { get { return unpPtr; } set { unpPtr = value; } } - private int ReadBorder { get { return readBorder; } set { readBorder = value; } } - private long DestUnpSize { get { return destUnpSize; } set { destUnpSize = value; } } - private long WrittenFileSize { get { return writtenFileSize; } set { writtenFileSize = value; } } - private byte[] Window { get { return window; } } - private uint LastLength { get { return (uint)lastLength; } set { lastLength = (int)value; } } - private uint OldDistN(int i) { return (uint)oldDist[i]; } - private void SetOldDistN(int i, uint value) { oldDist[i] = (int)value; } - private int WrPtr { get { return wrPtr; } set { wrPtr = value; } } - private Unpack BlockHeader { get { return this; } } - private Unpack Header { get { return this; } } - private int ReadTop { get { return readTop; } set { readTop = value; } } - private List Filters { get { return filters; } } + private int UnpPtr + { + get { return unpPtr; } + set { unpPtr = value; } + } + private int ReadBorder + { + get { return readBorder; } + set { readBorder = value; } + } + private long DestUnpSize + { + get { return destUnpSize; } + set { destUnpSize = value; } + } + private long WrittenFileSize + { + get { return writtenFileSize; } + set { writtenFileSize = value; } + } + private byte[] Window + { + get { return window; } + } + private uint LastLength + { + get { return (uint)lastLength; } + set { lastLength = (int)value; } + } + + private uint OldDistN(int i) + { + return (uint)oldDist[i]; + } + + private void SetOldDistN(int i, uint value) + { + oldDist[i] = (int)value; + } + + private int WrPtr + { + get { return wrPtr; } + set { wrPtr = value; } + } + private Unpack BlockHeader + { + get { return this; } + } + private Unpack Header + { + get { return this; } + } + private int ReadTop + { + get { return readTop; } + set { readTop = value; } + } + private List Filters + { + get { return filters; } + } // TODO: make sure these aren't already somewhere else public int BlockSize; @@ -145,8 +193,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // Check TablesRead5 to be sure that we read tables at least once // regardless of current block header TablePresent flag. // So we can safefly use these tables below. - if (!ReadBlockHeader() || - !ReadTables() || !TablesRead5) + if (!ReadBlockHeader() || !ReadTables() || !TablesRead5) { return; } @@ -162,9 +209,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // We use 'while', because for empty block containing only Huffman table, // we'll be on the block border once again just after reading the table. - while (Inp.InAddr > BlockHeader.BlockStart + BlockHeader.BlockSize - 1 || - Inp.InAddr == BlockHeader.BlockStart + BlockHeader.BlockSize - 1 && - Inp.InBit >= BlockHeader.BlockBitSize) + while ( + Inp.InAddr > BlockHeader.BlockStart + BlockHeader.BlockSize - 1 + || Inp.InAddr == BlockHeader.BlockStart + BlockHeader.BlockSize - 1 + && Inp.InBit >= BlockHeader.BlockBitSize + ) { if (BlockHeader.LastBlockInFile) { @@ -182,7 +231,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } } - if (((WriteBorder - UnpPtr) & MaxWinMask) < PackDef.MAX_LZ_MATCH + 3 && WriteBorder != UnpPtr) + if ( + ((WriteBorder - UnpPtr) & MaxWinMask) < PackDef.MAX_LZ_MATCH + 3 + && WriteBorder != UnpPtr + ) { UnpWriteBuf(); if (WrittenFileSize > DestUnpSize) @@ -213,7 +265,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 //uint DBits,Distance=1,DistSlot=DecodeNumber(Inp,&BlockTables.DD); int DBits; - uint Distance = 1, DistSlot = this.DecodeNumber(DD); + uint Distance = 1, + DistSlot = this.DecodeNumber(DD); if (DistSlot < 4) { DBits = 0; @@ -379,7 +432,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // If distance to filter start is that large that due to circular dictionary // mode now it points to old not written yet data, then we set 'NextWindow' // flag and process this filter only after processing that older data. - Filter.NextWindow = WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; + Filter.NextWindow = + WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; Filter.uBlockStart = (uint)((Filter.BlockStart + UnpPtr) & MaxWinMask); Filters.Add(Filter); @@ -438,7 +492,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 { // We may need to quit from main extraction loop and read new block header // and trees earlier than data in input buffer ends. - ReadBorder = Math.Min(ReadBorder, BlockHeader.BlockStart + BlockHeader.BlockSize - 1); + ReadBorder = Math.Min( + ReadBorder, + BlockHeader.BlockStart + BlockHeader.BlockSize - 1 + ); } return ReadCode != -1; } @@ -581,7 +638,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // // // Choose the nearest among WriteBorder and WrPtr actual written border. // // If border is equal to UnpPtr, it means that we have MaxWinSize data ahead. - // if (WriteBorder==UnpPtr || + // if (WriteBorder==UnpPtr || // WrPtr!=UnpPtr && ((WrPtr-UnpPtr)&MaxWinMask)<((WriteBorder-UnpPtr)&MaxWinMask)) // WriteBorder=WrPtr; // } @@ -766,7 +823,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } Header.BlockSize = BlockSize; - byte CheckSum = (byte)(0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16)); + byte CheckSum = (byte)( + 0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16) + ); if (CheckSum != SavedCheckSum) { return false; @@ -890,7 +949,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 // { // Filters.SoftReset(); // } - } } -#endif \ No newline at end of file +#endif diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackFilter.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackFilter.cs index 66d5d887..82fb4e5e 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackFilter.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackFilter.cs @@ -13,8 +13,16 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } // TODO uint - internal uint uBlockStart { get { return (uint)BlockStart; } set { BlockStart = (int)value; } } - internal uint uBlockLength { get { return (uint)BlockLength; } set { BlockLength = (int)value; } } + internal uint uBlockStart + { + get { return (uint)BlockStart; } + set { BlockStart = (int)value; } + } + internal uint uBlockLength + { + get { return (uint)BlockLength; } + set { BlockLength = (int)value; } + } internal int BlockStart { get; set; } @@ -30,4 +38,4 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 internal VMPreparedProgram Program { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs index e509afa2..c49007f7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackInline.cs @@ -1,5 +1,4 @@ - -namespace SharpCompress.Compressors.Rar.UnpackV1 +namespace SharpCompress.Compressors.Rar.UnpackV1 { internal partial class Unpack { diff --git a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs index ec04db1c..b00ffcfa 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV1/UnpackUtility.cs @@ -174,7 +174,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 } } input.AddBits(bits); - int N = dec.DecodePos[bits] + (Utility.URShift(((int)bitField - decodeLen[bits - 1]), (16 - bits))); + int N = + dec.DecodePos[bits] + + (Utility.URShift(((int)bitField - decodeLen[bits - 1]), (16 - bits))); if (N >= dec.MaxNum) { N = 0; @@ -182,12 +184,18 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 return (dec.DecodeNum[N]); } - internal static void makeDecodeTables(byte[] lenTab, int offset, Decode.Decode dec, int size) + internal static void makeDecodeTables( + byte[] lenTab, + int offset, + Decode.Decode dec, + int size + ) { Span lenCount = stackalloc int[16]; Span tmpPos = stackalloc int[16]; int i; - long M, N; + long M, + N; new Span(dec.DecodeNum).Clear(); // memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum)); @@ -196,7 +204,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV1 lenCount[lenTab[offset + i] & 0xF]++; } lenCount[0] = 0; - for (tmpPos[0] = 0, dec.DecodePos[0] = 0, dec.DecodeLen[0] = 0, N = 0, i = 1; i < 16; i++) + for ( + tmpPos[0] = 0, dec.DecodePos[0] = 0, dec.DecodeLen[0] = 0, N = 0, i = 1; + i < 16; + i++ + ) { N = 2 * (N + lenCount[i]); M = N << (15 - i); diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs index c1de6517..b06d56a2 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_cpp.cs @@ -14,7 +14,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class BitInput { - public BitInput(bool AllocBuffer) { ExternalBuffer = false; @@ -37,7 +36,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } - //BitInput::~BitInput() //{ // if (!ExternalBuffer) @@ -45,15 +43,13 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 //} // - public - void faddbits(uint Bits) + public void faddbits(uint Bits) { // Function wrapped version of inline addbits to save code size. addbits(Bits); } - public - uint fgetbits() + public uint fgetbits() { // Function wrapped version of inline getbits to save code size. return getbits(); @@ -66,6 +62,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 InBuf = Buf; ExternalBuffer = true; } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs index 14867ed8..3acb8f28 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/BitInput.getbits_hpp.cs @@ -1,12 +1,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { - internal partial class BitInput { public const int MAX_SIZE = 0x8000; // Size of input buffer. public int InAddr; // Curent byte position in the buffer. - public int InBit; // Current bit position in the current byte. + public int InBit; // Current bit position in the current byte. public bool ExternalBuffer; @@ -15,8 +14,7 @@ public byte[] InBuf; // Dynamically allocated input buffer. - public - void InitBitInput() + public void InitBitInput() { InAddr = InBit = 0; } @@ -66,5 +64,4 @@ //void SetExternalBuffer(byte *Buf); } - } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs index 66f8d06b..7b2a378d 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/FragmentedWindow.unpack50frag_cpp.cs @@ -17,14 +17,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal partial class FragmentedWindow { - public FragmentedWindow() { //memset(Mem,0,sizeof(Mem)); //memset(MemSize,0,sizeof(MemSize)); } - //FragmentedWindow::~FragmentedWindow() //{ // Reset(); @@ -42,7 +40,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } - public void Init(size_t WinSize) { Reset(); @@ -87,13 +84,12 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 BlockNum++; } if (TotalSize < WinSize) // Not found enough free blocks. - //throw std::bad_alloc(); + //throw std::bad_alloc(); { throw new InvalidOperationException(); } } - public byte this[size_t Item] { get @@ -139,18 +135,24 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 if (Item < MemSize[0]) { //return Mem[0][Item]; - buf = Mem[0]; offset = Item; return; + buf = Mem[0]; + offset = Item; + return; } for (uint I = 1; I < MemSize.Length; I++) { if (Item < MemSize[I]) { //return Mem[I][Item-MemSize[I-1]]; - buf = Mem[I]; offset = Item - MemSize[I - 1]; return; + buf = Mem[I]; + offset = Item - MemSize[I - 1]; + return; } } //return Mem[0][0]; // Must never happen; - buf = Mem[0]; offset = 0; return; // Must never happen; + buf = Mem[0]; + offset = 0; + return; // Must never happen; } public void CopyString(uint Length, uint Distance, ref size_t UnpPtr, size_t MaxWinMask) @@ -165,7 +167,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } - public void CopyData(byte[] Dest, size_t destOffset, size_t WinPos, size_t Size) { for (size_t I = 0; I < Size; I++) @@ -174,7 +175,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } - public size_t GetBlockSize(size_t StartPos, size_t RequiredSize) { for (uint I = 0; I < MemSize.Length; I++) @@ -187,6 +187,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 return 0; // Must never be here. } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/PackDef.compress_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/PackDef.compress_hpp.cs index 34021193..9863446d 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/PackDef.compress_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/PackDef.compress_hpp.cs @@ -2,7 +2,6 @@ { internal static class PackDef { - // Combine pack and unpack constants to class to avoid polluting global // namespace with numerous short names. public const uint MAX_LZ_MATCH = 0x1001; @@ -51,6 +50,5 @@ public const int FILTER_PPM = 7; public const int FILTER_NONE = 8; //} - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs index 7953fb89..f840edf7 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.cs @@ -43,7 +43,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 public void DoUnpack(FileHeader fileHeader, Stream readStream, Stream writeStream) { // as of 12/2017 .NET limits array indexing to using a signed integer - // MaxWinSize causes unpack to use a fragmented window when the file + // MaxWinSize causes unpack to use a fragmented window when the file // window size exceeds MaxWinSize // uggh, that's not how this variable is used, it's the size of the currently allocated window buffer //x MaxWinSize = ((uint)int.MaxValue) + 1; @@ -90,7 +90,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 public bool Suspended { get; set; } - public long DestSize { get => DestUnpSize; } + public long DestSize + { + get => DestUnpSize; + } public int Char { @@ -105,12 +108,15 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } - public int PpmEscChar { get => PPMEscChar; set => PPMEscChar = value; } + public int PpmEscChar + { + get => PPMEscChar; + set => PPMEscChar = value; + } public static byte[] EnsureCapacity(byte[] array, int length) { return array.Length < length ? new byte[length] : array; } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs index 818d4295..69281b36 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.rawint_hpp.cs @@ -27,7 +27,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 private uint32 RawGet4(byte[] D, int offset) { - return (uint)(D[offset] + (D[offset + 1] << 8) + (D[offset + 2] << 16) + (D[offset + 3] << 24)); + return (uint)( + D[offset] + (D[offset + 1] << 8) + (D[offset + 2] << 16) + (D[offset + 3] << 24) + ); } //inline uint64 RawGet8(const void *Data) @@ -117,6 +119,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // return (rotl32(i,24)&0xFF00FF00)|(rotl32(i,8)&0x00FF00FF); //#endif //} - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs index d3f2bd3a..b661725d 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack15_cpp.cs @@ -7,43 +7,102 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { private const int STARTL1 = 2; - private static readonly uint[] DecL1 ={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00, - 0xee00,0xf000,0xf200,0xf200,0xffff}; + private static readonly uint[] DecL1 = + { + 0x8000, + 0xa000, + 0xc000, + 0xd000, + 0xe000, + 0xea00, + 0xee00, + 0xf000, + 0xf200, + 0xf200, + 0xffff + }; private static readonly uint[] PosL1 = { 0, 0, 0, 2, 3, 5, 7, 11, 16, 20, 24, 32, 32 }; private const int STARTL2 = 3; - private static readonly uint[] DecL2 ={0xa000,0xc000,0xd000,0xe000,0xea00,0xee00, - 0xf000,0xf200,0xf240,0xffff}; + private static readonly uint[] DecL2 = + { + 0xa000, + 0xc000, + 0xd000, + 0xe000, + 0xea00, + 0xee00, + 0xf000, + 0xf200, + 0xf240, + 0xffff + }; private static readonly uint[] PosL2 = { 0, 0, 0, 0, 5, 7, 9, 13, 18, 22, 26, 34, 36 }; private const int STARTHF0 = 4; - private static readonly uint[] DecHf0 ={0x8000,0xc000,0xe000,0xf200,0xf200,0xf200, - 0xf200,0xf200,0xffff}; + private static readonly uint[] DecHf0 = + { + 0x8000, + 0xc000, + 0xe000, + 0xf200, + 0xf200, + 0xf200, + 0xf200, + 0xf200, + 0xffff + }; private static readonly uint[] PosHf0 = { 0, 0, 0, 0, 0, 8, 16, 24, 33, 33, 33, 33, 33 }; private const int STARTHF1 = 5; - private static readonly uint[] DecHf1 ={0x2000,0xc000,0xe000,0xf000,0xf200,0xf200, - 0xf7e0,0xffff}; + private static readonly uint[] DecHf1 = + { + 0x2000, + 0xc000, + 0xe000, + 0xf000, + 0xf200, + 0xf200, + 0xf7e0, + 0xffff + }; private static readonly uint[] PosHf1 = { 0, 0, 0, 0, 0, 0, 4, 44, 60, 76, 80, 80, 127 }; private const int STARTHF2 = 5; - private static readonly uint[] DecHf2 ={0x1000,0x2400,0x8000,0xc000,0xfa00,0xffff, - 0xffff,0xffff}; + private static readonly uint[] DecHf2 = + { + 0x1000, + 0x2400, + 0x8000, + 0xc000, + 0xfa00, + 0xffff, + 0xffff, + 0xffff + }; private static readonly uint[] PosHf2 = { 0, 0, 0, 0, 0, 0, 2, 7, 53, 117, 233, 0, 0 }; private const int STARTHF3 = 6; - private static readonly uint[] DecHf3 ={0x800,0x2400,0xee00,0xfe80,0xffff,0xffff, - 0xffff}; + private static readonly uint[] DecHf3 = + { + 0x800, + 0x2400, + 0xee00, + 0xfe80, + 0xffff, + 0xffff, + 0xffff + }; private static readonly uint[] PosHf3 = { 0, 0, 0, 0, 0, 0, 0, 2, 16, 218, 251, 0, 0 }; @@ -141,25 +200,100 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 UnpWriteBuf20(); } - //#define GetShortLen1(pos) ((pos)==1 ? Buf60+3:ShortLen1[pos]) - private uint GetShortLen1(uint pos) { return ((pos) == 1 ? (uint)(Buf60 + 3) : ShortLen1[pos]); } + private uint GetShortLen1(uint pos) + { + return ((pos) == 1 ? (uint)(Buf60 + 3) : ShortLen1[pos]); + } + //#define GetShortLen2(pos) ((pos)==3 ? Buf60+3:ShortLen2[pos]) - private uint GetShortLen2(uint pos) { return ((pos) == 3 ? (uint)(Buf60 + 3) : ShortLen2[pos]); } + private uint GetShortLen2(uint pos) + { + return ((pos) == 3 ? (uint)(Buf60 + 3) : ShortLen2[pos]); + } internal static class Unpack15Local { - public static readonly uint[] ShortLen1 = { 1, 3, 4, 4, 5, 6, 7, 8, 8, 4, 4, 5, 6, 6, 4, 0 }; - public static readonly uint[] ShortXor1 ={0,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xfe, - 0xff,0xc0,0x80,0x90,0x98,0x9c,0xb0}; - public static readonly uint[] ShortLen2 = { 2, 3, 3, 3, 4, 4, 5, 6, 6, 4, 4, 5, 6, 6, 4, 0 }; - public static readonly uint[] ShortXor2 ={0,0x40,0x60,0xa0,0xd0,0xe0,0xf0,0xf8, - 0xfc,0xc0,0x80,0x90,0x98,0x9c,0xb0}; + public static readonly uint[] ShortLen1 = + { + 1, + 3, + 4, + 4, + 5, + 6, + 7, + 8, + 8, + 4, + 4, + 5, + 6, + 6, + 4, + 0 + }; + public static readonly uint[] ShortXor1 = + { + 0, + 0xa0, + 0xd0, + 0xe0, + 0xf0, + 0xf8, + 0xfc, + 0xfe, + 0xff, + 0xc0, + 0x80, + 0x90, + 0x98, + 0x9c, + 0xb0 + }; + public static readonly uint[] ShortLen2 = + { + 2, + 3, + 3, + 3, + 4, + 4, + 5, + 6, + 6, + 4, + 4, + 5, + 6, + 6, + 4, + 0 + }; + public static readonly uint[] ShortXor2 = + { + 0, + 0x40, + 0x60, + 0xa0, + 0xd0, + 0xe0, + 0xf0, + 0xf8, + 0xfc, + 0xc0, + 0x80, + 0x90, + 0x98, + 0x9c, + 0xb0 + }; } private void ShortLZ() { - uint Length, SaveLength; + uint Length, + SaveLength; uint LastDistance; uint Distance; int DistancePlace; @@ -187,7 +321,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { for (Length = 0; ; Length++) { - if (((BitField ^ ShortXor1[Length]) & (~(0xff >> (int)GetShortLen1(Length)))) == 0) + if ( + ((BitField ^ ShortXor1[Length]) & (~(0xff >> (int)GetShortLen1(Length)))) + == 0 + ) { break; } @@ -199,7 +336,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { for (Length = 0; ; Length++) { - if (((BitField ^ ShortXor2[Length]) & (~(0xff >> (int)GetShortLen2(Length)))) == 0) + if ( + ((BitField ^ ShortXor2[Length]) & (~(0xff >> (int)GetShortLen2(Length)))) + == 0 + ) { break; } @@ -279,8 +419,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { uint Length; uint Distance; - uint DistancePlace, NewDistancePlace; - uint OldAvr2, OldAvr3; + uint DistancePlace, + NewDistancePlace; + uint OldAvr2, + OldAvr3; NumHuf = 0; Nlzb += 16; @@ -296,13 +438,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { Length = DecodeNum(BitField, STARTL2, DecL2, PosL2); } - else - if (AvrLn2 >= 64) + else if (AvrLn2 >= 64) { Length = DecodeNum(BitField, STARTL1, DecL1, PosL1); } - else - if (BitField < 0x100) + else if (BitField < 0x100) { Length = BitField; Inp.faddbits(16); @@ -325,8 +465,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { DistancePlace = DecodeNum(BitField, STARTHF2, DecHf2, PosHf2); } - else - if (AvrPlcB > 0x6ff) + else if (AvrPlcB > 0x6ff) { DistancePlace = DecodeNum(BitField, STARTHF1, DecHf1, PosHf1); } @@ -365,8 +504,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 AvrLn3++; AvrLn3 -= AvrLn3 >> 8; } - else - if (AvrLn3 > 0) + else if (AvrLn3 > 0) { AvrLn3--; } @@ -401,7 +539,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 private void HuffDecode() { - uint CurByte, NewBytePlace; + uint CurByte, + NewBytePlace; uint Length; uint Distance; int BytePlace; @@ -412,18 +551,15 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { BytePlace = (int)DecodeNum(BitField, STARTHF4, DecHf4, PosHf4); } - else - if (AvrPlc > 0x5dff) + else if (AvrPlc > 0x5dff) { BytePlace = (int)DecodeNum(BitField, STARTHF3, DecHf3, PosHf3); } - else - if (AvrPlc > 0x35ff) + else if (AvrPlc > 0x35ff) { BytePlace = (int)DecodeNum(BitField, STARTHF2, DecHf2, PosHf2); } - else - if (AvrPlc > 0x0dff) + else if (AvrPlc > 0x0dff) { BytePlace = (int)DecodeNum(BitField, STARTHF1, DecHf1, PosHf1); } @@ -461,8 +597,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } } - else - if (NumHuf++ >= 16 && FlagsCnt == 0) + else if (NumHuf++ >= 16 && FlagsCnt == 0) { StMode = 1; } @@ -499,7 +634,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 private void GetFlagsBuf() { - uint Flags, NewFlagsPlace; + uint Flags, + NewFlagsPlace; uint FlagsPlace = DecodeNum(Inp.fgetbits(), STARTHF2, DecHf2, PosHf2); // Our Huffman table stores 257 items and needs all them in other parts @@ -562,7 +698,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 private void CorrHuff(ushort[] CharSet, byte[] NumToPlace) { - int I, J; + int I, + J; for (I = 7; I >= 0; I--) for (J = 0; J < 32; J++) { @@ -595,8 +732,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } Inp.faddbits(StartPos); - return (((Num - (I != 0 ? DecTab[I - 1] : 0)) >> (int)(16 - StartPos)) + PosTab[StartPos]); + return ( + ((Num - (I != 0 ? DecTab[I - 1] : 0)) >> (int)(16 - StartPos)) + PosTab[StartPos] + ); } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs index 7f59f6dd..52133cf9 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack20_cpp.cs @@ -25,13 +25,172 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 CopyString(Length, Distance); } - internal static class Unpack20Local { - public static readonly byte[] LDecode = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224 }; - public static readonly byte[] LBits = { 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 }; - public static readonly uint[] DDecode = { 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576, 32768U, 49152U, 65536, 98304, 131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824, 655360, 720896, 786432, 851968, 917504, 983040 }; - public static readonly byte[] DBits = { 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, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }; + public static readonly byte[] LDecode = + { + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 10, + 12, + 14, + 16, + 20, + 24, + 28, + 32, + 40, + 48, + 56, + 64, + 80, + 96, + 112, + 128, + 160, + 192, + 224 + }; + public static readonly byte[] LBits = + { + 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 + }; + public static readonly uint[] DDecode = + { + 0, + 1, + 2, + 3, + 4, + 6, + 8, + 12, + 16, + 24, + 32, + 48, + 64, + 96, + 128, + 192, + 256, + 384, + 512, + 768, + 1024, + 1536, + 2048, + 3072, + 4096, + 6144, + 8192, + 12288, + 16384, + 24576, + 32768U, + 49152U, + 65536, + 98304, + 131072, + 196608, + 262144, + 327680, + 393216, + 458752, + 524288, + 589824, + 655360, + 720896, + 786432, + 851968, + 917504, + 983040 + }; + public static readonly byte[] DBits = + { + 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, + 14, + 14, + 15, + 15, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16 + }; public static readonly byte[] SDDecode = { 0, 4, 8, 16, 32, 64, 128, 192 }; public static readonly byte[] SDBits = { 2, 2, 3, 4, 5, 6, 6, 6 }; } @@ -260,7 +419,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 Inp.addbits(4); } MakeDecodeTables(BitLength, 0, BlockTables.BD, BC20); - for (uint I = 0; I < TableSize;) + for (uint I = 0; I < TableSize; ) { if (Inp.InAddr > ReadTop - 5) { @@ -276,8 +435,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 Table[I] = (byte)((Number + UnpOldTable20[I]) & 0xf); I++; } - else - if (Number == 16) + else if (Number == 16) { uint N = (Inp.getbits() >> 14) + 3; Inp.addbits(2); @@ -348,8 +506,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 ReadTables20(); } } - else - if (DecodeNumber(Inp, BlockTables.LD) == 269) + else if (DecodeNumber(Inp, BlockTables.LD) == 269) { ReadTables20(); } @@ -382,7 +539,13 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 V.D3 = V.D2; V.D2 = V.LastDelta - V.D1; V.D1 = V.LastDelta; - int PCh = 8 * V.LastChar + V.K1 * V.D1 + V.K2 * V.D2 + V.K3 * V.D3 + V.K4 * V.D4 + V.K5 * UnpChannelDelta; + int PCh = + 8 * V.LastChar + + V.K1 * V.D1 + + V.K2 * V.D2 + + V.K3 * V.D3 + + V.K4 * V.D4 + + V.K5 * UnpChannelDelta; PCh = (PCh >> 3) & 0xFF; uint Ch = (uint)(PCh - Delta); @@ -409,7 +572,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 if ((V.ByteCount & 0x1F) == 0) { - uint MinDif = V.Dif[0], NumMinDif = 0; + uint MinDif = V.Dif[0], + NumMinDif = 0; V.Dif[0] = 0; for (uint I = 1; I < V.Dif.Length; I++) { @@ -496,6 +660,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } return (byte)Ch; } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs index 1647b902..8491f7af 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack30_cpp.cs @@ -307,7 +307,7 @@ bool ReadEndOfBlock() bool ReadVMCode() { - // Entire VM code is guaranteed to fully present in block defined + // Entire VM code is guaranteed to fully present in block defined // by current Huffman table. Compressor checks that VM code does not cross // Huffman block boundaries. uint FirstByte=Inp.getbits()>>8; @@ -418,7 +418,7 @@ bool AddVMCode(uint FirstByte,byte[] Code,int CodeSize) Filters30[Filters30.Count-1]=Filter=new UnpackFilter30(); StackFilter.ParentFilter=(uint)(Filters30.Count-1); - // Reserve one item to store the data block length of our new filter + // Reserve one item to store the data block length of our new filter // entry. We'll set it to real block length below, after reading it. // But we need to initialize it now, because when processing corrupt // data, we can access this item even before we set it to real value. @@ -466,7 +466,7 @@ bool AddVMCode(uint FirstByte,byte[] Code,int CodeSize) else { // Set the data block size to same value as the previous block size - // for same filter. It is possible for corrupt data to access a new + // for same filter. It is possible for corrupt data to access a new // and not filled yet item of OldFilterLengths array here. This is why // we set new OldFilterLengths items to zero above. StackFilter.BlockLength=FiltPos BlockHeader.BlockStart + BlockHeader.BlockSize - 1 || - Inp.InAddr == BlockHeader.BlockStart + BlockHeader.BlockSize - 1 && - Inp.InBit >= BlockHeader.BlockBitSize) + while ( + Inp.InAddr > BlockHeader.BlockStart + BlockHeader.BlockSize - 1 + || Inp.InAddr == BlockHeader.BlockStart + BlockHeader.BlockSize - 1 + && Inp.InBit >= BlockHeader.BlockBitSize + ) { if (BlockHeader.LastBlockInFile) { FileDone = true; break; } - if (!ReadBlockHeader(Inp, ref BlockHeader) || !ReadTables(Inp, ref BlockHeader, ref BlockTables)) + if ( + !ReadBlockHeader(Inp, ref BlockHeader) + || !ReadTables(Inp, ref BlockHeader, ref BlockTables) + ) { return; } @@ -71,7 +79,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } - if (((WriteBorder - UnpPtr) & MaxWinMask) < MAX_LZ_MATCH + 3 && WriteBorder != UnpPtr) + if ( + ((WriteBorder - UnpPtr) & MaxWinMask) < MAX_LZ_MATCH + 3 + && WriteBorder != UnpPtr + ) { UnpWriteBuf(); if (WrittenFileSize > DestUnpSize) @@ -104,7 +115,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { uint Length = SlotToLength(Inp, MainSlot - 262); - uint DBits, Distance = 1, DistSlot = DecodeNumber(Inp, BlockTables.DD); + uint DBits, + Distance = 1, + DistSlot = DecodeNumber(Inp, BlockTables.DD); if (DistSlot < 4) { DBits = 0; @@ -273,7 +286,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // If distance to filter start is that large that due to circular dictionary // mode now it points to old not written yet data, then we set 'NextWindow' // flag and process this filter only after processing that older data. - Filter.NextWindow = WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; + Filter.NextWindow = + WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) <= Filter.BlockStart; Filter.BlockStart = (uint)((Filter.BlockStart + UnpPtr) & MaxWinMask); Filters.Add(Filter); @@ -328,7 +342,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { // We may need to quit from main extraction loop and read new block header // and trees earlier than data in input buffer ends. - ReadBorder = Math.Min(ReadBorder, BlockHeader.BlockStart + BlockHeader.BlockSize - 1); + ReadBorder = Math.Min( + ReadBorder, + BlockHeader.BlockStart + BlockHeader.BlockSize - 1 + ); } return ReadCode != -1; } @@ -393,7 +410,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 uint BlockEnd = (BlockStart + BlockLength) & MaxWinMask; //x FilterSrcMemory.Alloc(BlockLength); - FilterSrcMemory = EnsureCapacity(FilterSrcMemory, checked((int)BlockLength)); + FilterSrcMemory = EnsureCapacity( + FilterSrcMemory, + checked((int)BlockLength) + ); byte[] Mem = FilterSrcMemory; if (BlockStart < BlockEnd || BlockEnd == 0) { @@ -502,8 +522,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // Choose the nearest among WriteBorder and WrPtr actual written border. // If border is equal to UnpPtr, it means that we have MaxWinSize data ahead. - if (WriteBorder == UnpPtr || - WrPtr != UnpPtr && ((WrPtr - UnpPtr) & MaxWinMask) < ((WriteBorder - UnpPtr) & MaxWinMask)) + if ( + WriteBorder == UnpPtr + || WrPtr != UnpPtr + && ((WrPtr - UnpPtr) & MaxWinMask) < ((WriteBorder - UnpPtr) & MaxWinMask) + ) { WriteBorder = WrPtr; } @@ -517,6 +540,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { case FILTER_E8: case FILTER_E8E9: + { uint FileOffset = (uint)WrittenFileSize; @@ -524,7 +548,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 byte CmpByte2 = Flt.Type == FILTER_E8E9 ? (byte)0xe9 : (byte)0xe8; // DataSize is unsigned, so we use "CurPos+4" and not "DataSize-4" // to avoid overflow for DataSize<4. - for (uint CurPos = 0; CurPos + 4 < DataSize;) + for (uint CurPos = 0; CurPos + 4 < DataSize; ) { //x byte CurByte=*(Data++); byte CurByte = __d[Data++]; @@ -536,15 +560,14 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // We check 0x80000000 bit instead of '< 0' comparison // not assuming int32 presence or uint size and endianness. - if ((Addr & 0x80000000) != 0) // Addr<0 + if ((Addr & 0x80000000) != 0) // Addr<0 { - if (((Addr + Offset) & 0x80000000) == 0) // Addr+Offset>=0 + if (((Addr + Offset) & 0x80000000) == 0) // Addr+Offset>=0 { RawPut4(Addr + FileSize, __d, Data); } } - else - if (((Addr - FileSize) & 0x80000000) != 0) // Addr> 8); @@ -575,29 +602,29 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } return SrcData; case FILTER_DELTA: + { + // Unlike RAR3, we do not need to reject excessive channel + // values here, since RAR5 uses only 5 bits to store channel. + uint Channels = Flt.Channels, + SrcPos = 0; + + //x FilterDstMemory.Alloc(DataSize); + FilterDstMemory = EnsureCapacity(FilterDstMemory, checked((int)DataSize)); + + byte[] DstData = FilterDstMemory; + + // Bytes from same channels are grouped to continual data blocks, + // so we need to place them back to their interleaving positions. + for (uint CurChannel = 0; CurChannel < Channels; CurChannel++) { - // Unlike RAR3, we do not need to reject excessive channel - // values here, since RAR5 uses only 5 bits to store channel. - uint Channels = Flt.Channels, SrcPos = 0; - - //x FilterDstMemory.Alloc(DataSize); - FilterDstMemory = EnsureCapacity(FilterDstMemory, checked((int)DataSize)); - - byte[] DstData = FilterDstMemory; - - // Bytes from same channels are grouped to continual data blocks, - // so we need to place them back to their interleaving positions. - for (uint CurChannel = 0; CurChannel < Channels; CurChannel++) + byte PrevByte = 0; + for (uint DestPos = CurChannel; DestPos < DataSize; DestPos += Channels) { - byte PrevByte = 0; - for (uint DestPos = CurChannel; DestPos < DataSize; DestPos += Channels) - { - DstData[DestPos] = (PrevByte -= __d[Data + SrcPos++]); - } + DstData[DestPos] = (PrevByte -= __d[Data + SrcPos++]); } - return DstData; } - + return DstData; + } } return null; } @@ -627,8 +654,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 StartPtr = (StartPtr + BlockSize) & MaxWinMask; } } - else - if (EndPtr < StartPtr) + else if (EndPtr < StartPtr) { UnpWriteData(Window, StartPtr, MaxWinSize - StartPtr); UnpWriteData(Window, 0, EndPtr); @@ -703,7 +729,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } Header.BlockSize = BlockSize; - byte CheckSum = (byte)(0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16)); + byte CheckSum = (byte)( + 0x5a ^ BlockFlags ^ BlockSize ^ (BlockSize >> 8) ^ (BlockSize >> 16) + ); if (CheckSum != SavedCheckSum) { return false; @@ -717,7 +745,11 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 return true; } - private bool ReadTables(BitInput Inp, ref UnpackBlockHeader Header, ref UnpackBlockTables Tables) + private bool ReadTables( + BitInput Inp, + ref UnpackBlockHeader Header, + ref UnpackBlockTables Tables + ) { if (!Header.TablePresent) { @@ -766,7 +798,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 byte[] Table = new byte[HUFF_TABLE_SIZE]; const uint TableSize = HUFF_TABLE_SIZE; - for (uint I = 0; I < TableSize;) + for (uint I = 0; I < TableSize; ) { if (!Inp.ExternalBuffer && Inp.InAddr > ReadTop - 5) { @@ -782,8 +814,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 Table[I] = (byte)Number; I++; } - else - if (Number < 18) + else if (Number < 18) { uint N; if (Number == 16) @@ -851,6 +882,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 //Filters.SoftReset(); Filters.Clear(); } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs index 48df0608..17eecba5 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpack_cpp.cs @@ -19,10 +19,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { internal sealed partial class Unpack : BitInput { - - public Unpack(/* ComprDataIO *DataIO */) - //:Inp(true),VMCodeInp(true) - : base(true) + public Unpack( /* ComprDataIO *DataIO */ + ) + //:Inp(true),VMCodeInp(true) + : base(true) { _UnpackCtor(); @@ -33,10 +33,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 UnpAllBuf = false; UnpSomeRead = false; #if RarV2017_RAR_SMP - MaxUserThreads=1; - UnpThreadPool=CreateThreadPool(); - ReadBufMT=null; - UnpThreadData=null; + MaxUserThreads = 1; + UnpThreadPool = CreateThreadPool(); + ReadBufMT = null; + UnpThreadData = null; #endif MaxWinSize = 0; MaxWinMask = 0; @@ -73,7 +73,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 if (WinSize == 0) //ErrHandler.MemoryError(); { - throw new InvalidFormatException("invalid window size (possibly due to a rar file with a 4GB being unpacked on a 32-bit platform)"); + throw new InvalidFormatException( + "invalid window size (possibly due to a rar file with a 4GB being unpacked on a 32-bit platform)" + ); } // Minimum window size must be at least twice more than maximum possible @@ -150,7 +152,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 { for (size_t I = 1; I <= MaxWinSize; I++) { - NewWindow[(UnpPtr - I) & (WinSize - 1)] = Window[(UnpPtr - I) & (MaxWinSize - 1)]; + NewWindow[(UnpPtr - I) & (WinSize - 1)] = Window[ + (UnpPtr - I) & (MaxWinSize - 1) + ]; } } @@ -198,24 +202,25 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 #endif case 50: // RAR 5.0 compression algorithm. #if RarV2017_RAR_SMP - if (MaxUserThreads>1) - { -// We do not use the multithreaded unpack routine to repack RAR archives -// in 'suspended' mode, because unlike the single threaded code it can -// write more than one dictionary for same loop pass. So we would need -// larger buffers of unknown size. Also we do not support multithreading -// in fragmented window mode. - if (!Fragmented) - { - Unpack5MT(Solid); - break; - } - } + if (MaxUserThreads > 1) + { + // We do not use the multithreaded unpack routine to repack RAR archives + // in 'suspended' mode, because unlike the single threaded code it can + // write more than one dictionary for same loop pass. So we would need + // larger buffers of unknown size. Also we do not support multithreading + // in fragmented window mode. + if (!Fragmented) + { + Unpack5MT(Solid); + break; + } + } #endif Unpack5(Solid); break; #if !Rar2017_NOSTRICT - default: throw new InvalidFormatException("unknown compression method " + Method); + default: + throw new InvalidFormatException("unknown compression method " + Method); #endif } } @@ -246,7 +251,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 //memset(&BlockHeader,0,sizeof(BlockHeader)); BlockHeader = new UnpackBlockHeader(); - BlockHeader.BlockSize = -1; // '-1' means not defined yet. + BlockHeader.BlockSize = -1; // '-1' means not defined yet. #if !RarV2017_SFX_MODULE UnpInitData20(Solid); #endif @@ -254,7 +259,6 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 UnpInitData50(Solid); } - // LengthTable contains the length in bits for every element of alphabet. // Dec is the structure to decode Huffman code/ // Size is size of length table and DecodeNum field in Dec structure, @@ -370,7 +374,9 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // Find the upper limit for current bit field and adjust the bit length // accordingly if necessary. - while (CurBitLength < Dec.DecodeLen.Length && BitField >= Dec.DecodeLen[CurBitLength]) + while ( + CurBitLength < Dec.DecodeLen.Length && BitField >= Dec.DecodeLen[CurBitLength] + ) { CurBitLength++; } @@ -391,8 +397,10 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // of first position for current bit length and right aligned distance // between our bit field and start code for current bit length. uint Pos; - if (CurBitLength < Dec.DecodePos.Length && - (Pos = Dec.DecodePos[CurBitLength] + Dist) < Size) + if ( + CurBitLength < Dec.DecodePos.Length + && (Pos = Dec.DecodePos[CurBitLength] + Dist) < Size + ) { // Define the code to alphabet number translation. Dec.QuickNum[Code] = Dec.DecodeNum[Pos]; @@ -404,6 +412,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } } } - } } diff --git a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs index 228be40b..8c585af2 100644 --- a/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs +++ b/src/SharpCompress/Compressors/Rar/UnpackV2017/Unpack.unpackinline_cpp.cs @@ -76,7 +76,7 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 // // // This memcpy expanded inline by MSVC. We could also use uint64 // // assignment, which seems to provide about the same speed. - // memcpy(Dest,Src,8); + // memcpy(Dest,Src,8); // // Src+=8; // Dest+=8; @@ -155,7 +155,8 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 private uint SlotToLength(BitInput Inp, uint Slot) { - uint LBits, Length = 2; + uint LBits, + Length = 2; if (Slot < 8) { LBits = 0; @@ -174,6 +175,5 @@ namespace SharpCompress.Compressors.Rar.UnpackV2017 } return Length; } - } } diff --git a/src/SharpCompress/Compressors/Rar/VM/BitInput.cs b/src/SharpCompress/Compressors/Rar/VM/BitInput.cs index c0656086..b90d40d8 100644 --- a/src/SharpCompress/Compressors/Rar/VM/BitInput.cs +++ b/src/SharpCompress/Compressors/Rar/VM/BitInput.cs @@ -9,11 +9,18 @@ namespace SharpCompress.Compressors.Rar.VM public int inBit; // TODO: rename var - public int InAddr { get { return inAddr; } set { inAddr = value; } } - public int InBit { get { return inBit; } set { inBit = value; } } + public int InAddr + { + get { return inAddr; } + set { inAddr = value; } + } + public int InBit + { + get { return inBit; } + set { inBit = value; } + } public bool ExternalBuffer; - /// internal BitInput() { @@ -57,11 +64,11 @@ namespace SharpCompress.Compressors.Rar.VM return (uint)GetBits(); } - /// + /// /// (also named fgetbits) /// /// - /// the bits (unsigned short) + /// the bits (unsigned short) /// internal int GetBits() { @@ -71,9 +78,18 @@ namespace SharpCompress.Compressors.Rar.VM // BitField|=(int)(inBuf[inAddr+2])&0xFF; // BitField >>>= (8-inBit); // return (BitField & 0xffff); - return ((Utility.URShift((((InBuf[inAddr] & 0xff) << 16) - + ((InBuf[inAddr + 1] & 0xff) << 8) - + ((InBuf[inAddr + 2] & 0xff))), (8 - inBit))) & 0xffff); + return ( + ( + Utility.URShift( + ( + ((InBuf[inAddr] & 0xff) << 16) + + ((InBuf[inAddr + 1] & 0xff) << 8) + + ((InBuf[inAddr + 2] & 0xff)) + ), + (8 - inBit) + ) + ) & 0xffff + ); } /// Indicates an Overfow @@ -86,4 +102,4 @@ namespace SharpCompress.Compressors.Rar.VM return (inAddr + IncPtr >= MAX_SIZE); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/RarVM.cs b/src/SharpCompress/Compressors/Rar/VM/RarVM.cs index d7180efb..3ab8e2ca 100644 --- a/src/SharpCompress/Compressors/Rar/VM/RarVM.cs +++ b/src/SharpCompress/Compressors/Rar/VM/RarVM.cs @@ -132,7 +132,6 @@ namespace SharpCompress.Compressors.Rar.VM public void execute(VMPreparedProgram prg) { for (int i = 0; i < prg.InitR.Length; i++) - // memcpy(R,Prg->InitR,sizeof(Prg->InitR)); { R[i] = prg.InitR[i]; @@ -142,17 +141,16 @@ namespace SharpCompress.Compressors.Rar.VM if (globalSize != 0) { for (int i = 0; i < globalSize; i++) - // memcpy(Mem+VM_GLOBALMEMADDR,&Prg->GlobalData[0],GlobalSize); { Mem[VM_GLOBALMEMADDR + i] = prg.GlobalData[i]; } } - long staticSize = Math.Min(prg.StaticData.Count, VM_GLOBALMEMSIZE - globalSize) & 0xffFFffFF; + long staticSize = + Math.Min(prg.StaticData.Count, VM_GLOBALMEMSIZE - globalSize) & 0xffFFffFF; if (staticSize != 0) { for (int i = 0; i < staticSize; i++) - // memcpy(Mem+VM_GLOBALMEMADDR+GlobalSize,&Prg->StaticData[0],StaticSize); { Mem[VM_GLOBALMEMADDR + (int)globalSize + i] = prg.StaticData[i]; @@ -162,10 +160,8 @@ namespace SharpCompress.Compressors.Rar.VM flags = 0; //UPGRADE_NOTE: There is an untranslated Statement. Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'" - List preparedCode = prg.AltCommands.Count != 0 - ? prg - .AltCommands - : prg.Commands; + List preparedCode = + prg.AltCommands.Count != 0 ? prg.AltCommands : prg.Commands; if (!ExecuteCode(preparedCode, prg.CommandCount)) { @@ -184,14 +180,16 @@ namespace SharpCompress.Compressors.Rar.VM prg.GlobalData.Clear(); - int dataSize = Math.Min(GetValue(false, Mem, VM_GLOBALMEMADDR + 0x30), VM_GLOBALMEMSIZE - VM_FIXEDGLOBALSIZE); + int dataSize = Math.Min( + GetValue(false, Mem, VM_GLOBALMEMADDR + 0x30), + VM_GLOBALMEMSIZE - VM_FIXEDGLOBALSIZE + ); if (dataSize != 0) { //prg.GlobalData.Clear(); // ->GlobalData.Add(dataSize+VM_FIXEDGLOBALSIZE); prg.GlobalData.Capacity = dataSize + VM_FIXEDGLOBALSIZE; for (int i = 0; i < dataSize + VM_FIXEDGLOBALSIZE; i++) - // memcpy(&Prg->GlobalData[0],&Mem[VM_GLOBALMEMADDR],DataSize+VM_FIXEDGLOBALSIZE); { prg.GlobalData.Add(Mem[VM_GLOBALMEMADDR + i]); @@ -215,8 +213,7 @@ namespace SharpCompress.Compressors.Rar.VM return true; } - private bool ExecuteCode(List preparedCode, - int cmdCount) + private bool ExecuteCode(List preparedCode, int cmdCount) { maxOpCount = 25000000; codeSize = cmdCount; @@ -244,6 +241,7 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_CMP: + { VMFlags value1 = (VMFlags)GetValue(cmd.IsByteMode, Mem, op1); VMFlags result = value1 - GetValue(cmd.IsByteMode, Mem, op2); @@ -254,12 +252,15 @@ namespace SharpCompress.Compressors.Rar.VM } else { - flags = (VMFlags)((result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS)); + flags = (VMFlags)( + (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) + ); } } break; case VMCommands.VM_CMPB: + { VMFlags value1 = (VMFlags)GetValue(true, Mem, op1); VMFlags result = value1 - GetValue(true, Mem, op2); @@ -269,12 +270,15 @@ namespace SharpCompress.Compressors.Rar.VM } else { - flags = (VMFlags)((result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS)); + flags = (VMFlags)( + (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) + ); } } break; case VMCommands.VM_CMPD: + { VMFlags value1 = (VMFlags)GetValue(false, Mem, op1); VMFlags result = value1 - GetValue(false, Mem, op2); @@ -284,87 +288,127 @@ namespace SharpCompress.Compressors.Rar.VM } else { - flags = (VMFlags)((result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS)); + flags = (VMFlags)( + (result > value1) ? 1 : 0 | (int)(result & VMFlags.VM_FS) + ); } } break; case VMCommands.VM_ADD: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); - int result = - (int) - (((value1 + (long)GetValue(cmd.IsByteMode, Mem, op2))) & - unchecked((int)0xffffffff)); + int result = (int)( + ((value1 + (long)GetValue(cmd.IsByteMode, Mem, op2))) + & unchecked((int)0xffffffff) + ); if (cmd.IsByteMode) { result &= 0xff; - flags = - (VMFlags) - ((result < value1) - ? 1 - : 0 | - (result == 0 - ? (int)VMFlags.VM_FZ - : (((result & 0x80) != 0) ? (int)VMFlags.VM_FS : 0))); + flags = (VMFlags)( + (result < value1) + ? 1 + : 0 + | ( + result == 0 + ? (int)VMFlags.VM_FZ + : ( + ((result & 0x80) != 0) + ? (int)VMFlags.VM_FS + : 0 + ) + ) + ); // Flags=(Result value1) ? 1 : 0 | (result & (int)VMFlags.VM_FS))); + int result = (int)( + value1 + & 0xffFFffFF - GetValue(cmd.IsByteMode, Mem, op2) + & unchecked((int)0xFFffFFff) + ); + flags = (VMFlags)( + (result == 0) + ? (int)VMFlags.VM_FZ + : ((result > value1) ? 1 : 0 | (result & (int)VMFlags.VM_FS)) + ); SetValue(cmd.IsByteMode, Mem, op1, result); // (Cmd->ByteMode,Op1,Result); } break; case VMCommands.VM_SUBB: - SetValue(true, Mem, op1, - (int) - (GetValue(true, Mem, op1) & 0xFFffFFff - GetValue(true, Mem, op2) & - unchecked((int)0xFFffFFff))); + SetValue( + true, + Mem, + op1, + (int)( + GetValue(true, Mem, op1) + & 0xFFffFFff - GetValue(true, Mem, op2) + & unchecked((int)0xFFffFFff) + ) + ); break; case VMCommands.VM_SUBD: - SetValue(false, Mem, op1, - (int) - (GetValue(false, Mem, op1) & 0xFFffFFff - GetValue(false, Mem, op2) & - unchecked((int)0xFFffFFff))); + SetValue( + false, + Mem, + op1, + (int)( + GetValue(false, Mem, op1) + & 0xFFffFFff - GetValue(false, Mem, op2) + & unchecked((int)0xFFffFFff) + ) + ); break; case VMCommands.VM_JZ: @@ -384,31 +428,49 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_INC: + { - int result = (int)(GetValue(cmd.IsByteMode, Mem, op1) & 0xFFffFFffL + 1L); + int result = (int)( + GetValue(cmd.IsByteMode, Mem, op1) & 0xFFffFFffL + 1L + ); if (cmd.IsByteMode) { result &= 0xff; } SetValue(cmd.IsByteMode, Mem, op1, result); - flags = (VMFlags)(result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); } break; case VMCommands.VM_INCB: - SetValue(true, Mem, op1, (int)(GetValue(true, Mem, op1) & 0xFFffFFffL + 1L)); + SetValue( + true, + Mem, + op1, + (int)(GetValue(true, Mem, op1) & 0xFFffFFffL + 1L) + ); break; case VMCommands.VM_INCD: - SetValue(false, Mem, op1, (int)(GetValue(false, Mem, op1) & 0xFFffFFffL + 1L)); + SetValue( + false, + Mem, + op1, + (int)(GetValue(false, Mem, op1) & 0xFFffFFffL + 1L) + ); break; case VMCommands.VM_DEC: + { int result = (int)(GetValue(cmd.IsByteMode, Mem, op1) & 0xFFffFFff - 1); SetValue(cmd.IsByteMode, Mem, op1, result); - flags = (VMFlags)(result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); } break; @@ -417,7 +479,12 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_DECD: - SetValue(false, Mem, op1, (int)(GetValue(false, Mem, op1) & 0xFFffFFff - 1)); + SetValue( + false, + Mem, + op1, + (int)(GetValue(false, Mem, op1) & 0xFFffFFff - 1) + ); break; case VMCommands.VM_JMP: @@ -425,33 +492,53 @@ namespace SharpCompress.Compressors.Rar.VM continue; case VMCommands.VM_XOR: + { - int result = GetValue(cmd.IsByteMode, Mem, op1) ^ GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)(result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS); + int result = + GetValue(cmd.IsByteMode, Mem, op1) + ^ GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_AND: + { - int result = GetValue(cmd.IsByteMode, Mem, op1) & GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)(result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS); + int result = + GetValue(cmd.IsByteMode, Mem, op1) + & GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_OR: + { - int result = GetValue(cmd.IsByteMode, Mem, op1) | GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)(result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS); + int result = + GetValue(cmd.IsByteMode, Mem, op1) + | GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_TEST: + { - int result = GetValue(cmd.IsByteMode, Mem, op1) & GetValue(cmd.IsByteMode, Mem, op2); - flags = (VMFlags)(result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS); + int result = + GetValue(cmd.IsByteMode, Mem, op1) + & GetValue(cmd.IsByteMode, Mem, op2); + flags = (VMFlags)( + result == 0 ? (int)VMFlags.VM_FZ : result & (int)VMFlags.VM_FS + ); } break; @@ -524,54 +611,60 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_SHL: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); int value2 = GetValue(cmd.IsByteMode, Mem, op2); int result = value1 << value2; - flags = - (VMFlags) - ((result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) | - (((value1 << (value2 - 1)) & unchecked((int)0x80000000)) != 0 - ? (int)VMFlags.VM_FC - : 0)); + flags = (VMFlags)( + (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) + | ( + ((value1 << (value2 - 1)) & unchecked((int)0x80000000)) != 0 + ? (int)VMFlags.VM_FC + : 0 + ) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_SHR: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); int value2 = GetValue(cmd.IsByteMode, Mem, op2); int result = Utility.URShift(value1, value2); - flags = - (VMFlags) - ((result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) | - ((Utility.URShift(value1, (value2 - 1))) & (int)VMFlags.VM_FC)); + flags = (VMFlags)( + (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) + | ((Utility.URShift(value1, (value2 - 1))) & (int)VMFlags.VM_FC) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_SAR: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); int value2 = GetValue(cmd.IsByteMode, Mem, op2); int result = value1 >> value2; - flags = - (VMFlags) - ((result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) | - ((value1 >> (value2 - 1)) & (int)VMFlags.VM_FC)); + flags = (VMFlags)( + (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS)) + | ((value1 >> (value2 - 1)) & (int)VMFlags.VM_FC) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_NEG: + { int result = -GetValue(cmd.IsByteMode, Mem, op1); - flags = - (VMFlags) - (result == 0 - ? (int)VMFlags.VM_FZ - : (int)VMFlags.VM_FC | (result & (int)VMFlags.VM_FS)); + flags = (VMFlags)( + result == 0 + ? (int)VMFlags.VM_FZ + : (int)VMFlags.VM_FC | (result & (int)VMFlags.VM_FS) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; @@ -585,6 +678,7 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_PUSHA: + { for (int i = 0, SP = R[7] - 4; i < regCount; i++, SP -= 4) { @@ -595,6 +689,7 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_POPA: + { for (int i = 0, SP = R[7]; i < regCount; i++, SP += 4) { @@ -622,6 +717,7 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_XCHG: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); SetValue(cmd.IsByteMode, Mem, op1, GetValue(cmd.IsByteMode, Mem, op2)); @@ -630,17 +726,21 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_MUL: + { - int result = - (int) - ((GetValue(cmd.IsByteMode, Mem, op1) & - 0xFFffFFff * GetValue(cmd.IsByteMode, Mem, op2) & unchecked((int)0xFFffFFff)) & - unchecked((int)0xFFffFFff)); + int result = (int)( + ( + GetValue(cmd.IsByteMode, Mem, op1) + & 0xFFffFFff * GetValue(cmd.IsByteMode, Mem, op2) + & unchecked((int)0xFFffFFff) + ) & unchecked((int)0xFFffFFff) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_DIV: + { int divider = GetValue(cmd.IsByteMode, Mem, op2); if (divider != 0) @@ -652,44 +752,60 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMCommands.VM_ADC: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); int FC = (int)(flags & VMFlags.VM_FC); - int result = - (int) - (value1 & 0xFFffFFff + GetValue(cmd.IsByteMode, Mem, op2) & - 0xFFffFFff + FC & unchecked((int)0xFFffFFff)); + int result = (int)( + value1 + & 0xFFffFFff + GetValue(cmd.IsByteMode, Mem, op2) + & 0xFFffFFff + FC + & unchecked((int)0xFFffFFff) + ); if (cmd.IsByteMode) { result &= 0xff; } - flags = - (VMFlags) - ((result < value1 || result == value1 && FC != 0) - ? 1 - : 0 | (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS))); + flags = (VMFlags)( + (result < value1 || result == value1 && FC != 0) + ? 1 + : 0 + | ( + result == 0 + ? (int)VMFlags.VM_FZ + : (result & (int)VMFlags.VM_FS) + ) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; case VMCommands.VM_SBB: + { int value1 = GetValue(cmd.IsByteMode, Mem, op1); int FC = (int)(flags & VMFlags.VM_FC); - int result = - (int) - (value1 & 0xFFffFFff - GetValue(cmd.IsByteMode, Mem, op2) & - 0xFFffFFff - FC & unchecked((int)0xFFffFFff)); + int result = (int)( + value1 + & 0xFFffFFff - GetValue(cmd.IsByteMode, Mem, op2) + & 0xFFffFFff - FC + & unchecked((int)0xFFffFFff) + ); if (cmd.IsByteMode) { result &= 0xff; } - flags = - (VMFlags) - ((result > value1 || result == value1 && FC != 0) - ? 1 - : 0 | (result == 0 ? (int)VMFlags.VM_FZ : (result & (int)VMFlags.VM_FS))); + flags = (VMFlags)( + (result > value1 || result == value1 && FC != 0) + ? 1 + : 0 + | ( + result == 0 + ? (int)VMFlags.VM_FZ + : (result & (int)VMFlags.VM_FS) + ) + ); SetValue(cmd.IsByteMode, Mem, op1, result); } break; @@ -785,7 +901,9 @@ namespace SharpCompress.Compressors.Rar.VM curCmd.OpCode = (VMCommands)((data >> 10) - 24); AddBits(6); } - if ((VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_BYTEMODE) != 0) + if ( + (VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_BYTEMODE) != 0 + ) { curCmd.IsByteMode = (GetBits() >> 15) == 1 ? true : false; AddBits(1); @@ -797,7 +915,9 @@ namespace SharpCompress.Compressors.Rar.VM curCmd.Op1.Type = VMOpType.VM_OPNONE; curCmd.Op2.Type = VMOpType.VM_OPNONE; - int opNum = (VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_OPMASK); + int opNum = ( + VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & VMCmdFlags.VMCF_OPMASK + ); // TODO >>> CurCmd->Op1.Addr=CurCmd->Op2.Addr=NULL; << 0) @@ -809,9 +929,13 @@ namespace SharpCompress.Compressors.Rar.VM } else { - if (curCmd.Op1.Type == VMOpType.VM_OPINT && - (VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] & - (VMCmdFlags.VMCF_JUMP | VMCmdFlags.VMCF_PROC)) != 0) + if ( + curCmd.Op1.Type == VMOpType.VM_OPINT + && ( + VMCmdFlags.VM_CmdFlags[(int)curCmd.OpCode] + & (VMCmdFlags.VMCF_JUMP | VMCmdFlags.VMCF_PROC) + ) != 0 + ) { int distance = curCmd.Op1.Data; if (distance >= 256) @@ -958,7 +1082,16 @@ namespace SharpCompress.Compressors.Rar.VM for (int i = commands.IndexOf(cmd) + 1; i < commands.Count; i++) { int flags = VMCmdFlags.VM_CmdFlags[(int)commands[i].OpCode]; - if ((flags & (VMCmdFlags.VMCF_JUMP | VMCmdFlags.VMCF_PROC | VMCmdFlags.VMCF_USEFLAGS)) != 0) + if ( + ( + flags + & ( + VMCmdFlags.VMCF_JUMP + | VMCmdFlags.VMCF_PROC + | VMCmdFlags.VMCF_USEFLAGS + ) + ) != 0 + ) { flagsRequired = true; break; @@ -1039,20 +1172,13 @@ namespace SharpCompress.Compressors.Rar.VM { VMStandardFilterSignature[] stdList = { - new VMStandardFilterSignature(53, 0xad576887, - VMStandardFilters.VMSF_E8), - new VMStandardFilterSignature(57, 0x3cd7e57e, - VMStandardFilters.VMSF_E8E9), - new VMStandardFilterSignature(120, 0x3769893f, - VMStandardFilters.VMSF_ITANIUM), - new VMStandardFilterSignature(29, 0x0e06077d, - VMStandardFilters.VMSF_DELTA), - new VMStandardFilterSignature(149, 0x1c2c5dc8, - VMStandardFilters.VMSF_RGB), - new VMStandardFilterSignature(216, 0xbc85e701, - VMStandardFilters.VMSF_AUDIO), - new VMStandardFilterSignature(40, 0x46b9c560, - VMStandardFilters.VMSF_UPCASE) + new VMStandardFilterSignature(53, 0xad576887, VMStandardFilters.VMSF_E8), + new VMStandardFilterSignature(57, 0x3cd7e57e, VMStandardFilters.VMSF_E8E9), + new VMStandardFilterSignature(120, 0x3769893f, VMStandardFilters.VMSF_ITANIUM), + new VMStandardFilterSignature(29, 0x0e06077d, VMStandardFilters.VMSF_DELTA), + new VMStandardFilterSignature(149, 0x1c2c5dc8, VMStandardFilters.VMSF_RGB), + new VMStandardFilterSignature(216, 0xbc85e701, VMStandardFilters.VMSF_AUDIO), + new VMStandardFilterSignature(40, 0x46b9c560, VMStandardFilters.VMSF_UPCASE) }; uint CodeCRC = RarCRC.CheckCrc(0xffffffff, code, 0, code.Length) ^ 0xffffffff; for (int i = 0; i < stdList.Length; i++) @@ -1071,6 +1197,7 @@ namespace SharpCompress.Compressors.Rar.VM { case VMStandardFilters.VMSF_E8: case VMStandardFilters.VMSF_E8E9: + { int dataSize = R[4]; long fileOffset = R[6] & unchecked((int)0xFFffFFff); @@ -1080,8 +1207,10 @@ namespace SharpCompress.Compressors.Rar.VM break; } int fileSize = 0x1000000; - byte cmpByte2 = (byte)((filterType == VMStandardFilters.VMSF_E8E9) ? 0xe9 : 0xe8); - for (int curPos = 0; curPos < dataSize - 4;) + byte cmpByte2 = (byte)( + (filterType == VMStandardFilters.VMSF_E8E9) ? 0xe9 : 0xe8 + ); + for (int curPos = 0; curPos < dataSize - 4; ) { byte curByte = Mem[curPos++]; if (curByte == 0xe8 || curByte == cmpByte2) @@ -1123,6 +1252,7 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMStandardFilters.VMSF_ITANIUM: + { int dataSize = R[4]; long fileOffset = R[6] & unchecked((int)0xFFffFFff); @@ -1150,12 +1280,24 @@ namespace SharpCompress.Compressors.Rar.VM if ((cmdMask & (1 << i)) != 0) { int startPos = i * 41 + 5; - int opType = filterItanium_GetBits(curPos, startPos + 37, 4); + int opType = filterItanium_GetBits( + curPos, + startPos + 37, + 4 + ); if (opType == 5) { - int offset = filterItanium_GetBits(curPos, startPos + 13, 20); - filterItanium_SetBits(curPos, (int)(offset - fileOffset) & 0xfffff, - startPos + 13, 20); + int offset = filterItanium_GetBits( + curPos, + startPos + 13, + 20 + ); + filterItanium_SetBits( + curPos, + (int)(offset - fileOffset) & 0xfffff, + startPos + 13, + 20 + ); } } } @@ -1168,6 +1310,7 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMStandardFilters.VMSF_DELTA: + { int dataSize = R[4] & unchecked((int)0xFFffFFff); int channels = R[0] & unchecked((int)0xFFffFFff); @@ -1185,7 +1328,11 @@ namespace SharpCompress.Compressors.Rar.VM for (int curChannel = 0; curChannel < channels; curChannel++) { byte PrevByte = 0; - for (int destPos = dataSize + curChannel; destPos < border; destPos += channels) + for ( + int destPos = dataSize + curChannel; + destPos < border; + destPos += channels + ) { Mem[destPos] = (PrevByte = (byte)(PrevByte - Mem[srcPos++])); } @@ -1194,9 +1341,12 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMStandardFilters.VMSF_RGB: + { // byte *SrcData=Mem,*DestData=SrcData+DataSize; - int dataSize = R[4], width = R[0] - 3, posR = R[1]; + int dataSize = R[4], + width = R[0] - 3, + posR = R[1]; int channels = 3; int srcPos = 0; int destDataPos = dataSize; @@ -1257,8 +1407,10 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMStandardFilters.VMSF_AUDIO: + { - int dataSize = R[4], channels = R[0]; + int dataSize = R[4], + channels = R[0]; int srcPos = 0; int destDataPos = dataSize; @@ -1273,10 +1425,18 @@ namespace SharpCompress.Compressors.Rar.VM long prevByte = 0; long prevDelta = 0; long[] Dif = new long[7]; - int D1 = 0, D2 = 0, D3; - int K1 = 0, K2 = 0, K3 = 0; + int D1 = 0, + D2 = 0, + D3; + int K1 = 0, + K2 = 0, + K3 = 0; - for (int i = curChannel, byteCount = 0; i < dataSize; i += channels, byteCount++) + for ( + int i = curChannel, byteCount = 0; + i < dataSize; + i += channels, byteCount++ + ) { D3 = D2; D2 = (int)(prevDelta - D1); @@ -1315,7 +1475,8 @@ namespace SharpCompress.Compressors.Rar.VM if ((byteCount & 0x1f) == 0) { - long minDif = Dif[0], numMinDif = 0; + long minDif = Dif[0], + numMinDif = 0; Dif[0] = 0; for (int j = 1; j < Dif.Length; j++) { @@ -1377,8 +1538,11 @@ namespace SharpCompress.Compressors.Rar.VM break; case VMStandardFilters.VMSF_UPCASE: + { - int dataSize = R[4], srcPos = 0, destPos = dataSize; + int dataSize = R[4], + srcPos = 0, + destPos = dataSize; if (dataSize >= VM_GLOBALMEMADDR / 2) { break; diff --git a/src/SharpCompress/Compressors/Rar/VM/VMCmdFlags.cs b/src/SharpCompress/Compressors/Rar/VM/VMCmdFlags.cs index 55ae8dfe..d599a558 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMCmdFlags.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMCmdFlags.cs @@ -14,13 +14,15 @@ namespace SharpCompress.Compressors.Rar.VM public static byte[] VM_CmdFlags = { - VMCF_OP2 | VMCF_BYTEMODE, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, + VMCF_OP2 | VMCF_BYTEMODE, + VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS, - VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP1 | VMCF_JUMP, + VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS, + VMCF_OP1 | VMCF_JUMP, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, @@ -30,17 +32,28 @@ namespace SharpCompress.Compressors.Rar.VM VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, - VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, VMCF_OP1, VMCF_OP1, - VMCF_OP1 | VMCF_PROC, VMCF_OP0 | VMCF_PROC, VMCF_OP1 | VMCF_BYTEMODE, + VMCF_OP1 | VMCF_JUMP | VMCF_USEFLAGS, + VMCF_OP1, + VMCF_OP1, + VMCF_OP1 | VMCF_PROC, + VMCF_OP0 | VMCF_PROC, + VMCF_OP1 | VMCF_BYTEMODE, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP2 | VMCF_BYTEMODE | VMCF_CHFLAGS, - VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS, VMCF_OP0, VMCF_OP0, - VMCF_OP0 | VMCF_USEFLAGS, VMCF_OP0 | VMCF_CHFLAGS, VMCF_OP2, VMCF_OP2, - VMCF_OP2 | VMCF_BYTEMODE, VMCF_OP2 | VMCF_BYTEMODE, + VMCF_OP1 | VMCF_BYTEMODE | VMCF_CHFLAGS, + VMCF_OP0, + VMCF_OP0, + VMCF_OP0 | VMCF_USEFLAGS, + VMCF_OP0 | VMCF_CHFLAGS, + VMCF_OP2, + VMCF_OP2, + VMCF_OP2 | VMCF_BYTEMODE, + VMCF_OP2 | VMCF_BYTEMODE, VMCF_OP2 | VMCF_BYTEMODE, VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS, - VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS, VMCF_OP0 + VMCF_OP2 | VMCF_BYTEMODE | VMCF_USEFLAGS | VMCF_CHFLAGS, + VMCF_OP0 }; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMCommands.cs b/src/SharpCompress/Compressors/Rar/VM/VMCommands.cs index 5164c4c5..46fde3f7 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMCommands.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMCommands.cs @@ -10,48 +10,42 @@ namespace SharpCompress.Compressors.Rar.VM VM_JNZ = 5, VM_INC = 6, - VM_DEC = - 7, + VM_DEC = 7, VM_JMP = 8, VM_XOR = 9, VM_AND = 10, VM_OR = 11, VM_TEST = 12, - VM_JS = - 13, + VM_JS = 13, VM_JNS = 14, VM_JB = 15, VM_JBE = 16, VM_JA = 17, VM_JAE = 18, - VM_PUSH = - 19, + VM_PUSH = 19, VM_POP = 20, VM_CALL = 21, VM_RET = 22, VM_NOT = 23, VM_SHL = 24, - VM_SHR = - 25, + VM_SHR = 25, VM_SAR = 26, VM_NEG = 27, VM_PUSHA = 28, VM_POPA = 29, VM_PUSHF = 30, - VM_POPF = - 31, + VM_POPF = 31, VM_MOVZX = 32, VM_MOVSX = 33, VM_XCHG = 34, VM_MUL = 35, VM_DIV = 36, - VM_ADC = - 37, + VM_ADC = 37, VM_SBB = 38, VM_PRINT = 39, @@ -67,12 +61,11 @@ namespace SharpCompress.Compressors.Rar.VM VM_INCB = 48, VM_INCD = 49, - VM_DECB = - 50, + VM_DECB = 50, VM_DECD = 51, VM_NEGB = 52, VM_NEGD = 53, VM_STANDARD = 54 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMFlags.cs b/src/SharpCompress/Compressors/Rar/VM/VMFlags.cs index f0c8fd72..d8b23ba8 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMFlags.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMFlags.cs @@ -7,4 +7,4 @@ namespace SharpCompress.Compressors.Rar.VM VM_FZ = 2, VM_FS = 80000000 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMOpType.cs b/src/SharpCompress/Compressors/Rar/VM/VMOpType.cs index 9ea99d1a..8c72eb74 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMOpType.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMOpType.cs @@ -7,4 +7,4 @@ namespace SharpCompress.Compressors.Rar.VM VM_OPREGMEM = 2, VM_OPNONE = 3 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs b/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs index fc3238b5..69a459ca 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMPreparedCommand.cs @@ -14,4 +14,4 @@ namespace SharpCompress.Compressors.Rar.VM internal VMPreparedOperand Op2 { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMPreparedOperand.cs b/src/SharpCompress/Compressors/Rar/VM/VMPreparedOperand.cs index b8cb10d9..2f20f306 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMPreparedOperand.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMPreparedOperand.cs @@ -7,4 +7,4 @@ namespace SharpCompress.Compressors.Rar.VM internal int Base { get; set; } internal int Offset { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMPreparedProgram.cs b/src/SharpCompress/Compressors/Rar/VM/VMPreparedProgram.cs index 94da8a76..de9e7054 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMPreparedProgram.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMPreparedProgram.cs @@ -18,4 +18,4 @@ namespace SharpCompress.Compressors.Rar.VM internal int FilteredDataOffset { get; set; } internal int FilteredDataSize { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs b/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs index a5812ed0..cc55f167 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMStandardFilterSignature.cs @@ -15,4 +15,4 @@ namespace SharpCompress.Compressors.Rar.VM internal VMStandardFilters Type { get; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Rar/VM/VMStandardFilters.cs b/src/SharpCompress/Compressors/Rar/VM/VMStandardFilters.cs index 07f74348..5f7c18ea 100644 --- a/src/SharpCompress/Compressors/Rar/VM/VMStandardFilters.cs +++ b/src/SharpCompress/Compressors/Rar/VM/VMStandardFilters.cs @@ -11,4 +11,4 @@ namespace SharpCompress.Compressors.Rar.VM VMSF_DELTA = 6, VMSF_UPCASE = 7 } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Xz/BinaryUtils.cs b/src/SharpCompress/Compressors/Xz/BinaryUtils.cs index 05f66c46..a0a92171 100644 --- a/src/SharpCompress/Compressors/Xz/BinaryUtils.cs +++ b/src/SharpCompress/Compressors/Xz/BinaryUtils.cs @@ -17,6 +17,7 @@ namespace SharpCompress.Compressors.Xz { return unchecked((uint)ReadLittleEndianInt32(reader)); } + public static int ReadLittleEndianInt32(this Stream stream) { Span bytes = stackalloc byte[4]; diff --git a/src/SharpCompress/Compressors/Xz/CheckType.cs b/src/SharpCompress/Compressors/Xz/CheckType.cs index 19c8019a..4176ac4b 100644 --- a/src/SharpCompress/Compressors/Xz/CheckType.cs +++ b/src/SharpCompress/Compressors/Xz/CheckType.cs @@ -7,4 +7,4 @@ namespace SharpCompress.Compressors.Xz CRC64 = 0x04, SHA256 = 0x0A } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Xz/Crc64.cs b/src/SharpCompress/Compressors/Xz/Crc64.cs index 1bea4a23..6ea99940 100644 --- a/src/SharpCompress/Compressors/Xz/Crc64.cs +++ b/src/SharpCompress/Compressors/Xz/Crc64.cs @@ -64,5 +64,4 @@ namespace SharpCompress.Compressors.Xz return createTable; } } - } diff --git a/src/SharpCompress/Compressors/Xz/Filters/ArmFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/ArmFilter.cs index dac51743..cefc1137 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/ArmFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/ArmFilter.cs @@ -47,10 +47,7 @@ namespace SharpCompress.Compressors.Xz.Filters } } - public override void ValidateFilter() - { - - } + public override void ValidateFilter() { } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/Xz/Filters/ArmThumbFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/ArmThumbFilter.cs index 2d6a87cd..3a70f6f7 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/ArmThumbFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/ArmThumbFilter.cs @@ -28,7 +28,6 @@ namespace SharpCompress.Compressors.Xz.Filters public override void Init(byte[] properties) { - if (properties.Length != 0 && properties.Length != 4) { throw new InvalidDataException("ARM Thumb properties unexpected length"); @@ -48,10 +47,7 @@ namespace SharpCompress.Compressors.Xz.Filters } } - public override void ValidateFilter() - { - - } + public override void ValidateFilter() { } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs index 3cfdc6d6..79eddaaa 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs @@ -19,15 +19,18 @@ namespace SharpCompress.Compressors.Xz.Filters LZMA2 = 0x21 } - private static readonly Dictionary FilterMap = new Dictionary - { - {FilterTypes.ARCH_x86_FILTER, typeof(X86Filter) }, - {FilterTypes.ARCH_PowerPC_FILTER, typeof(PowerPCFilter) }, - {FilterTypes.ARCH_IA64_FILTER, typeof(IA64Filter) }, - {FilterTypes.ARCH_ARM_FILTER, typeof(ArmFilter) }, - {FilterTypes.ARCH_ARMTHUMB_FILTER, typeof(ArmThumbFilter) }, - {FilterTypes.ARCH_SPARC_FILTER, typeof(SparcFilter) }, - {FilterTypes.LZMA2, typeof(Lzma2Filter) } + private static readonly Dictionary FilterMap = new Dictionary< + FilterTypes, + Type + > + { + { FilterTypes.ARCH_x86_FILTER, typeof(X86Filter) }, + { FilterTypes.ARCH_PowerPC_FILTER, typeof(PowerPCFilter) }, + { FilterTypes.ARCH_IA64_FILTER, typeof(IA64Filter) }, + { FilterTypes.ARCH_ARM_FILTER, typeof(ArmFilter) }, + { FilterTypes.ARCH_ARMTHUMB_FILTER, typeof(ArmThumbFilter) }, + { FilterTypes.ARCH_SPARC_FILTER, typeof(SparcFilter) }, + { FilterTypes.LZMA2, typeof(Lzma2Filter) } }; public abstract bool AllowAsLast { get; } @@ -42,7 +45,9 @@ namespace SharpCompress.Compressors.Xz.Filters var filterType = (FilterTypes)reader.ReadXZInteger(); if (!FilterMap.ContainsKey(filterType)) { - throw new NotImplementedException($"Filter {filterType} has not yet been implemented"); + throw new NotImplementedException( + $"Filter {filterType} has not yet been implemented" + ); } var filter = (BlockFilter)Activator.CreateInstance(FilterMap[filterType])!; diff --git a/src/SharpCompress/Compressors/Xz/Filters/IA64Filter.cs b/src/SharpCompress/Compressors/Xz/Filters/IA64Filter.cs index 5fb8b7d1..7c78ef26 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/IA64Filter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/IA64Filter.cs @@ -47,10 +47,7 @@ namespace SharpCompress.Compressors.Xz.Filters } } - public override void ValidateFilter() - { - - } + public override void ValidateFilter() { } public override int Read(byte[] buffer, int offset, int count) { @@ -59,6 +56,7 @@ namespace SharpCompress.Compressors.Xz.Filters _ip += (UInt32)bytesRead; return bytesRead; } + public override void SetBaseStream(Stream stream) { BaseStream = stream; diff --git a/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs b/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs index 7e35187d..be1f9ff4 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/Lzma2Filter.cs @@ -46,9 +46,7 @@ namespace SharpCompress.Compressors.Xz.Filters } } - public override void ValidateFilter() - { - } + public override void ValidateFilter() { } public override void SetBaseStream(Stream stream) { diff --git a/src/SharpCompress/Compressors/Xz/Filters/PowerPCFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/PowerPCFilter.cs index 3dfaed6d..b9566c35 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/PowerPCFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/PowerPCFilter.cs @@ -28,7 +28,6 @@ namespace SharpCompress.Compressors.Xz.Filters public override void Init(byte[] properties) { - if (properties.Length != 0 && properties.Length != 4) { throw new InvalidDataException("PPC properties unexpected length"); diff --git a/src/SharpCompress/Compressors/Xz/Filters/SparcFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/SparcFilter.cs index 4f5e925d..1b7d4edd 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/SparcFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/SparcFilter.cs @@ -26,8 +26,8 @@ namespace SharpCompress.Compressors.Xz.Filters //private UInt32 _offset = 0; - public override void Init(byte[] properties) { - + public override void Init(byte[] properties) + { if (properties.Length != 0 && properties.Length != 4) { throw new InvalidDataException("SPARC properties unexpected length"); @@ -47,18 +47,18 @@ namespace SharpCompress.Compressors.Xz.Filters } } - public override void ValidateFilter() { + public override void ValidateFilter() { } - } - - public override int Read(byte[] buffer, int offset, int count){ + public override int Read(byte[] buffer, int offset, int count) + { int bytesRead = BaseStream.Read(buffer, offset, count); BranchExecFilter.SPARCConverter(buffer, _ip); _ip += (UInt32)bytesRead; return bytesRead; } - public override void SetBaseStream(Stream stream) { + public override void SetBaseStream(Stream stream) + { BaseStream = stream; } } diff --git a/src/SharpCompress/Compressors/Xz/Filters/X86Filter.cs b/src/SharpCompress/Compressors/Xz/Filters/X86Filter.cs index f5fcf924..46d5837a 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/X86Filter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/X86Filter.cs @@ -49,10 +49,7 @@ namespace SharpCompress.Compressors.Xz.Filters } } - public override void ValidateFilter() - { - - } + public override void ValidateFilter() { } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Compressors/Xz/XZBlock.cs b/src/SharpCompress/Compressors/Xz/XZBlock.cs index dc3a010d..38409ecf 100644 --- a/src/SharpCompress/Compressors/Xz/XZBlock.cs +++ b/src/SharpCompress/Compressors/Xz/XZBlock.cs @@ -27,8 +27,7 @@ namespace SharpCompress.Compressors.Xz private bool _crcChecked; private ulong _bytesRead; - public XZBlock(Stream stream, CheckType checkType, int checkSize) - : base(stream) + public XZBlock(Stream stream, CheckType checkType, int checkSize) : base(stream) { _checkType = checkType; _checkSize = checkSize; @@ -159,7 +158,9 @@ namespace SharpCompress.Compressors.Xz if (reserved != 0) { - throw new InvalidDataException("Reserved bytes used, perhaps an unknown XZ implementation"); + throw new InvalidDataException( + "Reserved bytes used, perhaps an unknown XZ implementation" + ); } bool compressedSizePresent = (blockFlags & 0x40) != 0; @@ -182,8 +183,10 @@ namespace SharpCompress.Compressors.Xz for (int i = 0; i < _numFilters; i++) { var filter = BlockFilter.Read(reader); - if ((i + 1 == _numFilters && !filter.AllowAsLast) - || (i + 1 < _numFilters && !filter.AllowAsNonLast)) + if ( + (i + 1 == _numFilters && !filter.AllowAsLast) + || (i + 1 < _numFilters && !filter.AllowAsNonLast) + ) { throw new InvalidDataException("Block Filters in bad order"); } @@ -198,11 +201,13 @@ namespace SharpCompress.Compressors.Xz } if (nonLastSizeChangers > 2) { - throw new InvalidDataException("More than two non-last block filters cannot change stream size"); + throw new InvalidDataException( + "More than two non-last block filters cannot change stream size" + ); } - int blockHeaderPaddingSize = BlockHeaderSize - - (4 + (int)(reader.BaseStream.Position - baseStreamOffset)); + int blockHeaderPaddingSize = + BlockHeaderSize - (4 + (int)(reader.BaseStream.Position - baseStreamOffset)); byte[] blockHeaderPadding = reader.ReadBytes(blockHeaderPaddingSize); if (!blockHeaderPadding.All(b => b == 0)) { diff --git a/src/SharpCompress/Compressors/Xz/XZFooter.cs b/src/SharpCompress/Compressors/Xz/XZFooter.cs index 52f72619..40850f31 100644 --- a/src/SharpCompress/Compressors/Xz/XZFooter.cs +++ b/src/SharpCompress/Compressors/Xz/XZFooter.cs @@ -22,7 +22,9 @@ namespace SharpCompress.Compressors.Xz public static XZFooter FromStream(Stream stream) { - var footer = new XZFooter(new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8)); + var footer = new XZFooter( + new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8) + ); footer.Process(); return footer; } diff --git a/src/SharpCompress/Compressors/Xz/XZHeader.cs b/src/SharpCompress/Compressors/Xz/XZHeader.cs index 8934e135..5968cc62 100644 --- a/src/SharpCompress/Compressors/Xz/XZHeader.cs +++ b/src/SharpCompress/Compressors/Xz/XZHeader.cs @@ -21,7 +21,9 @@ namespace SharpCompress.Compressors.Xz public static XZHeader FromStream(Stream stream) { - var header = new XZHeader(new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8)); + var header = new XZHeader( + new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8) + ); header.Process(); return header; } diff --git a/src/SharpCompress/Compressors/Xz/XZIndex.cs b/src/SharpCompress/Compressors/Xz/XZIndex.cs index 997d53c3..7ad364ce 100644 --- a/src/SharpCompress/Compressors/Xz/XZIndex.cs +++ b/src/SharpCompress/Compressors/Xz/XZIndex.cs @@ -30,7 +30,10 @@ namespace SharpCompress.Compressors.Xz public static XZIndex FromStream(Stream stream, bool indexMarkerAlreadyVerified) { - var index = new XZIndex(new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8), indexMarkerAlreadyVerified); + var index = new XZIndex( + new BinaryReader(NonDisposingStream.Create(stream), Encoding.UTF8), + indexMarkerAlreadyVerified + ); index.Process(); return index; } diff --git a/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs b/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs index 387a2a1e..d5be9a82 100644 --- a/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs +++ b/src/SharpCompress/Compressors/Xz/XZIndexMarkerReachedException.cs @@ -2,7 +2,5 @@ namespace SharpCompress.Compressors.Xz { - public class XZIndexMarkerReachedException : Exception - { - } + public class XZIndexMarkerReachedException : Exception { } } diff --git a/src/SharpCompress/Compressors/Xz/XZStream.cs b/src/SharpCompress/Compressors/Xz/XZStream.cs index 49b5e801..41d968f5 100644 --- a/src/SharpCompress/Compressors/Xz/XZStream.cs +++ b/src/SharpCompress/Compressors/Xz/XZStream.cs @@ -33,9 +33,12 @@ namespace SharpCompress.Compressors.Xz case CheckType.SHA256: throw new NotImplementedException(); default: - throw new NotSupportedException("Check Type unknown to this version of decoder."); + throw new NotSupportedException( + "Check Type unknown to this version of decoder." + ); } } + public XZHeader Header { get; private set; } public XZIndex Index { get; private set; } public XZFooter Footer { get; private set; } @@ -44,9 +47,7 @@ namespace SharpCompress.Compressors.Xz private bool _endOfStream; - public XZStream(Stream stream) : base(stream) - { - } + public XZStream(Stream stream) : base(stream) { } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/Crypto/Crc32Stream.cs b/src/SharpCompress/Crypto/Crc32Stream.cs index 635c4677..d3349bf5 100644 --- a/src/SharpCompress/Crypto/Crc32Stream.cs +++ b/src/SharpCompress/Crypto/Crc32Stream.cs @@ -18,10 +18,7 @@ namespace SharpCompress.Crypto private readonly Stream stream; - public Crc32Stream(Stream stream) - : this(stream, DefaultPolynomial, DefaultSeed) - { - } + public Crc32Stream(Stream stream) : this(stream, DefaultPolynomial, DefaultSeed) { } public Crc32Stream(Stream stream, uint polynomial, uint seed) { @@ -37,9 +34,11 @@ namespace SharpCompress.Crypto stream.Flush(); } - public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException(); + public override int Read(byte[] buffer, int offset, int count) => + throw new NotSupportedException(); - public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) => + throw new NotSupportedException(); public override void SetLength(long value) => throw new NotSupportedException(); @@ -69,7 +68,11 @@ namespace SharpCompress.Crypto public override bool CanSeek => false; public override bool CanWrite => stream.CanWrite; public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public uint Crc => ~hash; diff --git a/src/SharpCompress/Crypto/CryptoException.cs b/src/SharpCompress/Crypto/CryptoException.cs index 6e8b9f14..f67e6a01 100644 --- a/src/SharpCompress/Crypto/CryptoException.cs +++ b/src/SharpCompress/Crypto/CryptoException.cs @@ -2,24 +2,12 @@ namespace SharpCompress.Crypto { - public class CryptoException - : Exception + public class CryptoException : Exception { - public CryptoException() - { - } + public CryptoException() { } - public CryptoException( - string message) - : base(message) - { - } + public CryptoException(string message) : base(message) { } - public CryptoException( - string message, - Exception exception) - : base(message, exception) - { - } + public CryptoException(string message, Exception exception) : base(message, exception) { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Crypto/DataLengthException.cs b/src/SharpCompress/Crypto/DataLengthException.cs index b82a9e9c..d1069755 100644 --- a/src/SharpCompress/Crypto/DataLengthException.cs +++ b/src/SharpCompress/Crypto/DataLengthException.cs @@ -2,16 +2,13 @@ namespace SharpCompress.Crypto { - public class DataLengthException - : CryptoException + public class DataLengthException : CryptoException { /** * base constructor. */ - public DataLengthException() - { - } + public DataLengthException() { } /** * create a DataLengthException with the given message. @@ -19,17 +16,9 @@ namespace SharpCompress.Crypto * @param message the message to be carried with the exception. */ - public DataLengthException( - string message) - : base(message) - { - } + public DataLengthException(string message) : base(message) { } - public DataLengthException( - string message, - Exception exception) - : base(message, exception) - { - } + public DataLengthException(string message, Exception exception) : base(message, exception) + { } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Crypto/IBlockCipher.cs b/src/SharpCompress/Crypto/IBlockCipher.cs index 61a37c46..eed5fc48 100644 --- a/src/SharpCompress/Crypto/IBlockCipher.cs +++ b/src/SharpCompress/Crypto/IBlockCipher.cs @@ -31,4 +31,4 @@ namespace SharpCompress.Crypto /// void Reset(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Crypto/ICipherParameters.cs b/src/SharpCompress/Crypto/ICipherParameters.cs index d6e4af8b..dbccaa77 100644 --- a/src/SharpCompress/Crypto/ICipherParameters.cs +++ b/src/SharpCompress/Crypto/ICipherParameters.cs @@ -1,6 +1,4 @@ namespace SharpCompress.Crypto { - public interface ICipherParameters - { - } -} \ No newline at end of file + public interface ICipherParameters { } +} diff --git a/src/SharpCompress/Crypto/KeyParameter.cs b/src/SharpCompress/Crypto/KeyParameter.cs index 7bf2dad8..3fb36f46 100644 --- a/src/SharpCompress/Crypto/KeyParameter.cs +++ b/src/SharpCompress/Crypto/KeyParameter.cs @@ -2,13 +2,11 @@ namespace SharpCompress.Crypto { - public class KeyParameter - : ICipherParameters + public class KeyParameter : ICipherParameters { private readonly byte[] key; - public KeyParameter( - byte[] key) + public KeyParameter(byte[] key) { if (key is null) { @@ -18,10 +16,7 @@ namespace SharpCompress.Crypto this.key = (byte[])key.Clone(); } - public KeyParameter( - byte[] key, - int keyOff, - int keyLen) + public KeyParameter(byte[] key, int keyOff, int keyLen) { if (key is null) { @@ -45,4 +40,4 @@ namespace SharpCompress.Crypto return (byte[])key.Clone(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Crypto/RijndaelEngine.cs b/src/SharpCompress/Crypto/RijndaelEngine.cs index b1adaa76..6b91306b 100644 --- a/src/SharpCompress/Crypto/RijndaelEngine.cs +++ b/src/SharpCompress/Crypto/RijndaelEngine.cs @@ -2,147 +2,1362 @@ namespace SharpCompress.Crypto { - public sealed class RijndaelEngine - : IBlockCipher + public sealed class RijndaelEngine : IBlockCipher { private const int MAXROUNDS = 14; private const int MAXKC = (256 / 4); - private static ReadOnlySpan Logtable => new byte[] - { - 0, 0, 25, 1, 50, 2, 26, 198, - 75, 199, 27, 104, 51, 238, 223, 3, - 100, 4, 224, 14, 52, 141, 129, 239, - 76, 113, 8, 200, 248, 105, 28, 193, - 125, 194, 29, 181, 249, 185, 39, 106, - 77, 228, 166, 114, 154, 201, 9, 120, - 101, 47, 138, 5, 33, 15, 225, 36, - 18, 240, 130, 69, 53, 147, 218, 142, - 150, 143, 219, 189, 54, 208, 206, 148, - 19, 92, 210, 241, 64, 70, 131, 56, - 102, 221, 253, 48, 191, 6, 139, 98, - 179, 37, 226, 152, 34, 136, 145, 16, - 126, 110, 72, 195, 163, 182, 30, 66, - 58, 107, 40, 84, 250, 133, 61, 186, - 43, 121, 10, 21, 155, 159, 94, 202, - 78, 212, 172, 229, 243, 115, 167, 87, - 175, 88, 168, 80, 244, 234, 214, 116, - 79, 174, 233, 213, 231, 230, 173, 232, - 44, 215, 117, 122, 235, 22, 11, 245, - 89, 203, 95, 176, 156, 169, 81, 160, - 127, 12, 246, 111, 23, 196, 73, 236, - 216, 67, 31, 45, 164, 118, 123, 183, - 204, 187, 62, 90, 251, 96, 177, 134, - 59, 82, 161, 108, 170, 85, 41, 157, - 151, 178, 135, 144, 97, 190, 220, 252, - 188, 149, 207, 205, 55, 63, 91, 209, - 83, 57, 132, 60, 65, 162, 109, 71, - 20, 42, 158, 93, 86, 242, 211, 171, - 68, 17, 146, 217, 35, 32, 46, 137, - 180, 124, 184, 38, 119, 153, 227, 165, - 103, 74, 237, 222, 197, 49, 254, 24, - 13, 99, 140, 128, 192, 247, 112, 7 - }; + private static ReadOnlySpan Logtable => + new byte[] + { + 0, + 0, + 25, + 1, + 50, + 2, + 26, + 198, + 75, + 199, + 27, + 104, + 51, + 238, + 223, + 3, + 100, + 4, + 224, + 14, + 52, + 141, + 129, + 239, + 76, + 113, + 8, + 200, + 248, + 105, + 28, + 193, + 125, + 194, + 29, + 181, + 249, + 185, + 39, + 106, + 77, + 228, + 166, + 114, + 154, + 201, + 9, + 120, + 101, + 47, + 138, + 5, + 33, + 15, + 225, + 36, + 18, + 240, + 130, + 69, + 53, + 147, + 218, + 142, + 150, + 143, + 219, + 189, + 54, + 208, + 206, + 148, + 19, + 92, + 210, + 241, + 64, + 70, + 131, + 56, + 102, + 221, + 253, + 48, + 191, + 6, + 139, + 98, + 179, + 37, + 226, + 152, + 34, + 136, + 145, + 16, + 126, + 110, + 72, + 195, + 163, + 182, + 30, + 66, + 58, + 107, + 40, + 84, + 250, + 133, + 61, + 186, + 43, + 121, + 10, + 21, + 155, + 159, + 94, + 202, + 78, + 212, + 172, + 229, + 243, + 115, + 167, + 87, + 175, + 88, + 168, + 80, + 244, + 234, + 214, + 116, + 79, + 174, + 233, + 213, + 231, + 230, + 173, + 232, + 44, + 215, + 117, + 122, + 235, + 22, + 11, + 245, + 89, + 203, + 95, + 176, + 156, + 169, + 81, + 160, + 127, + 12, + 246, + 111, + 23, + 196, + 73, + 236, + 216, + 67, + 31, + 45, + 164, + 118, + 123, + 183, + 204, + 187, + 62, + 90, + 251, + 96, + 177, + 134, + 59, + 82, + 161, + 108, + 170, + 85, + 41, + 157, + 151, + 178, + 135, + 144, + 97, + 190, + 220, + 252, + 188, + 149, + 207, + 205, + 55, + 63, + 91, + 209, + 83, + 57, + 132, + 60, + 65, + 162, + 109, + 71, + 20, + 42, + 158, + 93, + 86, + 242, + 211, + 171, + 68, + 17, + 146, + 217, + 35, + 32, + 46, + 137, + 180, + 124, + 184, + 38, + 119, + 153, + 227, + 165, + 103, + 74, + 237, + 222, + 197, + 49, + 254, + 24, + 13, + 99, + 140, + 128, + 192, + 247, + 112, + 7 + }; - private static ReadOnlySpan Alogtable => new byte[] - { - 0, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53, - 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170, - 229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49, - 83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205, - 76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136, - 131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154, - 181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163, - 254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160, - 251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65, - 195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117, - 159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128, - 155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84, - 252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, - 69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14, - 18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23, - 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1, - 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53, - 95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170, - 229, 52, 92, 228, 55, 89, 235, 38, 106, 190, 217, 112, 144, 171, 230, 49, - 83, 245, 4, 12, 20, 60, 68, 204, 79, 209, 104, 184, 211, 110, 178, 205, - 76, 212, 103, 169, 224, 59, 77, 215, 98, 166, 241, 8, 24, 40, 120, 136, - 131, 158, 185, 208, 107, 189, 220, 127, 129, 152, 179, 206, 73, 219, 118, 154, - 181, 196, 87, 249, 16, 48, 80, 240, 11, 29, 39, 105, 187, 214, 97, 163, - 254, 25, 43, 125, 135, 146, 173, 236, 47, 113, 147, 174, 233, 32, 96, 160, - 251, 22, 58, 78, 210, 109, 183, 194, 93, 231, 50, 86, 250, 21, 63, 65, - 195, 94, 226, 61, 71, 201, 64, 192, 91, 237, 44, 116, 156, 191, 218, 117, - 159, 186, 213, 100, 172, 239, 42, 126, 130, 157, 188, 223, 122, 142, 137, 128, - 155, 182, 193, 88, 232, 35, 101, 175, 234, 37, 111, 177, 200, 67, 197, 84, - 252, 31, 33, 99, 165, 244, 7, 9, 27, 45, 119, 153, 176, 203, 70, 202, - 69, 207, 74, 222, 121, 139, 134, 145, 168, 227, 62, 66, 198, 81, 243, 14, - 18, 54, 90, 238, 41, 123, 141, 140, 143, 138, 133, 148, 167, 242, 13, 23, - 57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1 - }; + private static ReadOnlySpan Alogtable => + new byte[] + { + 0, + 3, + 5, + 15, + 17, + 51, + 85, + 255, + 26, + 46, + 114, + 150, + 161, + 248, + 19, + 53, + 95, + 225, + 56, + 72, + 216, + 115, + 149, + 164, + 247, + 2, + 6, + 10, + 30, + 34, + 102, + 170, + 229, + 52, + 92, + 228, + 55, + 89, + 235, + 38, + 106, + 190, + 217, + 112, + 144, + 171, + 230, + 49, + 83, + 245, + 4, + 12, + 20, + 60, + 68, + 204, + 79, + 209, + 104, + 184, + 211, + 110, + 178, + 205, + 76, + 212, + 103, + 169, + 224, + 59, + 77, + 215, + 98, + 166, + 241, + 8, + 24, + 40, + 120, + 136, + 131, + 158, + 185, + 208, + 107, + 189, + 220, + 127, + 129, + 152, + 179, + 206, + 73, + 219, + 118, + 154, + 181, + 196, + 87, + 249, + 16, + 48, + 80, + 240, + 11, + 29, + 39, + 105, + 187, + 214, + 97, + 163, + 254, + 25, + 43, + 125, + 135, + 146, + 173, + 236, + 47, + 113, + 147, + 174, + 233, + 32, + 96, + 160, + 251, + 22, + 58, + 78, + 210, + 109, + 183, + 194, + 93, + 231, + 50, + 86, + 250, + 21, + 63, + 65, + 195, + 94, + 226, + 61, + 71, + 201, + 64, + 192, + 91, + 237, + 44, + 116, + 156, + 191, + 218, + 117, + 159, + 186, + 213, + 100, + 172, + 239, + 42, + 126, + 130, + 157, + 188, + 223, + 122, + 142, + 137, + 128, + 155, + 182, + 193, + 88, + 232, + 35, + 101, + 175, + 234, + 37, + 111, + 177, + 200, + 67, + 197, + 84, + 252, + 31, + 33, + 99, + 165, + 244, + 7, + 9, + 27, + 45, + 119, + 153, + 176, + 203, + 70, + 202, + 69, + 207, + 74, + 222, + 121, + 139, + 134, + 145, + 168, + 227, + 62, + 66, + 198, + 81, + 243, + 14, + 18, + 54, + 90, + 238, + 41, + 123, + 141, + 140, + 143, + 138, + 133, + 148, + 167, + 242, + 13, + 23, + 57, + 75, + 221, + 124, + 132, + 151, + 162, + 253, + 28, + 36, + 108, + 180, + 199, + 82, + 246, + 1, + 3, + 5, + 15, + 17, + 51, + 85, + 255, + 26, + 46, + 114, + 150, + 161, + 248, + 19, + 53, + 95, + 225, + 56, + 72, + 216, + 115, + 149, + 164, + 247, + 2, + 6, + 10, + 30, + 34, + 102, + 170, + 229, + 52, + 92, + 228, + 55, + 89, + 235, + 38, + 106, + 190, + 217, + 112, + 144, + 171, + 230, + 49, + 83, + 245, + 4, + 12, + 20, + 60, + 68, + 204, + 79, + 209, + 104, + 184, + 211, + 110, + 178, + 205, + 76, + 212, + 103, + 169, + 224, + 59, + 77, + 215, + 98, + 166, + 241, + 8, + 24, + 40, + 120, + 136, + 131, + 158, + 185, + 208, + 107, + 189, + 220, + 127, + 129, + 152, + 179, + 206, + 73, + 219, + 118, + 154, + 181, + 196, + 87, + 249, + 16, + 48, + 80, + 240, + 11, + 29, + 39, + 105, + 187, + 214, + 97, + 163, + 254, + 25, + 43, + 125, + 135, + 146, + 173, + 236, + 47, + 113, + 147, + 174, + 233, + 32, + 96, + 160, + 251, + 22, + 58, + 78, + 210, + 109, + 183, + 194, + 93, + 231, + 50, + 86, + 250, + 21, + 63, + 65, + 195, + 94, + 226, + 61, + 71, + 201, + 64, + 192, + 91, + 237, + 44, + 116, + 156, + 191, + 218, + 117, + 159, + 186, + 213, + 100, + 172, + 239, + 42, + 126, + 130, + 157, + 188, + 223, + 122, + 142, + 137, + 128, + 155, + 182, + 193, + 88, + 232, + 35, + 101, + 175, + 234, + 37, + 111, + 177, + 200, + 67, + 197, + 84, + 252, + 31, + 33, + 99, + 165, + 244, + 7, + 9, + 27, + 45, + 119, + 153, + 176, + 203, + 70, + 202, + 69, + 207, + 74, + 222, + 121, + 139, + 134, + 145, + 168, + 227, + 62, + 66, + 198, + 81, + 243, + 14, + 18, + 54, + 90, + 238, + 41, + 123, + 141, + 140, + 143, + 138, + 133, + 148, + 167, + 242, + 13, + 23, + 57, + 75, + 221, + 124, + 132, + 151, + 162, + 253, + 28, + 36, + 108, + 180, + 199, + 82, + 246, + 1 + }; - private static ReadOnlySpan S => new byte[] - { - 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, - 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, - 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, - 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, - 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, - 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, - 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, - 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210, - 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, - 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, - 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, - 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, - 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, - 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, - 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, - 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22 - }; + private static ReadOnlySpan S => + new byte[] + { + 99, + 124, + 119, + 123, + 242, + 107, + 111, + 197, + 48, + 1, + 103, + 43, + 254, + 215, + 171, + 118, + 202, + 130, + 201, + 125, + 250, + 89, + 71, + 240, + 173, + 212, + 162, + 175, + 156, + 164, + 114, + 192, + 183, + 253, + 147, + 38, + 54, + 63, + 247, + 204, + 52, + 165, + 229, + 241, + 113, + 216, + 49, + 21, + 4, + 199, + 35, + 195, + 24, + 150, + 5, + 154, + 7, + 18, + 128, + 226, + 235, + 39, + 178, + 117, + 9, + 131, + 44, + 26, + 27, + 110, + 90, + 160, + 82, + 59, + 214, + 179, + 41, + 227, + 47, + 132, + 83, + 209, + 0, + 237, + 32, + 252, + 177, + 91, + 106, + 203, + 190, + 57, + 74, + 76, + 88, + 207, + 208, + 239, + 170, + 251, + 67, + 77, + 51, + 133, + 69, + 249, + 2, + 127, + 80, + 60, + 159, + 168, + 81, + 163, + 64, + 143, + 146, + 157, + 56, + 245, + 188, + 182, + 218, + 33, + 16, + 255, + 243, + 210, + 205, + 12, + 19, + 236, + 95, + 151, + 68, + 23, + 196, + 167, + 126, + 61, + 100, + 93, + 25, + 115, + 96, + 129, + 79, + 220, + 34, + 42, + 144, + 136, + 70, + 238, + 184, + 20, + 222, + 94, + 11, + 219, + 224, + 50, + 58, + 10, + 73, + 6, + 36, + 92, + 194, + 211, + 172, + 98, + 145, + 149, + 228, + 121, + 231, + 200, + 55, + 109, + 141, + 213, + 78, + 169, + 108, + 86, + 244, + 234, + 101, + 122, + 174, + 8, + 186, + 120, + 37, + 46, + 28, + 166, + 180, + 198, + 232, + 221, + 116, + 31, + 75, + 189, + 139, + 138, + 112, + 62, + 181, + 102, + 72, + 3, + 246, + 14, + 97, + 53, + 87, + 185, + 134, + 193, + 29, + 158, + 225, + 248, + 152, + 17, + 105, + 217, + 142, + 148, + 155, + 30, + 135, + 233, + 206, + 85, + 40, + 223, + 140, + 161, + 137, + 13, + 191, + 230, + 66, + 104, + 65, + 153, + 45, + 15, + 176, + 84, + 187, + 22 + }; - private static ReadOnlySpan Si => new byte[] - { - 82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251, - 124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203, - 84, 123, 148, 50, 166, 194, 35, 61, 238, 76, 149, 11, 66, 250, 195, 78, - 8, 46, 161, 102, 40, 217, 36, 178, 118, 91, 162, 73, 109, 139, 209, 37, - 114, 248, 246, 100, 134, 104, 152, 22, 212, 164, 92, 204, 93, 101, 182, 146, - 108, 112, 72, 80, 253, 237, 185, 218, 94, 21, 70, 87, 167, 141, 157, 132, - 144, 216, 171, 0, 140, 188, 211, 10, 247, 228, 88, 5, 184, 179, 69, 6, - 208, 44, 30, 143, 202, 63, 15, 2, 193, 175, 189, 3, 1, 19, 138, 107, - 58, 145, 17, 65, 79, 103, 220, 234, 151, 242, 207, 206, 240, 180, 230, 115, - 150, 172, 116, 34, 231, 173, 53, 133, 226, 249, 55, 232, 28, 117, 223, 110, - 71, 241, 26, 113, 29, 41, 197, 137, 111, 183, 98, 14, 170, 24, 190, 27, - 252, 86, 62, 75, 198, 210, 121, 32, 154, 219, 192, 254, 120, 205, 90, 244, - 31, 221, 168, 51, 136, 7, 199, 49, 177, 18, 16, 89, 39, 128, 236, 95, - 96, 81, 127, 169, 25, 181, 74, 13, 45, 229, 122, 159, 147, 201, 156, 239, - 160, 224, 59, 77, 174, 42, 245, 176, 200, 235, 187, 60, 131, 83, 153, 97, - 23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125 - }; + private static ReadOnlySpan Si => + new byte[] + { + 82, + 9, + 106, + 213, + 48, + 54, + 165, + 56, + 191, + 64, + 163, + 158, + 129, + 243, + 215, + 251, + 124, + 227, + 57, + 130, + 155, + 47, + 255, + 135, + 52, + 142, + 67, + 68, + 196, + 222, + 233, + 203, + 84, + 123, + 148, + 50, + 166, + 194, + 35, + 61, + 238, + 76, + 149, + 11, + 66, + 250, + 195, + 78, + 8, + 46, + 161, + 102, + 40, + 217, + 36, + 178, + 118, + 91, + 162, + 73, + 109, + 139, + 209, + 37, + 114, + 248, + 246, + 100, + 134, + 104, + 152, + 22, + 212, + 164, + 92, + 204, + 93, + 101, + 182, + 146, + 108, + 112, + 72, + 80, + 253, + 237, + 185, + 218, + 94, + 21, + 70, + 87, + 167, + 141, + 157, + 132, + 144, + 216, + 171, + 0, + 140, + 188, + 211, + 10, + 247, + 228, + 88, + 5, + 184, + 179, + 69, + 6, + 208, + 44, + 30, + 143, + 202, + 63, + 15, + 2, + 193, + 175, + 189, + 3, + 1, + 19, + 138, + 107, + 58, + 145, + 17, + 65, + 79, + 103, + 220, + 234, + 151, + 242, + 207, + 206, + 240, + 180, + 230, + 115, + 150, + 172, + 116, + 34, + 231, + 173, + 53, + 133, + 226, + 249, + 55, + 232, + 28, + 117, + 223, + 110, + 71, + 241, + 26, + 113, + 29, + 41, + 197, + 137, + 111, + 183, + 98, + 14, + 170, + 24, + 190, + 27, + 252, + 86, + 62, + 75, + 198, + 210, + 121, + 32, + 154, + 219, + 192, + 254, + 120, + 205, + 90, + 244, + 31, + 221, + 168, + 51, + 136, + 7, + 199, + 49, + 177, + 18, + 16, + 89, + 39, + 128, + 236, + 95, + 96, + 81, + 127, + 169, + 25, + 181, + 74, + 13, + 45, + 229, + 122, + 159, + 147, + 201, + 156, + 239, + 160, + 224, + 59, + 77, + 174, + 42, + 245, + 176, + 200, + 235, + 187, + 60, + 131, + 83, + 153, + 97, + 23, + 43, + 4, + 126, + 186, + 119, + 214, + 38, + 225, + 105, + 20, + 99, + 85, + 33, + 12, + 125 + }; - private static ReadOnlySpan rcon => new byte[] - { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, - 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 - }; + private static ReadOnlySpan rcon => + new byte[] + { + 0x01, + 0x02, + 0x04, + 0x08, + 0x10, + 0x20, + 0x40, + 0x80, + 0x1b, + 0x36, + 0x6c, + 0xd8, + 0xab, + 0x4d, + 0x9a, + 0x2f, + 0x5e, + 0xbc, + 0x63, + 0xc6, + 0x97, + 0x35, + 0x6a, + 0xd4, + 0xb3, + 0x7d, + 0xfa, + 0xef, + 0xc5, + 0x91 + }; private static readonly byte[][] shifts0 = { - new byte[] {0, 8, 16, 24}, - new byte[] {0, 8, 16, 24}, - new byte[] {0, 8, 16, 24}, - new byte[] {0, 8, 16, 32}, - new byte[] {0, 8, 24, 32} + new byte[] { 0, 8, 16, 24 }, + new byte[] { 0, 8, 16, 24 }, + new byte[] { 0, 8, 16, 24 }, + new byte[] { 0, 8, 16, 32 }, + new byte[] { 0, 8, 24, 32 } }; private static readonly byte[][] shifts1 = { - new byte[] {0, 24, 16, 8}, - new byte[] {0, 32, 24, 16}, - new byte[] {0, 40, 32, 24}, - new byte[] {0, 48, 40, 24}, - new byte[] {0, 56, 40, 32} + new byte[] { 0, 24, 16, 8 }, + new byte[] { 0, 32, 24, 16 }, + new byte[] { 0, 40, 32, 24 }, + new byte[] { 0, 48, 40, 24 }, + new byte[] { 0, 56, 40, 32 } }; /** @@ -150,8 +1365,7 @@ namespace SharpCompress.Crypto * needed for MixColumn and InvMixColumn */ - private byte Mul0x2( - int b) + private byte Mul0x2(int b) { if (b != 0) { @@ -160,8 +1374,7 @@ namespace SharpCompress.Crypto return 0; } - private byte Mul0x3( - int b) + private byte Mul0x3(int b) { if (b != 0) { @@ -170,8 +1383,7 @@ namespace SharpCompress.Crypto return 0; } - private byte Mul0x9( - int b) + private byte Mul0x9(int b) { if (b >= 0) { @@ -180,8 +1392,7 @@ namespace SharpCompress.Crypto return 0; } - private byte Mul0xb( - int b) + private byte Mul0xb(int b) { if (b >= 0) { @@ -190,8 +1401,7 @@ namespace SharpCompress.Crypto return 0; } - private byte Mul0xd( - int b) + private byte Mul0xd(int b) { if (b >= 0) { @@ -200,8 +1410,7 @@ namespace SharpCompress.Crypto return 0; } - private byte Mul0xe( - int b) + private byte Mul0xe(int b) { if (b >= 0) { @@ -222,9 +1431,7 @@ namespace SharpCompress.Crypto A3 ^= rk[3]; } - private long Shift( - long r, - int shift) + private long Shift(long r, int shift) { //return (((long)((ulong) r >> shift) | (r << (BC - shift)))) & BC_MASK; @@ -282,7 +1489,10 @@ namespace SharpCompress.Crypto private void MixColumn() { - long r0, r1, r2, r3; + long r0, + r1, + r2, + r3; r0 = r1 = r2 = r3 = 0; @@ -315,7 +1525,10 @@ namespace SharpCompress.Crypto private void InvMixColumn() { - long r0, r1, r2, r3; + long r0, + r1, + r2, + r3; r0 = r1 = r2 = r3 = 0; for (int j = 0; j < BC; j += 8) @@ -353,10 +1566,10 @@ namespace SharpCompress.Crypto * The number of calculations depends on keyBits and blockBits */ - private long[][] GenerateWorkingKey( - byte[] key) + private long[][] GenerateWorkingKey(byte[] key) { - int t, rconpointer = 0; + int t, + rconpointer = 0; int keyBits = key.Length * 8; byte[,] tk = new byte[4, MAXKC]; @@ -472,7 +1685,10 @@ namespace SharpCompress.Crypto private int ROUNDS; private readonly int blockBits; private long[][]? workingKey; - private long A0, A1, A2, A3; + private long A0, + A1, + A2, + A3; private bool forEncryption; private readonly byte[] shifts0SC; private readonly byte[] shifts1SC; @@ -481,10 +1697,7 @@ namespace SharpCompress.Crypto * default constructor - 128 bit block size. */ - public RijndaelEngine() - : this(128) - { - } + public RijndaelEngine() : this(128) { } /** * basic constructor - set the cipher up for a given blocksize @@ -492,8 +1705,7 @@ namespace SharpCompress.Crypto * @param blocksize the blocksize in bits, must be 128, 192, or 256. */ - public RijndaelEngine( - int blockBits) + public RijndaelEngine(int blockBits) { switch (blockBits) { @@ -543,9 +1755,7 @@ namespace SharpCompress.Crypto * inappropriate. */ - public void Init( - bool forEncryption, - ICipherParameters parameters) + public void Init(bool forEncryption, ICipherParameters parameters) { var parameter = parameters as KeyParameter; if (parameter != null) @@ -555,7 +1765,9 @@ namespace SharpCompress.Crypto return; } - throw new ArgumentException("invalid parameter passed to Rijndael init - " + parameters.GetType()); + throw new ArgumentException( + "invalid parameter passed to Rijndael init - " + parameters.GetType() + ); } public string AlgorithmName => "Rijndael"; @@ -600,9 +1812,7 @@ namespace SharpCompress.Crypto return BC / 2; } - public void Reset() - { - } + public void Reset() { } private void UnPackBlock(ReadOnlySpan bytes) { @@ -700,4 +1910,4 @@ namespace SharpCompress.Crypto KeyAddition(rk[0]); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Factories/Factory.cs b/src/SharpCompress/Factories/Factory.cs index 9f5cb001..ba0bae88 100644 --- a/src/SharpCompress/Factories/Factory.cs +++ b/src/SharpCompress/Factories/Factory.cs @@ -29,7 +29,7 @@ namespace SharpCompress.Factories /// /// Gets the collection of registered . /// - public static IEnumerable Factories => _factories; + public static IEnumerable Factories => _factories; /// /// Registers an archive factory. @@ -71,7 +71,11 @@ namespace SharpCompress.Factories /// /// /// - internal virtual bool TryOpenReader(RewindableStream rewindableStream, ReaderOptions options, out IReader? reader) + internal virtual bool TryOpenReader( + RewindableStream rewindableStream, + ReaderOptions options, + out IReader? reader + ) { reader = null; @@ -85,8 +89,8 @@ namespace SharpCompress.Factories return true; } } - + return false; - } + } } } diff --git a/src/SharpCompress/Factories/GZipFactory.cs b/src/SharpCompress/Factories/GZipFactory.cs index fe6f4260..1c473e55 100644 --- a/src/SharpCompress/Factories/GZipFactory.cs +++ b/src/SharpCompress/Factories/GZipFactory.cs @@ -20,12 +20,13 @@ namespace SharpCompress.Factories /// /// Represents the foundation factory of GZip archive. /// - public class GZipFactory : Factory, - IArchiveFactory, - IMultiArchiveFactory, - IReaderFactory, - IWriterFactory, - IWriteableArchiveFactory + public class GZipFactory + : Factory, + IArchiveFactory, + IMultiArchiveFactory, + IReaderFactory, + IWriterFactory, + IWriteableArchiveFactory { #region IFactory @@ -65,7 +66,7 @@ namespace SharpCompress.Factories #endregion - #region IMultiArchiveFactory + #region IMultiArchiveFactory /// public IArchive Open(IReadOnlyList streams, ReaderOptions? readerOptions = null) @@ -84,7 +85,11 @@ namespace SharpCompress.Factories #region IReaderFactory /// - internal override bool TryOpenReader(RewindableStream rewindableStream, ReaderOptions options, out IReader? reader) + internal override bool TryOpenReader( + RewindableStream rewindableStream, + ReaderOptions options, + out IReader? reader + ) { reader = null; @@ -104,7 +109,7 @@ namespace SharpCompress.Factories reader = OpenReader(rewindableStream, options); return true; } - + return false; } @@ -123,7 +128,9 @@ namespace SharpCompress.Factories { if (writerOptions.CompressionType != CompressionType.GZip) { - throw new InvalidFormatException("GZip archives only support GZip compression type."); + throw new InvalidFormatException( + "GZip archives only support GZip compression type." + ); } return new GZipWriter(stream, new GZipWriterOptions(writerOptions)); } diff --git a/src/SharpCompress/Factories/IFactory.cs b/src/SharpCompress/Factories/IFactory.cs index 82e27f11..39c2c384 100644 --- a/src/SharpCompress/Factories/IFactory.cs +++ b/src/SharpCompress/Factories/IFactory.cs @@ -32,7 +32,7 @@ namespace SharpCompress.Factories /// returns the extensions typically used by this archive type. /// /// - IEnumerable GetSupportedExtensions(); + IEnumerable GetSupportedExtensions(); /// /// Returns true if the stream represents an archive of the format defined by this type. @@ -52,4 +52,3 @@ namespace SharpCompress.Factories FileInfo? GetFilePart(int index, FileInfo part1); } } - diff --git a/src/SharpCompress/Factories/RarFactory.cs b/src/SharpCompress/Factories/RarFactory.cs index 7d6c16ba..f9ffdb8c 100644 --- a/src/SharpCompress/Factories/RarFactory.cs +++ b/src/SharpCompress/Factories/RarFactory.cs @@ -14,10 +14,7 @@ namespace SharpCompress.Factories /// /// Represents the foundation factory of RAR archive. /// - public class RarFactory : Factory, - IArchiveFactory, - IMultiArchiveFactory, - IReaderFactory + public class RarFactory : Factory, IArchiveFactory, IMultiArchiveFactory, IReaderFactory { #region IArchive @@ -48,7 +45,7 @@ namespace SharpCompress.Factories #endregion - #region IArchiveFactory + #region IArchiveFactory /// public IArchive Open(Stream stream, ReaderOptions? readerOptions = null) @@ -80,7 +77,7 @@ namespace SharpCompress.Factories #endregion - #region IReaderFactory + #region IReaderFactory /// public IReader OpenReader(Stream stream, ReaderOptions? options) diff --git a/src/SharpCompress/Factories/SevenZipFactory.cs b/src/SharpCompress/Factories/SevenZipFactory.cs index c7d4dd8b..8bdbb8d0 100644 --- a/src/SharpCompress/Factories/SevenZipFactory.cs +++ b/src/SharpCompress/Factories/SevenZipFactory.cs @@ -14,9 +14,7 @@ namespace SharpCompress.Factories /// /// Represents the foundation factory of 7Zip archive. /// - public class SevenZipFactory : Factory, - IArchiveFactory, - IMultiArchiveFactory + public class SevenZipFactory : Factory, IArchiveFactory, IMultiArchiveFactory { #region IFactory @@ -40,7 +38,7 @@ namespace SharpCompress.Factories #endregion - #region IArchiveFactory + #region IArchiveFactory /// public IArchive Open(Stream stream, ReaderOptions? readerOptions = null) @@ -68,18 +66,22 @@ namespace SharpCompress.Factories public IArchive Open(IReadOnlyList fileInfos, ReaderOptions? readerOptions = null) { return SevenZipArchive.Open(fileInfos, readerOptions); - } + } #endregion #region reader - internal override bool TryOpenReader(RewindableStream rewindableStream, ReaderOptions options, out IReader? reader) + internal override bool TryOpenReader( + RewindableStream rewindableStream, + ReaderOptions options, + out IReader? reader + ) { reader = null; return false; } - + #endregion } } diff --git a/src/SharpCompress/Factories/TarFactory.cs b/src/SharpCompress/Factories/TarFactory.cs index 4214ca93..b2322d56 100644 --- a/src/SharpCompress/Factories/TarFactory.cs +++ b/src/SharpCompress/Factories/TarFactory.cs @@ -22,12 +22,13 @@ namespace SharpCompress.Factories /// /// Represents the foundation factory of TAR archive. /// - public class TarFactory : Factory, - IArchiveFactory, - IMultiArchiveFactory, - IReaderFactory, - IWriterFactory, - IWriteableArchiveFactory + public class TarFactory + : Factory, + IArchiveFactory, + IMultiArchiveFactory, + IReaderFactory, + IWriterFactory, + IWriteableArchiveFactory { #region IFactory @@ -111,7 +112,11 @@ namespace SharpCompress.Factories #region IReaderFactory /// - internal override bool TryOpenReader(RewindableStream rewindableStream, ReaderOptions options, out IReader? reader) + internal override bool TryOpenReader( + RewindableStream rewindableStream, + ReaderOptions options, + out IReader? reader + ) { reader = null; @@ -127,7 +132,11 @@ namespace SharpCompress.Factories if (BZip2Stream.IsBZip2(rewindableStream)) { rewindableStream.Rewind(false); - var testStream = new BZip2Stream(NonDisposingStream.Create(rewindableStream), CompressionMode.Decompress, false); + var testStream = new BZip2Stream( + NonDisposingStream.Create(rewindableStream), + CompressionMode.Decompress, + false + ); if (TarArchive.IsTarFile(testStream)) { rewindableStream.Rewind(true); @@ -140,7 +149,10 @@ namespace SharpCompress.Factories if (LZipStream.IsLZipFile(rewindableStream)) { rewindableStream.Rewind(false); - var testStream = new LZipStream(NonDisposingStream.Create(rewindableStream), CompressionMode.Decompress); + var testStream = new LZipStream( + NonDisposingStream.Create(rewindableStream), + CompressionMode.Decompress + ); if (TarArchive.IsTarFile(testStream)) { rewindableStream.Rewind(true); @@ -161,7 +173,7 @@ namespace SharpCompress.Factories return true; } } - + return false; } @@ -192,6 +204,5 @@ namespace SharpCompress.Factories } #endregion - } } diff --git a/src/SharpCompress/Factories/ZipFactory.cs b/src/SharpCompress/Factories/ZipFactory.cs index a3e6e757..66b274cb 100644 --- a/src/SharpCompress/Factories/ZipFactory.cs +++ b/src/SharpCompress/Factories/ZipFactory.cs @@ -18,12 +18,13 @@ namespace SharpCompress.Factories /// /// Represents the foundation factory of ZIP archive. /// - public class ZipFactory : Factory, - IArchiveFactory, - IMultiArchiveFactory, - IReaderFactory, - IWriterFactory, - IWriteableArchiveFactory + public class ZipFactory + : Factory, + IArchiveFactory, + IMultiArchiveFactory, + IReaderFactory, + IWriterFactory, + IWriteableArchiveFactory { #region IFactory @@ -44,9 +45,7 @@ namespace SharpCompress.Factories /// public override bool IsArchive(Stream stream, string? password = null) { - var startPosition = stream.CanSeek - ? stream.Position - : -1; + var startPosition = stream.CanSeek ? stream.Position : -1; // probe for single volume zip @@ -91,7 +90,7 @@ namespace SharpCompress.Factories #endregion - #region IMultiArchiveFactory + #region IMultiArchiveFactory /// public IArchive Open(IReadOnlyList streams, ReaderOptions? readerOptions = null) @@ -107,7 +106,7 @@ namespace SharpCompress.Factories #endregion - #region IReaderFactory + #region IReaderFactory /// public IReader OpenReader(Stream stream, ReaderOptions? options) diff --git a/src/SharpCompress/IO/BufferedSubStream.cs b/src/SharpCompress/IO/BufferedSubStream.cs index 9b6ae6cd..94d70b17 100644 --- a/src/SharpCompress/IO/BufferedSubStream.cs +++ b/src/SharpCompress/IO/BufferedSubStream.cs @@ -10,7 +10,8 @@ namespace SharpCompress.IO private int cacheLength; private readonly byte[] cache; - public BufferedSubStream(Stream stream, long origin, long bytesToRead) : base(stream, throwOnDispose: false) + public BufferedSubStream(Stream stream, long origin, long bytesToRead) + : base(stream, throwOnDispose: false) { position = origin; BytesLeftToRead = bytesToRead; @@ -32,7 +33,11 @@ namespace SharpCompress.IO public override long Length => BytesLeftToRead; - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -80,4 +85,4 @@ namespace SharpCompress.IO throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/IO/CountingWritableSubStream.cs b/src/SharpCompress/IO/CountingWritableSubStream.cs index b94303bf..a5aa4465 100644 --- a/src/SharpCompress/IO/CountingWritableSubStream.cs +++ b/src/SharpCompress/IO/CountingWritableSubStream.cs @@ -5,9 +5,7 @@ namespace SharpCompress.IO { internal class CountingWritableSubStream : NonDisposingStream { - internal CountingWritableSubStream(Stream stream) : base(stream, throwOnDispose: false) - { - } + internal CountingWritableSubStream(Stream stream) : base(stream, throwOnDispose: false) { } public ulong Count { get; private set; } @@ -24,7 +22,11 @@ namespace SharpCompress.IO public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -53,4 +55,4 @@ namespace SharpCompress.IO ++Count; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/IO/ListeningStream.cs b/src/SharpCompress/IO/ListeningStream.cs index 1bab99d2..d914bec4 100644 --- a/src/SharpCompress/IO/ListeningStream.cs +++ b/src/SharpCompress/IO/ListeningStream.cs @@ -38,13 +38,20 @@ namespace SharpCompress.IO public override long Length => Stream.Length; - public override long Position { get => Stream.Position; set => Stream.Position = value; } + public override long Position + { + get => Stream.Position; + set => Stream.Position = value; + } public override int Read(byte[] buffer, int offset, int count) { int read = Stream.Read(buffer, offset, count); currentEntryTotalReadBytes += read; - listener.FireCompressedBytesRead(currentEntryTotalReadBytes, currentEntryTotalReadBytes); + listener.FireCompressedBytesRead( + currentEntryTotalReadBytes, + currentEntryTotalReadBytes + ); return read; } @@ -57,7 +64,10 @@ namespace SharpCompress.IO } ++currentEntryTotalReadBytes; - listener.FireCompressedBytesRead(currentEntryTotalReadBytes, currentEntryTotalReadBytes); + listener.FireCompressedBytesRead( + currentEntryTotalReadBytes, + currentEntryTotalReadBytes + ); return value; } @@ -76,4 +86,4 @@ namespace SharpCompress.IO Stream.Write(buffer, offset, count); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/IO/MarkingBinaryReader.cs b/src/SharpCompress/IO/MarkingBinaryReader.cs index 5b3e7ffe..01847518 100644 --- a/src/SharpCompress/IO/MarkingBinaryReader.cs +++ b/src/SharpCompress/IO/MarkingBinaryReader.cs @@ -6,10 +6,7 @@ namespace SharpCompress.IO { internal class MarkingBinaryReader : BinaryReader { - public MarkingBinaryReader(Stream stream) - : base(stream) - { - } + public MarkingBinaryReader(Stream stream) : base(stream) { } public virtual long CurrentReadByteCount { get; protected set; } @@ -59,7 +56,13 @@ namespace SharpCompress.IO var bytes = base.ReadBytes(count); if (bytes.Length != count) { - throw new EndOfStreamException(string.Format("Could not read the requested amount of bytes. End of stream reached. Requested: {0} Read: {1}", count, bytes.Length)); + throw new EndOfStreamException( + string.Format( + "Could not read the requested amount of bytes. End of stream reached. Requested: {0} Read: {1}", + count, + bytes.Length + ) + ); } return bytes; } diff --git a/src/SharpCompress/IO/NonDisposingStream.cs b/src/SharpCompress/IO/NonDisposingStream.cs index 12b9a6cf..a3b74469 100644 --- a/src/SharpCompress/IO/NonDisposingStream.cs +++ b/src/SharpCompress/IO/NonDisposingStream.cs @@ -7,7 +7,10 @@ namespace SharpCompress.IO { public static NonDisposingStream Create(Stream stream, bool throwOnDispose = false) { - if (stream is NonDisposingStream nonDisposingStream && nonDisposingStream.ThrowOnDispose == throwOnDispose) + if ( + stream is NonDisposingStream nonDisposingStream + && nonDisposingStream.ThrowOnDispose == throwOnDispose + ) { return nonDisposingStream; } @@ -26,7 +29,9 @@ namespace SharpCompress.IO { if (ThrowOnDispose) { - throw new InvalidOperationException($"Attempt to dispose of a {nameof(NonDisposingStream)} when {nameof(ThrowOnDispose)} is {ThrowOnDispose}"); + throw new InvalidOperationException( + $"Attempt to dispose of a {nameof(NonDisposingStream)} when {nameof(ThrowOnDispose)} is {ThrowOnDispose}" + ); } } @@ -45,7 +50,11 @@ namespace SharpCompress.IO public override long Length => Stream.Length; - public override long Position { get => Stream.Position; set => Stream.Position = value; } + public override long Position + { + get => Stream.Position; + set => Stream.Position = value; + } public override int Read(byte[] buffer, int offset, int count) { diff --git a/src/SharpCompress/IO/ReadOnlySubStream.cs b/src/SharpCompress/IO/ReadOnlySubStream.cs index 4ba326dd..f098db4c 100644 --- a/src/SharpCompress/IO/ReadOnlySubStream.cs +++ b/src/SharpCompress/IO/ReadOnlySubStream.cs @@ -5,10 +5,8 @@ namespace SharpCompress.IO { internal class ReadOnlySubStream : NonDisposingStream { - public ReadOnlySubStream(Stream stream, long bytesToRead) - : this(stream, null, bytesToRead) - { - } + public ReadOnlySubStream(Stream stream, long bytesToRead) : this(stream, null, bytesToRead) + { } public ReadOnlySubStream(Stream stream, long? origin, long bytesToRead) : base(stream, throwOnDispose: false) @@ -35,7 +33,11 @@ namespace SharpCompress.IO public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } public override int Read(byte[] buffer, int offset, int count) { @@ -69,7 +71,7 @@ namespace SharpCompress.IO public override int Read(Span buffer) { var slice_len = BytesLeftToRead < buffer.Length ? BytesLeftToRead : buffer.Length; - var read = Stream.Read(buffer.Slice(0,(int)slice_len)); + var read = Stream.Read(buffer.Slice(0, (int)slice_len)); if (read > 0) { BytesLeftToRead -= read; diff --git a/src/SharpCompress/IO/RewindableStream.cs b/src/SharpCompress/IO/RewindableStream.cs index c30efeb0..281f08ea 100644 --- a/src/SharpCompress/IO/RewindableStream.cs +++ b/src/SharpCompress/IO/RewindableStream.cs @@ -46,7 +46,6 @@ namespace SharpCompress.IO } else { - bufferStream.TransferTo(buffer); //create new memorystream to allow proper resizing as memorystream could be a user provided buffer //https://github.com/adamhathcock/sharpcompress/issues/306 diff --git a/src/SharpCompress/IO/SourceStream.cs b/src/SharpCompress/IO/SourceStream.cs index e23f7eb7..35fba988 100644 --- a/src/SharpCompress/IO/SourceStream.cs +++ b/src/SharpCompress/IO/SourceStream.cs @@ -17,15 +17,19 @@ namespace SharpCompress.IO private Func _getStreamPart; private int _stream; - public SourceStream(FileInfo file, Func getPart, ReaderOptions options) : this(null, null, file, getPart, options) - { - } + public SourceStream(FileInfo file, Func getPart, ReaderOptions options) + : this(null, null, file, getPart, options) { } - public SourceStream(Stream stream, Func getPart, ReaderOptions options) : this(stream, getPart, null, null, options) - { - } + public SourceStream(Stream stream, Func getPart, ReaderOptions options) + : this(stream, getPart, null, null, options) { } - private SourceStream(Stream? stream, Func? getStreamPart, FileInfo? file, Func? getFilePart, ReaderOptions options) + private SourceStream( + Stream? stream, + Func? getStreamPart, + FileInfo? file, + Func? getFilePart, + ReaderOptions options + ) { this.ReaderOptions = options; _files = new List(); @@ -54,9 +58,7 @@ namespace SharpCompress.IO public void LoadAllParts() { - for (int i = 1; SetStream(i); i++) - { - } + for (int i = 1; SetStream(i); i++) { } SetStream(0); } @@ -69,6 +71,7 @@ namespace SharpCompress.IO public IEnumerable Streams => _streams; private Stream Current => _streams[_stream]; + public bool LoadStream(int index) //ensure all parts to id are loaded { while (_streams.Count <= index) @@ -101,6 +104,7 @@ namespace SharpCompress.IO } return true; } + public bool SetStream(int idx) //allow caller to switch part in multipart { if (LoadStream(idx)) @@ -137,7 +141,11 @@ namespace SharpCompress.IO while (count != 0 && r != 0) { - r = Current.Read(buffer, offset, (int)Math.Min(count, Current.Length - Current.Position)); + r = Current.Read( + buffer, + offset, + (int)Math.Min(count, Current.Length - Current.Position) + ); count -= r; offset += r; @@ -146,7 +154,7 @@ namespace SharpCompress.IO var length = Current.Length; // Load next file if present - if (!SetStream(_stream + 1)) + if (!SetStream(_stream + 1)) { break; } @@ -166,9 +174,15 @@ namespace SharpCompress.IO long pos = this.Position; switch (origin) { - case SeekOrigin.Begin: pos = offset; break; - case SeekOrigin.Current: pos += offset; break; - case SeekOrigin.End: pos = Length + offset; break; + case SeekOrigin.Begin: + pos = offset; + break; + case SeekOrigin.Current: + pos += offset; + break; + case SeekOrigin.End: + pos = Length + offset; + break; } _prevSize = 0; diff --git a/src/SharpCompress/Lazy.cs b/src/SharpCompress/Lazy.cs index eab72849..3ddd47d2 100644 --- a/src/SharpCompress/Lazy.cs +++ b/src/SharpCompress/Lazy.cs @@ -28,4 +28,4 @@ namespace SharpCompress } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Polyfills/StringExtensions.cs b/src/SharpCompress/Polyfills/StringExtensions.cs index e58aff4d..c6283707 100644 --- a/src/SharpCompress/Polyfills/StringExtensions.cs +++ b/src/SharpCompress/Polyfills/StringExtensions.cs @@ -16,4 +16,4 @@ namespace SharpCompress } } -#endif \ No newline at end of file +#endif diff --git a/src/SharpCompress/Readers/AbstractReader.cs b/src/SharpCompress/Readers/AbstractReader.cs index 619d834e..f8d91ca1 100644 --- a/src/SharpCompress/Readers/AbstractReader.cs +++ b/src/SharpCompress/Readers/AbstractReader.cs @@ -99,9 +99,11 @@ namespace SharpCompress.Readers entriesForCurrentReadStream?.Dispose(); if ((stream is null) || (!stream.CanRead)) { - throw new MultipartStreamRequiredException("File is split into multiple archives: '" - + Entry.Key + - "'. A new readable stream is required. Use Cancel if it was intended."); + throw new MultipartStreamRequiredException( + "File is split into multiple archives: '" + + Entry.Key + + "'. A new readable stream is required. Use Cancel if it was intended." + ); } entriesForCurrentReadStream = GetEntries(stream).GetEnumerator(); return entriesForCurrentReadStream.MoveNext(); @@ -133,9 +135,7 @@ namespace SharpCompress.Readers { var part = Entry.Parts.First(); - if (ArchiveType != ArchiveType.Rar - && !Entry.IsSolid - && Entry.CompressedSize > 0) + if (ArchiveType != ArchiveType.Rar && !Entry.IsSolid && Entry.CompressedSize > 0) { //not solid and has a known compressed size then we can skip raw bytes. var rawStream = part.GetRawStream(); @@ -159,7 +159,9 @@ namespace SharpCompress.Readers { if (wroteCurrentEntry) { - throw new ArgumentException("WriteEntryTo or OpenEntryStream can only be called once."); + throw new ArgumentException( + "WriteEntryTo or OpenEntryStream can only be called once." + ); } if (writableStream is null) @@ -168,7 +170,9 @@ namespace SharpCompress.Readers } if (!writableStream.CanWrite) { - throw new ArgumentException("A writable Stream was required. Use Cancel if that was intended."); + throw new ArgumentException( + "A writable Stream was required. Use Cancel if that was intended." + ); } Write(writableStream); @@ -188,7 +192,9 @@ namespace SharpCompress.Readers { if (wroteCurrentEntry) { - throw new ArgumentException("WriteEntryTo or OpenEntryStream can only be called once."); + throw new ArgumentException( + "WriteEntryTo or OpenEntryStream can only be called once." + ); } var stream = GetEntryStream(); wroteCurrentEntry = true; @@ -212,26 +218,49 @@ namespace SharpCompress.Readers IEntry IReader.Entry => Entry; - void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes) + void IExtractionListener.FireCompressedBytesRead( + long currentPartCompressedBytes, + long compressedReadBytes + ) { - CompressedBytesRead?.Invoke(this, new CompressedBytesReadEventArgs( - currentFilePartCompressedBytesRead: currentPartCompressedBytes, - compressedBytesRead: compressedReadBytes - )); + CompressedBytesRead?.Invoke( + this, + new CompressedBytesReadEventArgs( + currentFilePartCompressedBytesRead: currentPartCompressedBytes, + compressedBytesRead: compressedReadBytes + ) + ); } - void IExtractionListener.FireFilePartExtractionBegin(string name, long size, long compressedSize) + void IExtractionListener.FireFilePartExtractionBegin( + string name, + long size, + long compressedSize + ) { - FilePartExtractionBegin?.Invoke(this, new FilePartExtractionBeginEventArgs( - compressedSize: compressedSize, - size: size, - name: name - )); + FilePartExtractionBegin?.Invoke( + this, + new FilePartExtractionBeginEventArgs( + compressedSize: compressedSize, + size: size, + name: name + ) + ); } - void IReaderExtractionListener.FireEntryExtractionProgress(Entry entry, long bytesTransferred, int iterations) + void IReaderExtractionListener.FireEntryExtractionProgress( + Entry entry, + long bytesTransferred, + int iterations + ) { - EntryExtractionProgress?.Invoke(this, new ReaderExtractionEventArgs(entry, new ReaderProgress(entry, bytesTransferred, iterations))); + EntryExtractionProgress?.Invoke( + this, + new ReaderExtractionEventArgs( + entry, + new ReaderProgress(entry, bytesTransferred, iterations) + ) + ); } } } diff --git a/src/SharpCompress/Readers/GZip/GZipReader.cs b/src/SharpCompress/Readers/GZip/GZipReader.cs index f4b889d0..d9a823f0 100644 --- a/src/SharpCompress/Readers/GZip/GZipReader.cs +++ b/src/SharpCompress/Readers/GZip/GZipReader.cs @@ -7,8 +7,7 @@ namespace SharpCompress.Readers.GZip { public class GZipReader : AbstractReader { - internal GZipReader(Stream stream, ReaderOptions options) - : base(options, ArchiveType.GZip) + internal GZipReader(Stream stream, ReaderOptions options) : base(options, ArchiveType.GZip) { Volume = new GZipVolume(stream, options); } diff --git a/src/SharpCompress/Readers/IReader.cs b/src/SharpCompress/Readers/IReader.cs index db11164d..a4beaa80 100644 --- a/src/SharpCompress/Readers/IReader.cs +++ b/src/SharpCompress/Readers/IReader.cs @@ -36,4 +36,4 @@ namespace SharpCompress.Readers /// EntryStream OpenEntryStream(); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/IReaderExtensions.cs b/src/SharpCompress/Readers/IReaderExtensions.cs index 502fc8ad..29f11ef1 100644 --- a/src/SharpCompress/Readers/IReaderExtensions.cs +++ b/src/SharpCompress/Readers/IReaderExtensions.cs @@ -24,8 +24,11 @@ namespace SharpCompress.Readers /// /// Extract all remaining unread entries to specific directory, retaining filename /// - public static void WriteAllToDirectory(this IReader reader, string destinationDirectory, - ExtractionOptions? options = null) + public static void WriteAllToDirectory( + this IReader reader, + string destinationDirectory, + ExtractionOptions? options = null + ) { while (reader.MoveToNextEntry()) { @@ -36,28 +39,41 @@ namespace SharpCompress.Readers /// /// Extract to specific directory, retaining filename /// - public static void WriteEntryToDirectory(this IReader reader, string destinationDirectory, - ExtractionOptions? options = null) + public static void WriteEntryToDirectory( + this IReader reader, + string destinationDirectory, + ExtractionOptions? options = null + ) { - ExtractionMethods.WriteEntryToDirectory(reader.Entry, destinationDirectory, options, - reader.WriteEntryToFile); + ExtractionMethods.WriteEntryToDirectory( + reader.Entry, + destinationDirectory, + options, + reader.WriteEntryToFile + ); } /// /// Extract to specific file /// - public static void WriteEntryToFile(this IReader reader, - string destinationFileName, - ExtractionOptions? options = null) + public static void WriteEntryToFile( + this IReader reader, + string destinationFileName, + ExtractionOptions? options = null + ) { - ExtractionMethods.WriteEntryToFile(reader.Entry, destinationFileName, options, - (x, fm) => - { - using (FileStream fs = File.Open(destinationFileName, fm)) - { - reader.WriteEntryTo(fs); - } - }); + ExtractionMethods.WriteEntryToFile( + reader.Entry, + destinationFileName, + options, + (x, fm) => + { + using (FileStream fs = File.Open(destinationFileName, fm)) + { + reader.WriteEntryTo(fs); + } + } + ); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/IReaderFactory.cs b/src/SharpCompress/Readers/IReaderFactory.cs index 1f6f7408..4587cca6 100644 --- a/src/SharpCompress/Readers/IReaderFactory.cs +++ b/src/SharpCompress/Readers/IReaderFactory.cs @@ -20,4 +20,3 @@ namespace SharpCompress.Readers IReader OpenReader(Stream stream, ReaderOptions? options); } } - diff --git a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs index 6de11a24..4e857626 100644 --- a/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs +++ b/src/SharpCompress/Readers/Rar/MultiVolumeRarReader.cs @@ -20,9 +20,7 @@ namespace SharpCompress.Readers.Rar this.streams = streams.GetEnumerator(); } - internal override void ValidateArchive(RarVolume archive) - { - } + internal override void ValidateArchive(RarVolume archive) { } protected override Stream RequestInitialStream() { @@ -30,7 +28,9 @@ namespace SharpCompress.Readers.Rar { return streams.Current; } - throw new MultiVolumeExtractionException("No stream provided when requested by MultiVolumeRarReader"); + throw new MultiVolumeExtractionException( + "No stream provided when requested by MultiVolumeRarReader" + ); } internal override bool NextEntryForCurrentStream() @@ -57,8 +57,11 @@ namespace SharpCompress.Readers.Rar private Stream tempStream; private bool isFirst = true; - internal MultiVolumeStreamEnumerator(MultiVolumeRarReader r, IEnumerator nextReadableStreams, - Stream tempStream) + internal MultiVolumeStreamEnumerator( + MultiVolumeRarReader r, + IEnumerator nextReadableStreams, + Stream tempStream + ) { reader = r; this.nextReadableStreams = nextReadableStreams; @@ -77,9 +80,7 @@ namespace SharpCompress.Readers.Rar public FilePart Current { get; private set; } - public void Dispose() - { - } + public void Dispose() { } object IEnumerator.Current => Current; @@ -103,7 +104,9 @@ namespace SharpCompress.Readers.Rar } else if (!nextReadableStreams.MoveNext()) { - throw new MultiVolumeExtractionException("No stream provided when requested by MultiVolumeRarReader"); + throw new MultiVolumeExtractionException( + "No stream provided when requested by MultiVolumeRarReader" + ); } else { @@ -114,9 +117,7 @@ namespace SharpCompress.Readers.Rar return true; } - public void Reset() - { - } + public void Reset() { } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs index 76c9f201..5c545540 100644 --- a/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs +++ b/src/SharpCompress/Readers/Rar/NonSeekableStreamFilePart.cs @@ -7,15 +7,14 @@ namespace SharpCompress.Readers.Rar internal class NonSeekableStreamFilePart : RarFilePart { internal NonSeekableStreamFilePart(MarkHeader mh, FileHeader fh, int index = 0) - : base(mh, fh, index) - { - } + : base(mh, fh, index) { } internal override Stream GetCompressedStream() { return FileHeader.PackedStream; } - internal override string FilePartName => "Unknown Stream - File Entry: " + FileHeader.FileName; + internal override string FilePartName => + "Unknown Stream - File Entry: " + FileHeader.FileName; } } diff --git a/src/SharpCompress/Readers/Rar/RarReader.cs b/src/SharpCompress/Readers/Rar/RarReader.cs index c51534bc..32bf4124 100644 --- a/src/SharpCompress/Readers/Rar/RarReader.cs +++ b/src/SharpCompress/Readers/Rar/RarReader.cs @@ -13,13 +13,12 @@ namespace SharpCompress.Readers.Rar public abstract class RarReader : AbstractReader { private RarVolume? volume; - internal Lazy UnpackV2017 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); - internal Lazy UnpackV1 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); + internal Lazy UnpackV2017 { get; } = + new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); + internal Lazy UnpackV1 { get; } = + new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); - internal RarReader(ReaderOptions options) - : base(options, ArchiveType.Rar) - { - } + internal RarReader(ReaderOptions options) : base(options, ArchiveType.Rar) { } internal abstract void ValidateArchive(RarVolume archive); @@ -66,10 +65,15 @@ namespace SharpCompress.Readers.Rar protected override EntryStream GetEntryStream() { - var stream = new MultiVolumeReadOnlyStream(CreateFilePartEnumerableForCurrentEntry().Cast(), this); + var stream = new MultiVolumeReadOnlyStream( + CreateFilePartEnumerableForCurrentEntry().Cast(), + this + ); if (Entry.IsRarV3) { - return CreateEntryStream(new RarCrcStream(UnpackV1.Value, Entry.FileHeader, stream)); + return CreateEntryStream( + new RarCrcStream(UnpackV1.Value, Entry.FileHeader, stream) + ); } return CreateEntryStream(new RarCrcStream(UnpackV2017.Value, Entry.FileHeader, stream)); } diff --git a/src/SharpCompress/Readers/Rar/RarReaderEntry.cs b/src/SharpCompress/Readers/Rar/RarReaderEntry.cs index 2e29d615..7a67392e 100644 --- a/src/SharpCompress/Readers/Rar/RarReaderEntry.cs +++ b/src/SharpCompress/Readers/Rar/RarReaderEntry.cs @@ -31,4 +31,4 @@ namespace SharpCompress.Readers.Rar /// public override long Size => Part.FileHeader.UncompressedSize; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/Rar/RarReaderVolume.cs b/src/SharpCompress/Readers/Rar/RarReaderVolume.cs index fa3bbdf1..61e73ecb 100644 --- a/src/SharpCompress/Readers/Rar/RarReaderVolume.cs +++ b/src/SharpCompress/Readers/Rar/RarReaderVolume.cs @@ -9,9 +9,7 @@ namespace SharpCompress.Readers.Rar public class RarReaderVolume : RarVolume { internal RarReaderVolume(Stream stream, ReaderOptions options, int index = 0) - : base(StreamingMode.Streaming, stream, options, index) - { - } + : base(StreamingMode.Streaming, stream, options, index) { } internal override RarFilePart CreateFilePart(MarkHeader markHeader, FileHeader fileHeader) { diff --git a/src/SharpCompress/Readers/Rar/SingleVolumeRarReader.cs b/src/SharpCompress/Readers/Rar/SingleVolumeRarReader.cs index 4d3cf411..45bf884b 100644 --- a/src/SharpCompress/Readers/Rar/SingleVolumeRarReader.cs +++ b/src/SharpCompress/Readers/Rar/SingleVolumeRarReader.cs @@ -8,8 +8,7 @@ namespace SharpCompress.Readers.Rar { private readonly Stream stream; - internal SingleVolumeRarReader(Stream stream, ReaderOptions options) - : base(options) + internal SingleVolumeRarReader(Stream stream, ReaderOptions options) : base(options) { this.stream = stream; } @@ -18,7 +17,8 @@ namespace SharpCompress.Readers.Rar { if (archive.IsMultiVolume) { - var msg = "Streamed archive is a Multi-volume archive. Use different RarReader method to extract."; + var msg = + "Streamed archive is a Multi-volume archive. Use different RarReader method to extract."; throw new MultiVolumeExtractionException(msg); } } @@ -28,4 +28,4 @@ namespace SharpCompress.Readers.Rar return stream; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/ReaderFactory.cs b/src/SharpCompress/Readers/ReaderFactory.cs index 5f75ed0d..d7e58f68 100644 --- a/src/SharpCompress/Readers/ReaderFactory.cs +++ b/src/SharpCompress/Readers/ReaderFactory.cs @@ -18,20 +18,23 @@ namespace SharpCompress.Readers public static IReader Open(Stream stream, ReaderOptions? options = null) { stream.CheckNotNull(nameof(stream)); - options = options ?? new ReaderOptions() - { - LeaveStreamOpen = false - }; + options = options ?? new ReaderOptions() { LeaveStreamOpen = false }; RewindableStream rewindableStream = new RewindableStream(stream); rewindableStream.StartRecording(); - foreach(var factory in Factories.Factory.Factories.OfType()) + foreach (var factory in Factories.Factory.Factories.OfType()) { - if (factory.TryOpenReader(rewindableStream, options, out var reader) && reader != null) return reader; - } + if ( + factory.TryOpenReader(rewindableStream, options, out var reader) + && reader != null + ) + return reader; + } - throw new InvalidOperationException("Cannot determine compressed stream type. Supported Reader Formats: Zip, GZip, BZip2, Tar, Rar, LZip, XZ"); + throw new InvalidOperationException( + "Cannot determine compressed stream type. Supported Reader Formats: Zip, GZip, BZip2, Tar, Rar, LZip, XZ" + ); } } } diff --git a/src/SharpCompress/Readers/ReaderOptions.cs b/src/SharpCompress/Readers/ReaderOptions.cs index 110b0c33..3891781d 100644 --- a/src/SharpCompress/Readers/ReaderOptions.cs +++ b/src/SharpCompress/Readers/ReaderOptions.cs @@ -13,4 +13,4 @@ namespace SharpCompress.Readers public bool DisableCheckIncomplete { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Readers/ReaderProgress.cs b/src/SharpCompress/Readers/ReaderProgress.cs index 7b6f099d..794929dd 100644 --- a/src/SharpCompress/Readers/ReaderProgress.cs +++ b/src/SharpCompress/Readers/ReaderProgress.cs @@ -1,6 +1,4 @@ - - -using System; +using System; using SharpCompress.Common; namespace SharpCompress.Readers diff --git a/src/SharpCompress/Readers/Tar/TarReader.cs b/src/SharpCompress/Readers/Tar/TarReader.cs index a2b7ecc7..707c2e58 100644 --- a/src/SharpCompress/Readers/Tar/TarReader.cs +++ b/src/SharpCompress/Readers/Tar/TarReader.cs @@ -33,29 +33,29 @@ namespace SharpCompress.Readers.Tar switch (compressionType) { case CompressionType.BZip2: - { - return new BZip2Stream(stream, CompressionMode.Decompress, false); - } + { + return new BZip2Stream(stream, CompressionMode.Decompress, false); + } case CompressionType.GZip: - { - return new GZipStream(stream, CompressionMode.Decompress); - } + { + return new GZipStream(stream, CompressionMode.Decompress); + } case CompressionType.LZip: - { - return new LZipStream(stream, CompressionMode.Decompress); - } + { + return new LZipStream(stream, CompressionMode.Decompress); + } case CompressionType.Xz: - { - return new XZStream(stream); - } + { + return new XZStream(stream); + } case CompressionType.None: - { - return stream; - } + { + return stream; + } default: - { - throw new NotSupportedException("Invalid compression type: " + compressionType); - } + { + throw new NotSupportedException("Invalid compression type: " + compressionType); + } } } @@ -76,7 +76,10 @@ namespace SharpCompress.Readers.Tar if (GZipArchive.IsGZipFile(rewindableStream)) { rewindableStream.Rewind(false); - GZipStream testStream = new GZipStream(rewindableStream, CompressionMode.Decompress); + GZipStream testStream = new GZipStream( + rewindableStream, + CompressionMode.Decompress + ); if (TarArchive.IsTarFile(testStream)) { rewindableStream.Rewind(true); @@ -89,7 +92,11 @@ namespace SharpCompress.Readers.Tar if (BZip2Stream.IsBZip2(rewindableStream)) { rewindableStream.Rewind(false); - BZip2Stream testStream = new BZip2Stream(rewindableStream, CompressionMode.Decompress, false); + BZip2Stream testStream = new BZip2Stream( + rewindableStream, + CompressionMode.Decompress, + false + ); if (TarArchive.IsTarFile(testStream)) { rewindableStream.Rewind(true); @@ -102,7 +109,10 @@ namespace SharpCompress.Readers.Tar if (LZipStream.IsLZipFile(rewindableStream)) { rewindableStream.Rewind(false); - LZipStream testStream = new LZipStream(rewindableStream, CompressionMode.Decompress); + LZipStream testStream = new LZipStream( + rewindableStream, + CompressionMode.Decompress + ); if (TarArchive.IsTarFile(testStream)) { rewindableStream.Rewind(true); @@ -118,7 +128,12 @@ namespace SharpCompress.Readers.Tar protected override IEnumerable GetEntries(Stream stream) { - return TarEntry.GetEntries(StreamingMode.Streaming, stream, compressionType, Options.ArchiveEncoding); + return TarEntry.GetEntries( + StreamingMode.Streaming, + stream, + compressionType, + Options.ArchiveEncoding + ); } } } diff --git a/src/SharpCompress/Readers/Zip/ZipReader.cs b/src/SharpCompress/Readers/Zip/ZipReader.cs index 54a759b2..111b3860 100644 --- a/src/SharpCompress/Readers/Zip/ZipReader.cs +++ b/src/SharpCompress/Readers/Zip/ZipReader.cs @@ -10,11 +10,13 @@ namespace SharpCompress.Readers.Zip { private readonly StreamingZipHeaderFactory _headerFactory; - private ZipReader(Stream stream, ReaderOptions options) - : base(options, ArchiveType.Zip) + private ZipReader(Stream stream, ReaderOptions options) : base(options, ArchiveType.Zip) { Volume = new ZipVolume(stream, options); - _headerFactory = new StreamingZipHeaderFactory(options.Password, options.ArchiveEncoding); + _headerFactory = new StreamingZipHeaderFactory( + options.Password, + options.ArchiveEncoding + ); } public override ZipVolume Volume { get; } @@ -44,14 +46,17 @@ namespace SharpCompress.Readers.Zip switch (h.ZipHeaderType) { case ZipHeaderType.LocalEntry: + { - yield return new ZipEntry(new StreamingZipFilePart((LocalEntryHeader)h, stream)); + yield return new ZipEntry( + new StreamingZipFilePart((LocalEntryHeader)h, stream) + ); } break; case ZipHeaderType.DirectoryEnd: - { - yield break; - } + { + yield break; + } } } } diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index 3d6f3c58..ff059ae6 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -69,7 +69,13 @@ namespace SharpCompress } } - public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length) + public static void Copy( + Array sourceArray, + long sourceIndex, + Array destinationArray, + long destinationIndex, + long length + ) { if (sourceIndex > Int32.MaxValue || sourceIndex < Int32.MinValue) { @@ -86,7 +92,13 @@ namespace SharpCompress throw new ArgumentOutOfRangeException(nameof(length)); } - Array.Copy(sourceArray, (int)sourceIndex, destinationArray, (int)destinationIndex, (int)length); + Array.Copy( + sourceArray, + (int)sourceIndex, + destinationArray, + (int)destinationIndex, + (int)length + ); } public static IEnumerable AsEnumerable(this T item) @@ -141,8 +153,7 @@ namespace SharpCompress { break; } - } - while (true); + } while (true); } finally { @@ -155,10 +166,7 @@ namespace SharpCompress byte[] buffer = GetTransferByteArray(); try { - do - { - } - while (source.Read(buffer, 0, buffer.Length) == buffer.Length); + do { } while (source.Read(buffer, 0, buffer.Length) == buffer.Length); } finally { @@ -183,13 +191,12 @@ namespace SharpCompress count++; if (count == array.Length) { - source.Position = source.Position - len + i - array.Length +1; + source.Position = source.Position - len + i - array.Length + 1; return true; } } } - } - while ((len = source.Read(buffer, 0, buffer.Length)) > 0); + } while ((len = source.Read(buffer, 0, buffer.Length)) > 0); } finally { @@ -242,15 +249,18 @@ namespace SharpCompress var localDateTime = dateTime.Value.ToLocalTime(); return (uint)( - (localDateTime.Second / 2) | (localDateTime.Minute << 5) | (localDateTime.Hour << 11) | - (localDateTime.Day << 16) | (localDateTime.Month << 21) | - ((localDateTime.Year - 1980) << 25)); + (localDateTime.Second / 2) + | (localDateTime.Minute << 5) + | (localDateTime.Hour << 11) + | (localDateTime.Day << 16) + | (localDateTime.Month << 21) + | ((localDateTime.Year - 1980) << 25) + ); } public static DateTime DosDateToDateTime(UInt32 iTime) { - return DosDateToDateTime((UInt16)(iTime / 65536), - (UInt16)(iTime % 65536)); + return DosDateToDateTime((UInt16)(iTime / 65536), (UInt16)(iTime % 65536)); } /// @@ -283,7 +293,12 @@ namespace SharpCompress } } - public static long TransferTo(this Stream source, Stream destination, Common.Entry entry, IReaderExtractionListener readerExtractionListener) + public static long TransferTo( + this Stream source, + Stream destination, + Common.Entry entry, + IReaderExtractionListener readerExtractionListener + ) { byte[] array = GetTransferByteArray(); try @@ -357,10 +372,10 @@ namespace SharpCompress /// Return the new UINT32 in the other endianness format public static UInt32 SwapUINT32(UInt32 number) { - return (number >> 24) | - ((number << 8) & 0x00FF0000) | - ((number >> 8) & 0x0000FF00) | - (number << 24); + return (number >> 24) + | ((number << 8) & 0x00FF0000) + | ((number >> 8) & 0x0000FF00) + | (number << 24); } /// diff --git a/src/SharpCompress/Writers/AbstractWriter.cs b/src/SharpCompress/Writers/AbstractWriter.cs index fad9bd1e..0c910f69 100644 --- a/src/SharpCompress/Writers/AbstractWriter.cs +++ b/src/SharpCompress/Writers/AbstractWriter.cs @@ -56,4 +56,4 @@ namespace SharpCompress.Writers } } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Writers/GZip/GZipWriter.cs b/src/SharpCompress/Writers/GZip/GZipWriter.cs index 12e820a2..b7d32ed2 100644 --- a/src/SharpCompress/Writers/GZip/GZipWriter.cs +++ b/src/SharpCompress/Writers/GZip/GZipWriter.cs @@ -18,9 +18,14 @@ namespace SharpCompress.Writers.GZip { destination = NonDisposingStream.Create(destination); } - InitalizeStream(new GZipStream(destination, CompressionMode.Compress, - options?.CompressionLevel ?? CompressionLevel.Default, - WriterOptions.ArchiveEncoding.GetEncoding())); + InitalizeStream( + new GZipStream( + destination, + CompressionMode.Compress, + options?.CompressionLevel ?? CompressionLevel.Default, + WriterOptions.ArchiveEncoding.GetEncoding() + ) + ); } protected override void Dispose(bool isDisposing) diff --git a/src/SharpCompress/Writers/GZip/GZipWriterOptions.cs b/src/SharpCompress/Writers/GZip/GZipWriterOptions.cs index b6966e16..cef2744a 100644 --- a/src/SharpCompress/Writers/GZip/GZipWriterOptions.cs +++ b/src/SharpCompress/Writers/GZip/GZipWriterOptions.cs @@ -5,13 +5,9 @@ namespace SharpCompress.Writers.GZip { public class GZipWriterOptions : WriterOptions { - public GZipWriterOptions() - : base(CompressionType.GZip) - { - } + public GZipWriterOptions() : base(CompressionType.GZip) { } - internal GZipWriterOptions(WriterOptions options) - : base(options.CompressionType) + internal GZipWriterOptions(WriterOptions options) : base(options.CompressionType) { LeaveStreamOpen = options.LeaveStreamOpen; ArchiveEncoding = options.ArchiveEncoding; @@ -25,4 +21,4 @@ namespace SharpCompress.Writers.GZip public CompressionLevel CompressionLevel { get; set; } = CompressionLevel.Default; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Writers/IWriter.cs b/src/SharpCompress/Writers/IWriter.cs index a15225bf..0c8cb5ab 100644 --- a/src/SharpCompress/Writers/IWriter.cs +++ b/src/SharpCompress/Writers/IWriter.cs @@ -9,4 +9,4 @@ namespace SharpCompress.Writers ArchiveType WriterType { get; } void Write(string filename, Stream source, DateTime? modificationTime); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Writers/IWriterExtensions.cs b/src/SharpCompress/Writers/IWriterExtensions.cs index 5fc1c82d..9335c46e 100644 --- a/src/SharpCompress/Writers/IWriterExtensions.cs +++ b/src/SharpCompress/Writers/IWriterExtensions.cs @@ -29,16 +29,23 @@ namespace SharpCompress.Writers writer.Write(entryPath, new FileInfo(source)); } - public static void WriteAll(this IWriter writer, string directory, string searchPattern = "*", SearchOption option = SearchOption.TopDirectoryOnly) + public static void WriteAll( + this IWriter writer, + string directory, + string searchPattern = "*", + SearchOption option = SearchOption.TopDirectoryOnly + ) { writer.WriteAll(directory, searchPattern, null, option); } - public static void WriteAll(this IWriter writer, - string directory, - string searchPattern = "*", - Func? fileSearchFunc = null, - SearchOption option = SearchOption.TopDirectoryOnly) + public static void WriteAll( + this IWriter writer, + string directory, + string searchPattern = "*", + Func? fileSearchFunc = null, + SearchOption option = SearchOption.TopDirectoryOnly + ) { if (!Directory.Exists(directory)) { @@ -49,7 +56,11 @@ namespace SharpCompress.Writers { fileSearchFunc = n => true; } - foreach (var file in Directory.EnumerateFiles(directory, searchPattern, option).Where(fileSearchFunc)) + foreach ( + var file in Directory + .EnumerateFiles(directory, searchPattern, option) + .Where(fileSearchFunc) + ) { writer.Write(file.Substring(directory.Length), file); } diff --git a/src/SharpCompress/Writers/Tar/TarWriter.cs b/src/SharpCompress/Writers/Tar/TarWriter.cs index c90e069e..b6b4da5c 100644 --- a/src/SharpCompress/Writers/Tar/TarWriter.cs +++ b/src/SharpCompress/Writers/Tar/TarWriter.cs @@ -32,24 +32,29 @@ namespace SharpCompress.Writers.Tar case CompressionType.None: break; case CompressionType.BZip2: + { destination = new BZip2Stream(destination, CompressionMode.Compress, false); } break; case CompressionType.GZip: + { destination = new GZipStream(destination, CompressionMode.Compress); } break; case CompressionType.LZip: + { destination = new LZipStream(destination, CompressionMode.Compress); } break; default: - { - throw new InvalidFormatException("Tar does not support compression: " + options.CompressionType); - } + { + throw new InvalidFormatException( + "Tar does not support compression: " + options.CompressionType + ); + } } InitalizeStream(destination); } @@ -110,15 +115,15 @@ namespace SharpCompress.Writers.Tar switch (OutputStream) { case BZip2Stream b: - { - b.Finish(); - break; - } + { + b.Finish(); + break; + } case LZipStream l: - { - l.Finish(); - break; - } + { + l.Finish(); + break; + } } } base.Dispose(isDisposing); diff --git a/src/SharpCompress/Writers/Tar/TarWriterOptions.cs b/src/SharpCompress/Writers/Tar/TarWriterOptions.cs index 752d95cb..f3cc26db 100755 --- a/src/SharpCompress/Writers/Tar/TarWriterOptions.cs +++ b/src/SharpCompress/Writers/Tar/TarWriterOptions.cs @@ -20,4 +20,4 @@ namespace SharpCompress.Writers.Tar ArchiveEncoding = options.ArchiveEncoding; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Writers/WriterFactory.cs b/src/SharpCompress/Writers/WriterFactory.cs index 60aa613c..cd7102c5 100644 --- a/src/SharpCompress/Writers/WriterFactory.cs +++ b/src/SharpCompress/Writers/WriterFactory.cs @@ -8,10 +8,13 @@ namespace SharpCompress.Writers { public static class WriterFactory { - public static IWriter Open(Stream stream, ArchiveType archiveType, WriterOptions writerOptions) + public static IWriter Open( + Stream stream, + ArchiveType archiveType, + WriterOptions writerOptions + ) { - var factory = Factories.Factory - .Factories + var factory = Factories.Factory.Factories .OfType() .FirstOrDefault(item => item.KnownArchiveType == archiveType); diff --git a/src/SharpCompress/Writers/WriterOptions.cs b/src/SharpCompress/Writers/WriterOptions.cs index db1e2ffa..db3b83c7 100644 --- a/src/SharpCompress/Writers/WriterOptions.cs +++ b/src/SharpCompress/Writers/WriterOptions.cs @@ -8,6 +8,7 @@ namespace SharpCompress.Writers { CompressionType = compressionType; } + public CompressionType CompressionType { get; set; } public static implicit operator WriterOptions(CompressionType compressionType) @@ -15,4 +16,4 @@ namespace SharpCompress.Writers return new WriterOptions(compressionType); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs index d4609ef6..de54e622 100644 --- a/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs +++ b/src/SharpCompress/Writers/Zip/ZipCentralDirectoryEntry.cs @@ -14,7 +14,12 @@ namespace SharpCompress.Writers.Zip private readonly string fileName; private readonly ArchiveEncoding archiveEncoding; - public ZipCentralDirectoryEntry(ZipCompressionMethod compression, string fileName, ulong headerOffset, ArchiveEncoding archiveEncoding) + public ZipCentralDirectoryEntry( + ZipCompressionMethod compression, + string fileName, + ulong headerOffset, + ArchiveEncoding archiveEncoding + ) { this.compression = compression; this.fileName = fileName; @@ -45,7 +50,9 @@ 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: @@ -143,8 +150,26 @@ namespace SharpCompress.Writers.Zip outputStream.Write(encodedComment, 0, encodedComment.Length); - return (uint)(8 + 2 + 2 + 4 + 4 + 4 + 4 + 2 + 2 + 2 - + 2 + 2 + 2 + 2 + 4 + encodedFilename.Length + extralength + encodedComment.Length); + return (uint)( + 8 + + 2 + + 2 + + 4 + + 4 + + 4 + + 4 + + 2 + + 2 + + 2 + + 2 + + 2 + + 2 + + 2 + + 4 + + encodedFilename.Length + + extralength + + encodedComment.Length + ); } } } diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index 7ee74e19..fb04e7a4 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -19,7 +19,8 @@ namespace SharpCompress.Writers.Zip { private readonly CompressionType compressionType; private readonly CompressionLevel compressionLevel; - private readonly List entries = new List(); + private readonly List entries = + new List(); private readonly string zipComment; private long streamPosition; private PpmdProperties? ppmdProps; @@ -47,10 +48,7 @@ namespace SharpCompress.Writers.Zip private PpmdProperties PpmdProperties { - get - { - return ppmdProps ??= new PpmdProperties(); - } + get { return ppmdProps ??= new PpmdProperties(); } } protected override void Dispose(bool isDisposing) @@ -72,39 +70,46 @@ namespace SharpCompress.Writers.Zip switch (compressionType) { case CompressionType.None: - { - return ZipCompressionMethod.None; - } + { + return ZipCompressionMethod.None; + } case CompressionType.Deflate: - { - return ZipCompressionMethod.Deflate; - } + { + return ZipCompressionMethod.Deflate; + } case CompressionType.BZip2: - { - return ZipCompressionMethod.BZip2; - } + { + return ZipCompressionMethod.BZip2; + } case CompressionType.LZMA: - { - return ZipCompressionMethod.LZMA; - } + { + return ZipCompressionMethod.LZMA; + } case CompressionType.PPMd: - { - return ZipCompressionMethod.PPMd; - } + { + return ZipCompressionMethod.PPMd; + } default: - throw new InvalidFormatException("Invalid compression method: " + compressionType); + throw new InvalidFormatException( + "Invalid compression method: " + compressionType + ); } } public override void Write(string entryPath, Stream source, DateTime? modificationTime) { - Write(entryPath, source, new ZipWriterEntryOptions() - { - ModificationDateTime = modificationTime - }); + Write( + entryPath, + source, + new ZipWriterEntryOptions() { ModificationDateTime = modificationTime } + ); } - public void Write(string entryPath, Stream source, ZipWriterEntryOptions zipWriterEntryOptions) + public void Write( + string entryPath, + Stream source, + ZipWriterEntryOptions zipWriterEntryOptions + ) { using (Stream output = WriteToStream(entryPath, zipWriterEntryOptions)) { @@ -119,7 +124,12 @@ namespace SharpCompress.Writers.Zip entryPath = NormalizeFilename(entryPath); options.ModificationDateTime ??= DateTime.Now; options.EntryComment ??= string.Empty; - var entry = new ZipCentralDirectoryEntry(compression, entryPath, (ulong)streamPosition, WriterOptions.ArchiveEncoding) + var entry = new ZipCentralDirectoryEntry( + compression, + entryPath, + (ulong)streamPosition, + WriterOptions.ArchiveEncoding + ) { Comment = options.EntryComment, ModificationTime = options.ModificationDateTime @@ -134,8 +144,13 @@ namespace SharpCompress.Writers.Zip var headersize = (uint)WriteHeader(entryPath, options, entry, useZip64); streamPosition += headersize; - return new ZipWritingStream(this, OutputStream, entry, compression, - options.DeflateCompressionLevel ?? compressionLevel); + return new ZipWritingStream( + this, + OutputStream, + entry, + compression, + options.DeflateCompressionLevel ?? compressionLevel + ); } private string NormalizeFilename(string filename) @@ -151,15 +166,24 @@ namespace SharpCompress.Writers.Zip return filename.Trim('/'); } - private int WriteHeader(string filename, ZipWriterEntryOptions zipWriterEntryOptions, ZipCentralDirectoryEntry entry, bool useZip64) + private int WriteHeader( + string filename, + ZipWriterEntryOptions zipWriterEntryOptions, + ZipCentralDirectoryEntry entry, + bool useZip64 + ) { // We err on the side of caution until the zip specification clarifies how to support this if (!OutputStream.CanSeek && useZip64) { - throw new NotSupportedException("Zip64 extensions are not supported on non-seekable streams"); + throw new NotSupportedException( + "Zip64 extensions are not supported on non-seekable streams" + ); } - var explicitZipCompressionInfo = ToZipCompressionMethod(zipWriterEntryOptions.CompressionType ?? compressionType); + var explicitZipCompressionInfo = ToZipCompressionMethod( + zipWriterEntryOptions.CompressionType ?? compressionType + ); byte[] encodedFilename = WriterOptions.ArchiveEncoding.Encode(filename); Span intBuf = stackalloc byte[4]; @@ -180,7 +204,9 @@ namespace SharpCompress.Writers.Zip { OutputStream.Write(stackalloc byte[] { 63, 0 }); //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; @@ -195,7 +221,10 @@ namespace SharpCompress.Writers.Zip OutputStream.Write(intBuf.Slice(0, 2)); BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)explicitZipCompressionInfo); OutputStream.Write(intBuf.Slice(0, 2)); // zipping method - BinaryPrimitives.WriteUInt32LittleEndian(intBuf, zipWriterEntryOptions.ModificationDateTime.DateTimeToDosTime()); + BinaryPrimitives.WriteUInt32LittleEndian( + intBuf, + zipWriterEntryOptions.ModificationDateTime.DateTimeToDosTime() + ); OutputStream.Write(intBuf); // zipping date and time @@ -218,7 +247,9 @@ namespace SharpCompress.Writers.Zip if (extralength != 0) { OutputStream.Write(new byte[extralength], 0, extralength); // reserve space for zip64 data - entry.Zip64HeaderOffset = (ushort)(6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length); + entry.Zip64HeaderOffset = (ushort)( + 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length + ); } return 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length + extralength; @@ -237,11 +268,14 @@ namespace SharpCompress.Writers.Zip private void WriteEndRecord(ulong size) { - - var zip64EndOfCentralDirectoryNeeded = entries.Count > ushort.MaxValue || streamPosition >= uint.MaxValue || size >= uint.MaxValue; + var zip64EndOfCentralDirectoryNeeded = + entries.Count > ushort.MaxValue + || streamPosition >= uint.MaxValue + || size >= uint.MaxValue; var sizevalue = size >= uint.MaxValue ? uint.MaxValue : (uint)size; - var streampositionvalue = streamPosition >= uint.MaxValue ? uint.MaxValue : (uint)streamPosition; + var streampositionvalue = + streamPosition >= uint.MaxValue ? uint.MaxValue : (uint)streamPosition; Span intBuf = stackalloc byte[8]; if (zip64EndOfCentralDirectoryNeeded) @@ -317,8 +351,13 @@ namespace SharpCompress.Writers.Zip private bool limitsExceeded; private bool isDisposed; - internal ZipWritingStream(ZipWriter writer, Stream originalStream, ZipCentralDirectoryEntry entry, - ZipCompressionMethod zipCompressionMethod, CompressionLevel compressionLevel) + internal ZipWritingStream( + ZipWriter writer, + Stream originalStream, + ZipCentralDirectoryEntry entry, + ZipCompressionMethod zipCompressionMethod, + CompressionLevel compressionLevel + ) { this.writer = writer; this.originalStream = originalStream; @@ -337,7 +376,11 @@ namespace SharpCompress.Writers.Zip public override long Length => throw new NotSupportedException(); - public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } + public override long Position + { + get => throw new NotSupportedException(); + set => throw new NotSupportedException(); + } private Stream GetWriteStream(Stream writeStream) { @@ -346,38 +389,47 @@ namespace SharpCompress.Writers.Zip switch (zipCompressionMethod) { case ZipCompressionMethod.None: - { - return output; - } + { + return output; + } case ZipCompressionMethod.Deflate: - { - return new DeflateStream(counting, CompressionMode.Compress, compressionLevel); - } + { + return new DeflateStream( + counting, + CompressionMode.Compress, + compressionLevel + ); + } case ZipCompressionMethod.BZip2: - { - return new BZip2Stream(counting, CompressionMode.Compress, false); - } + { + return new BZip2Stream(counting, CompressionMode.Compress, false); + } case ZipCompressionMethod.LZMA: - { - counting.WriteByte(9); - counting.WriteByte(20); - counting.WriteByte(5); - counting.WriteByte(0); + { + counting.WriteByte(9); + counting.WriteByte(20); + counting.WriteByte(5); + counting.WriteByte(0); - LzmaStream lzmaStream = new LzmaStream(new LzmaEncoderProperties(!originalStream.CanSeek), - false, counting); - counting.Write(lzmaStream.Properties, 0, lzmaStream.Properties.Length); - return lzmaStream; - } + LzmaStream lzmaStream = new LzmaStream( + new LzmaEncoderProperties(!originalStream.CanSeek), + false, + counting + ); + counting.Write(lzmaStream.Properties, 0, lzmaStream.Properties.Length); + return lzmaStream; + } case ZipCompressionMethod.PPMd: - { - counting.Write(writer.PpmdProperties.Properties, 0, 2); - return new PpmdStream(writer.PpmdProperties, counting, true); - } + { + counting.Write(writer.PpmdProperties.Properties, 0, 2); + return new PpmdStream(writer.PpmdProperties, counting, true); + } default: - { - throw new NotSupportedException("CompressionMethod: " + zipCompressionMethod); - } + { + throw new NotSupportedException( + "CompressionMethod: " + zipCompressionMethod + ); + } } } @@ -408,7 +460,8 @@ namespace SharpCompress.Writers.Zip entry.Compressed = counting!.Count; entry.Decompressed = decompressed; - var zip64 = entry.Compressed >= uint.MaxValue || entry.Decompressed >= uint.MaxValue; + var zip64 = + entry.Compressed >= uint.MaxValue || entry.Decompressed >= uint.MaxValue; var compressedvalue = zip64 ? uint.MaxValue : (uint)counting.Count; var decompressedvalue = zip64 ? uint.MaxValue : (uint)entry.Decompressed; @@ -433,14 +486,18 @@ namespace SharpCompress.Writers.Zip // We should not get here as the Write call checks the limits if (zip64 && entry.Zip64HeaderOffset == 0) { - throw new NotSupportedException("Attempted to write a stream that is larger than 4GiB without setting the zip64 option"); + throw new NotSupportedException( + "Attempted to write a stream that is larger than 4GiB without setting the zip64 option" + ); } // If we have pre-allocated space for zip64 data, // fill it out, even if it is not required if (entry.Zip64HeaderOffset != 0) { - originalStream.Position = (long)(entry.HeaderOffset + entry.Zip64HeaderOffset); + originalStream.Position = (long)( + entry.HeaderOffset + entry.Zip64HeaderOffset + ); Span intBuf = stackalloc byte[8]; BinaryPrimitives.WriteUInt16LittleEndian(intBuf, 0x0001); originalStream.Write(intBuf.Slice(0, 2)); @@ -466,15 +523,18 @@ namespace SharpCompress.Writers.Zip // We should not get here as the Write call checks the limits if (zip64) { - throw new NotSupportedException("Streams larger than 4GiB are not supported for non-seekable streams"); + throw new NotSupportedException( + "Streams larger than 4GiB are not supported for non-seekable streams" + ); } Span intBuf = stackalloc byte[4]; - BinaryPrimitives.WriteUInt32LittleEndian(intBuf, ZipHeaderFactory.POST_DATA_DESCRIPTOR); + BinaryPrimitives.WriteUInt32LittleEndian( + intBuf, + ZipHeaderFactory.POST_DATA_DESCRIPTOR + ); originalStream.Write(intBuf); - writer.WriteFooter(entry.Crc, - compressedvalue, - decompressedvalue); + writer.WriteFooter(entry.Crc, compressedvalue, decompressedvalue); writer.streamPosition += (long)entry.Compressed + 16; } writer.entries.Add(entry); @@ -508,9 +568,15 @@ namespace SharpCompress.Writers.Zip if (entry.Zip64HeaderOffset == 0) { // Pre-check, the counting.Count is not exact, as we do not know the size before having actually compressed it - if (limitsExceeded || ((decompressed + (uint)count) > uint.MaxValue) || (counting!.Count + (uint)count) > uint.MaxValue) + if ( + limitsExceeded + || ((decompressed + (uint)count) > uint.MaxValue) + || (counting!.Count + (uint)count) > uint.MaxValue + ) { - throw new NotSupportedException("Attempted to write a stream that is larger than 4GiB without setting the zip64 option"); + throw new NotSupportedException( + "Attempted to write a stream that is larger than 4GiB without setting the zip64 option" + ); } } @@ -528,7 +594,9 @@ namespace SharpCompress.Writers.Zip // throwing an exception in Dispose() which is discouraged // as it can mask other errors limitsExceeded = true; - throw new NotSupportedException("Attempted to write a stream that is larger than 4GiB without setting the zip64 option"); + throw new NotSupportedException( + "Attempted to write a stream that is larger than 4GiB without setting the zip64 option" + ); } } } diff --git a/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs b/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs index e1ef77bf..0f4e8886 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriterEntryOptions.cs @@ -7,6 +7,7 @@ namespace SharpCompress.Writers.Zip public class ZipWriterEntryOptions { public CompressionType? CompressionType { get; set; } + /// /// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default. /// @@ -18,10 +19,10 @@ namespace SharpCompress.Writers.Zip /// /// Allocate an extra 20 bytes for this entry to store, - /// 64 bit length values, thus enabling streams - /// larger than 4GiB. - /// This option is not supported with non-seekable streams. + /// 64 bit length values, thus enabling streams + /// larger than 4GiB. + /// This option is not supported with non-seekable streams. /// public bool? EnableZip64 { get; set; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs b/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs index 969e2349..e1758896 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriterOptions.cs @@ -5,13 +5,9 @@ namespace SharpCompress.Writers.Zip { public class ZipWriterOptions : WriterOptions { - public ZipWriterOptions(CompressionType compressionType) - : base(compressionType) - { - } + public ZipWriterOptions(CompressionType compressionType) : base(compressionType) { } - internal ZipWriterOptions(WriterOptions options) - : base(options.CompressionType) + internal ZipWriterOptions(WriterOptions options) : base(options.CompressionType) { LeaveStreamOpen = options.LeaveStreamOpen; ArchiveEncoding = options.ArchiveEncoding; @@ -24,6 +20,7 @@ namespace SharpCompress.Writers.Zip ArchiveComment = writerOptions.ArchiveComment; } } + /// /// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default. /// @@ -32,12 +29,12 @@ namespace SharpCompress.Writers.Zip public string? ArchiveComment { get; set; } /// - /// Sets a value indicating if zip64 support is enabled. - /// If this is not set, individual stream lengths cannot exceed 4 GiB. - /// This option is not supported for non-seekable streams. - /// Archives larger than 4GiB are supported as long as all streams - /// are less than 4GiB in length. + /// Sets a value indicating if zip64 support is enabled. + /// If this is not set, individual stream lengths cannot exceed 4 GiB. + /// This option is not supported for non-seekable streams. + /// Archives larger than 4GiB are supported as long as all streams + /// are less than 4GiB in length. /// public bool UseZip64 { get; set; } } -} \ No newline at end of file +} diff --git a/tests/SharpCompress.Test/ADCTest.cs b/tests/SharpCompress.Test/ADCTest.cs index 039260c4..4be158d1 100644 --- a/tests/SharpCompress.Test/ADCTest.cs +++ b/tests/SharpCompress.Test/ADCTest.cs @@ -37,12 +37,20 @@ namespace SharpCompress.Test [Fact] public void TestBuffer() { - using (FileStream decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin"))) + using ( + FileStream decFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") + ) + ) { byte[] decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using (FileStream cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin"))) + using ( + FileStream cmpFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") + ) + ) { byte[] compressed = new byte[cmpFs.Length]; cmpFs.Read(compressed, 0, compressed.Length); @@ -58,12 +66,20 @@ namespace SharpCompress.Test [Fact] public void TestBaseStream() { - using (FileStream decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin"))) + using ( + FileStream decFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") + ) + ) { byte[] decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using (FileStream cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin"))) + using ( + FileStream cmpFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") + ) + ) { byte[]? test; @@ -77,12 +93,20 @@ namespace SharpCompress.Test [Fact] public void TestADCStreamWholeChunk() { - using (FileStream decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin"))) + using ( + FileStream decFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") + ) + ) { byte[] decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using (FileStream cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin"))) + using ( + FileStream cmpFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") + ) + ) { using (ADCStream decStream = new ADCStream(cmpFs, CompressionMode.Decompress)) { @@ -99,12 +123,20 @@ namespace SharpCompress.Test [Fact] public void TestADCStream() { - using (FileStream decFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin"))) + using ( + FileStream decFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_decompressed.bin") + ) + ) { byte[] decompressed = new byte[decFs.Length]; decFs.Read(decompressed, 0, decompressed.Length); - using (FileStream cmpFs = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin"))) + using ( + FileStream cmpFs = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "adc_compressed.bin") + ) + ) { using (ADCStream decStream = new ADCStream(cmpFs, CompressionMode.Decompress)) { @@ -117,8 +149,7 @@ namespace SharpCompress.Test { count = decStream.Read(test, 0, test.Length); decMs.Write(test, 0, count); - } - while (count > 0); + } while (count > 0); Assert.Equal(decompressed, decMs.ToArray()); } diff --git a/tests/SharpCompress.Test/ArchiveTests.cs b/tests/SharpCompress.Test/ArchiveTests.cs index d93455c0..dcf033ca 100644 --- a/tests/SharpCompress.Test/ArchiveTests.cs +++ b/tests/SharpCompress.Test/ArchiveTests.cs @@ -27,8 +27,10 @@ namespace SharpCompress.Test ArchiveStreamReadExtractAll(new[] { testArchive }, compression); } - - protected void ArchiveStreamReadExtractAll(IEnumerable testArchives, CompressionType compression) + protected void ArchiveStreamReadExtractAll( + IEnumerable testArchives, + CompressionType compression + ) { foreach (var path in testArchives) { @@ -50,14 +52,18 @@ namespace SharpCompress.Test stream.ThrowOnDispose = false; return; } - foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + foreach ( + var entry in archive.Entries.Where(entry => !entry.IsDirectory) + ) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions + { + ExtractFullPath = true, + Overwrite = true + } + ); } stream.ThrowOnDispose = false; } @@ -79,12 +85,21 @@ namespace SharpCompress.Test ArchiveStreamRead(readerOptions, testArchive); } - protected void ArchiveStreamRead(ReaderOptions? readerOptions = null, params string[] testArchives) + protected void ArchiveStreamRead( + ReaderOptions? readerOptions = null, + params string[] testArchives + ) { - ArchiveStreamRead(readerOptions, testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))); + ArchiveStreamRead( + readerOptions, + testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)) + ); } - protected void ArchiveStreamRead(ReaderOptions? readerOptions, IEnumerable testArchives) + protected void ArchiveStreamRead( + ReaderOptions? readerOptions, + IEnumerable testArchives + ) { foreach (var path in testArchives) { @@ -95,12 +110,10 @@ namespace SharpCompress.Test { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } catch (IndexOutOfRangeException) @@ -115,54 +128,37 @@ namespace SharpCompress.Test } } - protected void ArchiveStreamMultiRead(ReaderOptions? readerOptions = null, params string[] testArchives) + protected void ArchiveStreamMultiRead( + ReaderOptions? readerOptions = null, + params string[] testArchives + ) { - ArchiveStreamMultiRead(readerOptions, testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))); + ArchiveStreamMultiRead( + readerOptions, + testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)) + ); } - protected void ArchiveStreamMultiRead(ReaderOptions? readerOptions, IEnumerable testArchives) + protected void ArchiveStreamMultiRead( + ReaderOptions? readerOptions, + IEnumerable testArchives + ) { - using (var archive = ArchiveFactory.Open(testArchives.Select(a => new FileInfo(a)), readerOptions)) - { - try - { - foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) - { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); - } - } - catch (IndexOutOfRangeException) - { - throw; - } - } - VerifyFiles(); - } - - protected void ArchiveOpenStreamRead(ReaderOptions? readerOptions = null, params string[] testArchives) - { - ArchiveOpenStreamRead(readerOptions, testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))); - } - - protected void ArchiveOpenStreamRead(ReaderOptions? readerOptions, IEnumerable testArchives) - { - using (var archive = ArchiveFactory.Open(testArchives.Select(f => new FileInfo(f)), readerOptions)) + using ( + var archive = ArchiveFactory.Open( + testArchives.Select(a => new FileInfo(a)), + readerOptions + ) + ) { try { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } catch (IndexOutOfRangeException) @@ -173,16 +169,73 @@ namespace SharpCompress.Test VerifyFiles(); } - protected void ArchiveOpenEntryVolumeIndexTest(int[][] results, ReaderOptions? readerOptions = null, params string[] testArchives) + protected void ArchiveOpenStreamRead( + ReaderOptions? readerOptions = null, + params string[] testArchives + ) { - ArchiveOpenEntryVolumeIndexTest(results, readerOptions, testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x))); + ArchiveOpenStreamRead( + readerOptions, + testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)) + ); } + protected void ArchiveOpenStreamRead( + ReaderOptions? readerOptions, + IEnumerable testArchives + ) + { + using ( + var archive = ArchiveFactory.Open( + testArchives.Select(f => new FileInfo(f)), + readerOptions + ) + ) + { + try + { + foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) + { + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); + } + } + catch (IndexOutOfRangeException) + { + throw; + } + } + VerifyFiles(); + } - protected void ArchiveOpenEntryVolumeIndexTest(int[][] results, ReaderOptions? readerOptions, IEnumerable testArchives) + protected void ArchiveOpenEntryVolumeIndexTest( + int[][] results, + ReaderOptions? readerOptions = null, + params string[] testArchives + ) + { + ArchiveOpenEntryVolumeIndexTest( + results, + readerOptions, + testArchives.Select(x => Path.Combine(TEST_ARCHIVES_PATH, x)) + ); + } + + protected void ArchiveOpenEntryVolumeIndexTest( + int[][] results, + ReaderOptions? readerOptions, + IEnumerable testArchives + ) { string[] src = testArchives.ToArray(); - using (var archive = ArchiveFactory.Open(testArchives.Select(f => new FileInfo(f)), readerOptions)) + using ( + var archive = ArchiveFactory.Open( + testArchives.Select(f => new FileInfo(f)), + readerOptions + ) + ) { try { @@ -191,8 +244,14 @@ namespace SharpCompress.Test { Assert.Equal(entry.VolumeIndexFirst, results[idx][0]); Assert.Equal(entry.VolumeIndexLast, results[idx][1]); - Assert.Equal(src[entry.VolumeIndexFirst], archive.Volumes.First(a => a.Index == entry.VolumeIndexFirst).FileName); - Assert.Equal(src[entry.VolumeIndexLast], archive.Volumes.First(a => a.Index == entry.VolumeIndexLast).FileName); + Assert.Equal( + src[entry.VolumeIndexFirst], + archive.Volumes.First(a => a.Index == entry.VolumeIndexFirst).FileName + ); + Assert.Equal( + src[entry.VolumeIndexLast], + archive.Volumes.First(a => a.Index == entry.VolumeIndexLast).FileName + ); idx++; } @@ -204,8 +263,6 @@ namespace SharpCompress.Test } } - - protected void ArchiveFileRead(string testArchive, ReaderOptions? readerOptions = null) { testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive); @@ -213,12 +270,10 @@ namespace SharpCompress.Test { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -234,14 +289,16 @@ namespace SharpCompress.Test { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, + entry.WriteToDirectory( + SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true, PreserveAttributes = true, PreserveFileTime = true - }); + } + ); } } VerifyFilesEx(); diff --git a/tests/SharpCompress.Test/Filters/BranchExecTests.cs b/tests/SharpCompress.Test/Filters/BranchExecTests.cs index 41dea9fd..138012c0 100644 --- a/tests/SharpCompress.Test/Filters/BranchExecTests.cs +++ b/tests/SharpCompress.Test/Filters/BranchExecTests.cs @@ -1,7 +1,7 @@ /* * BranchExecTests.cs -- Test for converters * - * + * * All data is extracted from busybox, where "ip" is the offset within the busybox file. */ @@ -12,87 +12,1177 @@ namespace SharpCompress.Test.Filters { public class BranchExecTests { - private static byte[] x86resultData { get; } = new byte[] { - 0x12, 0x00, 0x00, 0x00, 0x02, 0x0B, 0x00, 0x00, 0xE8, 0xBD, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x6D, 0x01, 0x00, 0x00, 0xF0, 0xCA, - 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0xBC, 0x09, 0x00, 0x00, 0x14, 0xC2, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x98, 0x0B, 0x00, 0x00, 0x60, 0x75, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xF1, 0xFF, 0x42, 0x01, 0x00, 0x00, 0x08, 0xC8, 0x00, 0x00, 0x1C, 0x00, - }; + private static byte[] x86resultData { get; } = + new byte[] + { + 0x12, + 0x00, + 0x00, + 0x00, + 0x02, + 0x0B, + 0x00, + 0x00, + 0xE8, + 0xBD, + 0x00, + 0x00, + 0x00, + 0x07, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x6D, + 0x01, + 0x00, + 0x00, + 0xF0, + 0xCA, + 0x00, + 0x00, + 0x1C, + 0x00, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0xBC, + 0x09, + 0x00, + 0x00, + 0x14, + 0xC2, + 0x00, + 0x00, + 0xE0, + 0x01, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x98, + 0x0B, + 0x00, + 0x00, + 0x60, + 0x75, + 0x0A, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x00, + 0xF1, + 0xFF, + 0x42, + 0x01, + 0x00, + 0x00, + 0x08, + 0xC8, + 0x00, + 0x00, + 0x1C, + 0x00, + }; - private static byte[] x86Data { get; } = new byte[] { - 0x12, 0x00, 0x00, 0x00, 0x02, 0x0B, 0x00, 0x00, 0xE8, 0xCA, 0x20, 0x00, 0x00, 0x07, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x6D, 0x01, 0x00, 0x00, 0xF0, 0xCA, - 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0xBC, 0x09, 0x00, 0x00, 0x14, 0xC2, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, - 0x98, 0x0B, 0x00, 0x00, 0x60, 0x75, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0xF1, 0xFF, 0x42, 0x01, 0x00, 0x00, 0x08, 0xC8, 0x00, 0x00, 0x1C, 0x00, - }; + private static byte[] x86Data { get; } = + new byte[] + { + 0x12, + 0x00, + 0x00, + 0x00, + 0x02, + 0x0B, + 0x00, + 0x00, + 0xE8, + 0xCA, + 0x20, + 0x00, + 0x00, + 0x07, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x6D, + 0x01, + 0x00, + 0x00, + 0xF0, + 0xCA, + 0x00, + 0x00, + 0x1C, + 0x00, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0xBC, + 0x09, + 0x00, + 0x00, + 0x14, + 0xC2, + 0x00, + 0x00, + 0xE0, + 0x01, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x98, + 0x0B, + 0x00, + 0x00, + 0x60, + 0x75, + 0x0A, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x10, + 0x00, + 0xF1, + 0xFF, + 0x42, + 0x01, + 0x00, + 0x00, + 0x08, + 0xC8, + 0x00, + 0x00, + 0x1C, + 0x00, + }; - private static byte[] ppcResultData { get; } = new byte[] { - 0xF8, 0x6B, 0x2E, 0x8C, 0x95, 0xC5, 0x4B, 0x1B, 0x94, 0x78, 0x9E, 0x7C, 0xBD, 0x8B, 0xA8, 0xAF, 0x31, 0x20, 0xFE, 0x0F, 0xB3, 0x15, 0x9A, 0x7C, 0xD5, 0x5C, - 0xC2, 0xC0, 0xEC, 0xE9, 0x43, 0x2B, 0xD0, 0x9F, 0x2C, 0xFC, 0xB8, 0x2B, 0x6B, 0x15, 0xCD, 0x3F, 0x0C, 0xAF, 0x8F, 0x68, 0xB0, 0x6E, 0x6B, 0x30, 0x2E, 0x8C, - 0x3F, 0x7E, 0x96, 0x7C, 0x93, 0xB2, 0xA4, 0x0E, 0x43, 0xEA, 0x20, 0x10, 0x38, 0x6D, 0x37, 0xF8, 0x87, 0xFE, 0xA9, 0x63, 0x75, 0xF5, 0x56, 0x34, 0x4A, 0xE3, - 0xCF, 0x89, 0x18, 0x08, 0xC2, 0x76, 0x74, 0x12, 0xEC, 0xA7, 0x6D, 0xC2, 0xB7, 0x1B, 0x7A, 0xB2, 0xD4, 0xED - }; + private static byte[] ppcResultData { get; } = + new byte[] + { + 0xF8, + 0x6B, + 0x2E, + 0x8C, + 0x95, + 0xC5, + 0x4B, + 0x1B, + 0x94, + 0x78, + 0x9E, + 0x7C, + 0xBD, + 0x8B, + 0xA8, + 0xAF, + 0x31, + 0x20, + 0xFE, + 0x0F, + 0xB3, + 0x15, + 0x9A, + 0x7C, + 0xD5, + 0x5C, + 0xC2, + 0xC0, + 0xEC, + 0xE9, + 0x43, + 0x2B, + 0xD0, + 0x9F, + 0x2C, + 0xFC, + 0xB8, + 0x2B, + 0x6B, + 0x15, + 0xCD, + 0x3F, + 0x0C, + 0xAF, + 0x8F, + 0x68, + 0xB0, + 0x6E, + 0x6B, + 0x30, + 0x2E, + 0x8C, + 0x3F, + 0x7E, + 0x96, + 0x7C, + 0x93, + 0xB2, + 0xA4, + 0x0E, + 0x43, + 0xEA, + 0x20, + 0x10, + 0x38, + 0x6D, + 0x37, + 0xF8, + 0x87, + 0xFE, + 0xA9, + 0x63, + 0x75, + 0xF5, + 0x56, + 0x34, + 0x4A, + 0xE3, + 0xCF, + 0x89, + 0x18, + 0x08, + 0xC2, + 0x76, + 0x74, + 0x12, + 0xEC, + 0xA7, + 0x6D, + 0xC2, + 0xB7, + 0x1B, + 0x7A, + 0xB2, + 0xD4, + 0xED + }; - private static byte[] ppcData { get; } = new byte[] { - 0xF8, 0x6B, 0x2E, 0x8C, 0x95, 0xC5, 0x4B, 0x1B, 0x94, 0x78, 0x9E, 0x7C, 0xBD, 0x8B, 0xA8, 0xAF, 0x31, 0x20, 0xFE, 0x0F, 0xB3, 0x15, 0x9A, 0x7C, 0xD5, 0x5C, - 0xC2, 0xC0, 0xEC, 0xE9, 0x43, 0x2B, 0xD0, 0x9F, 0x2C, 0xFC, 0xB8, 0x2B, 0x6B, 0x15, 0xCD, 0x3F, 0x0C, 0xAF, 0x8F, 0x68, 0xB0, 0x6E, 0x6B, 0x30, 0x2E, 0x8C, - 0x3F, 0x7E, 0x96, 0x7C, 0x93, 0xB2, 0xA4, 0x0E, 0x43, 0xEA, 0x20, 0x10, 0x38, 0x6D, 0x37, 0xF8, 0x87, 0xFE, 0xA9, 0x63, 0x75, 0xF5, 0x56, 0x34, 0x4A, 0xE3, - 0xD6, 0x75, 0x18, 0x08, 0xC2, 0x76, 0x74, 0x12, 0xEC, 0xA7, 0x6D, 0xC2, 0xB7, 0x1B, 0x7A, 0xB2, 0xD4, 0xED - }; + private static byte[] ppcData { get; } = + new byte[] + { + 0xF8, + 0x6B, + 0x2E, + 0x8C, + 0x95, + 0xC5, + 0x4B, + 0x1B, + 0x94, + 0x78, + 0x9E, + 0x7C, + 0xBD, + 0x8B, + 0xA8, + 0xAF, + 0x31, + 0x20, + 0xFE, + 0x0F, + 0xB3, + 0x15, + 0x9A, + 0x7C, + 0xD5, + 0x5C, + 0xC2, + 0xC0, + 0xEC, + 0xE9, + 0x43, + 0x2B, + 0xD0, + 0x9F, + 0x2C, + 0xFC, + 0xB8, + 0x2B, + 0x6B, + 0x15, + 0xCD, + 0x3F, + 0x0C, + 0xAF, + 0x8F, + 0x68, + 0xB0, + 0x6E, + 0x6B, + 0x30, + 0x2E, + 0x8C, + 0x3F, + 0x7E, + 0x96, + 0x7C, + 0x93, + 0xB2, + 0xA4, + 0x0E, + 0x43, + 0xEA, + 0x20, + 0x10, + 0x38, + 0x6D, + 0x37, + 0xF8, + 0x87, + 0xFE, + 0xA9, + 0x63, + 0x75, + 0xF5, + 0x56, + 0x34, + 0x4A, + 0xE3, + 0xD6, + 0x75, + 0x18, + 0x08, + 0xC2, + 0x76, + 0x74, + 0x12, + 0xEC, + 0xA7, + 0x6D, + 0xC2, + 0xB7, + 0x1B, + 0x7A, + 0xB2, + 0xD4, + 0xED + }; - private static byte[] armResultData { get; } = new byte[] { - 0x7C, 0xFC, 0x0A, 0x00, 0x16, 0x42, 0x01, 0x00, 0x80, 0xFC, 0x0A, 0x00, 0x16, 0xB8, 0x00, 0x00, 0x84, 0xFC, 0x0A, 0x00, 0x16, 0x3A, 0x00, 0x00, 0x04, 0xE0, - 0x2D, 0xE5, 0x04, 0xD0, 0x4D, 0xE2, 0x0E, 0x04, 0x00, 0xEB, 0x04, 0xD0, 0x8D, 0xE2, 0x04, 0xE0, 0x9D, 0xE4, 0x1E, 0xFF, 0x2F, 0xE1, 0x04, 0xE0, 0x2D, 0xE5, - 0x04, 0xE0, 0x9F, 0xE5, 0x0E, 0xE0, 0x8F, 0xE0, 0x08, 0xF0, 0xBE, 0xE5, 0xF0, 0x3A, 0x0A, 0x00, 0x00, 0xC6, 0x8F, 0xE2, 0xA3, 0xCA, 0x8C, 0xE2, 0xF0, 0xFA, - 0xBC, 0xE5, 0x00, 0xC6, 0x8F, 0xE2, 0xA3, 0xCA, 0x8C, 0xE2, 0xE8, 0xFA, 0xBC, 0xE5, 0x00, 0xC6, 0x8F, 0xE2 - }; + private static byte[] armResultData { get; } = + new byte[] + { + 0x7C, + 0xFC, + 0x0A, + 0x00, + 0x16, + 0x42, + 0x01, + 0x00, + 0x80, + 0xFC, + 0x0A, + 0x00, + 0x16, + 0xB8, + 0x00, + 0x00, + 0x84, + 0xFC, + 0x0A, + 0x00, + 0x16, + 0x3A, + 0x00, + 0x00, + 0x04, + 0xE0, + 0x2D, + 0xE5, + 0x04, + 0xD0, + 0x4D, + 0xE2, + 0x0E, + 0x04, + 0x00, + 0xEB, + 0x04, + 0xD0, + 0x8D, + 0xE2, + 0x04, + 0xE0, + 0x9D, + 0xE4, + 0x1E, + 0xFF, + 0x2F, + 0xE1, + 0x04, + 0xE0, + 0x2D, + 0xE5, + 0x04, + 0xE0, + 0x9F, + 0xE5, + 0x0E, + 0xE0, + 0x8F, + 0xE0, + 0x08, + 0xF0, + 0xBE, + 0xE5, + 0xF0, + 0x3A, + 0x0A, + 0x00, + 0x00, + 0xC6, + 0x8F, + 0xE2, + 0xA3, + 0xCA, + 0x8C, + 0xE2, + 0xF0, + 0xFA, + 0xBC, + 0xE5, + 0x00, + 0xC6, + 0x8F, + 0xE2, + 0xA3, + 0xCA, + 0x8C, + 0xE2, + 0xE8, + 0xFA, + 0xBC, + 0xE5, + 0x00, + 0xC6, + 0x8F, + 0xE2 + }; - private static byte[] armData { get; } = new byte[] { - 0x7C, 0xFC, 0x0A, 0x00, 0x16, 0x42, 0x01, 0x00, 0x80, 0xFC, 0x0A, 0x00, 0x16, 0xB8, 0x00, 0x00, 0x84, 0xFC, 0x0A, 0x00, 0x16, 0x3A, 0x00, 0x00, 0x04, 0xE0, - 0x2D, 0xE5, 0x04, 0xD0, 0x4D, 0xE2, 0x18, 0x13, 0x00, 0xEB, 0x04, 0xD0, 0x8D, 0xE2, 0x04, 0xE0, 0x9D, 0xE4, 0x1E, 0xFF, 0x2F, 0xE1, 0x04, 0xE0, 0x2D, 0xE5, - 0x04, 0xE0, 0x9F, 0xE5, 0x0E, 0xE0, 0x8F, 0xE0, 0x08, 0xF0, 0xBE, 0xE5, 0xF0, 0x3A, 0x0A, 0x00, 0x00, 0xC6, 0x8F, 0xE2, 0xA3, 0xCA, 0x8C, 0xE2, 0xF0, 0xFA, - 0xBC, 0xE5, 0x00, 0xC6, 0x8F, 0xE2, 0xA3, 0xCA, 0x8C, 0xE2, 0xE8, 0xFA, 0xBC, 0xE5, 0x00, 0xC6, 0x8F, 0xE2 - }; + private static byte[] armData { get; } = + new byte[] + { + 0x7C, + 0xFC, + 0x0A, + 0x00, + 0x16, + 0x42, + 0x01, + 0x00, + 0x80, + 0xFC, + 0x0A, + 0x00, + 0x16, + 0xB8, + 0x00, + 0x00, + 0x84, + 0xFC, + 0x0A, + 0x00, + 0x16, + 0x3A, + 0x00, + 0x00, + 0x04, + 0xE0, + 0x2D, + 0xE5, + 0x04, + 0xD0, + 0x4D, + 0xE2, + 0x18, + 0x13, + 0x00, + 0xEB, + 0x04, + 0xD0, + 0x8D, + 0xE2, + 0x04, + 0xE0, + 0x9D, + 0xE4, + 0x1E, + 0xFF, + 0x2F, + 0xE1, + 0x04, + 0xE0, + 0x2D, + 0xE5, + 0x04, + 0xE0, + 0x9F, + 0xE5, + 0x0E, + 0xE0, + 0x8F, + 0xE0, + 0x08, + 0xF0, + 0xBE, + 0xE5, + 0xF0, + 0x3A, + 0x0A, + 0x00, + 0x00, + 0xC6, + 0x8F, + 0xE2, + 0xA3, + 0xCA, + 0x8C, + 0xE2, + 0xF0, + 0xFA, + 0xBC, + 0xE5, + 0x00, + 0xC6, + 0x8F, + 0xE2, + 0xA3, + 0xCA, + 0x8C, + 0xE2, + 0xE8, + 0xFA, + 0xBC, + 0xE5, + 0x00, + 0xC6, + 0x8F, + 0xE2 + }; - private static byte[] armtResultData { get; } = new byte[] { - 0x95, 0x23, 0xB6, 0xB1, 0xBE, 0x60, 0x79, 0xF0, 0xF6, 0x01, 0xD9, 0x7F, 0x2E, 0x03, 0x31, 0x1C, 0xFD, 0xD3, 0x40, 0x0F, 0x21, 0x3C, 0x06, 0x97, 0xE5, 0xC3, - 0x57, 0x11, 0x76, 0x6F, 0xE3, 0x70, 0xED, 0x49, 0xCB, 0xB5, 0xC9, 0x42, 0x59, 0x10, 0x2F, 0xBD, 0xAE, 0xB1, 0x40, 0x4D, 0x9D, 0x7C, 0xE9, 0xFC, 0x48, 0x3E, - 0xBC, 0x7F, 0x0B, 0x23, 0xB0, 0x8A, 0x4D, 0x02, 0x39, 0xC4, 0xFB, 0x66, 0x83, 0x7F, 0xA7, 0xBD, 0x12, 0xAC, 0xED, 0x31, 0x34, 0x93, 0x4D, 0x8D, 0xD7, 0x94, - 0x93, 0x1C, 0x0A, 0x50, 0x54, 0x4B, 0x03, 0x55, 0x27, 0xFE, 0xCE, 0x29, 0x66, 0x52, 0x81, 0xAE, 0x69, 0xA0, 0x69, 0xF2, 0x3D, 0xFF, 0xA1, 0x8A, 0x5D, 0x61, - 0x7D, 0xC5, 0x94, 0x0A, 0x7D, 0xED, 0x11, 0x0F - }; + private static byte[] armtResultData { get; } = + new byte[] + { + 0x95, + 0x23, + 0xB6, + 0xB1, + 0xBE, + 0x60, + 0x79, + 0xF0, + 0xF6, + 0x01, + 0xD9, + 0x7F, + 0x2E, + 0x03, + 0x31, + 0x1C, + 0xFD, + 0xD3, + 0x40, + 0x0F, + 0x21, + 0x3C, + 0x06, + 0x97, + 0xE5, + 0xC3, + 0x57, + 0x11, + 0x76, + 0x6F, + 0xE3, + 0x70, + 0xED, + 0x49, + 0xCB, + 0xB5, + 0xC9, + 0x42, + 0x59, + 0x10, + 0x2F, + 0xBD, + 0xAE, + 0xB1, + 0x40, + 0x4D, + 0x9D, + 0x7C, + 0xE9, + 0xFC, + 0x48, + 0x3E, + 0xBC, + 0x7F, + 0x0B, + 0x23, + 0xB0, + 0x8A, + 0x4D, + 0x02, + 0x39, + 0xC4, + 0xFB, + 0x66, + 0x83, + 0x7F, + 0xA7, + 0xBD, + 0x12, + 0xAC, + 0xED, + 0x31, + 0x34, + 0x93, + 0x4D, + 0x8D, + 0xD7, + 0x94, + 0x93, + 0x1C, + 0x0A, + 0x50, + 0x54, + 0x4B, + 0x03, + 0x55, + 0x27, + 0xFE, + 0xCE, + 0x29, + 0x66, + 0x52, + 0x81, + 0xAE, + 0x69, + 0xA0, + 0x69, + 0xF2, + 0x3D, + 0xFF, + 0xA1, + 0x8A, + 0x5D, + 0x61, + 0x7D, + 0xC5, + 0x94, + 0x0A, + 0x7D, + 0xED, + 0x11, + 0x0F + }; - private static byte[] armtData { get; } = new byte[] { - 0x95, 0x23, 0xB6, 0xB1, 0xBE, 0x60, 0x79, 0xF0, 0xF6, 0x01, 0xD9, 0x7F, 0x2E, 0x03, 0x31, 0x1C, 0xFD, 0xD3, 0x40, 0x0F, 0x21, 0x3C, 0x06, 0x97, 0xE5, 0xC3, - 0x57, 0x11, 0x76, 0x6F, 0xE3, 0x70, 0xED, 0x49, 0xCB, 0xB5, 0xC9, 0x42, 0x59, 0x10, 0x2F, 0xBD, 0xAE, 0xB1, 0x40, 0x4D, 0x9D, 0x7C, 0xE9, 0xFC, 0x48, 0x3E, - 0xBC, 0x7F, 0x0B, 0x23, 0xB0, 0x8A, 0x4D, 0x02, 0x39, 0xC4, 0xFB, 0x66, 0x83, 0x7F, 0xA7, 0xBD, 0x12, 0xAC, 0xED, 0x31, 0x34, 0x93, 0x4D, 0x8D, 0xD7, 0x94, - 0x93, 0x1C, 0x0A, 0x50, 0x54, 0x4B, 0x03, 0x55, 0x27, 0xFE, 0xCE, 0x29, 0x66, 0x52, 0x81, 0xAE, 0x69, 0xA0, 0x6A, 0xF2, 0x6F, 0xFC, 0xA1, 0x8A, 0x5D, 0x61, - 0x7D, 0xC5, 0x94, 0x0A, 0x7D, 0xED, 0x11, 0x0F - }; + private static byte[] armtData { get; } = + new byte[] + { + 0x95, + 0x23, + 0xB6, + 0xB1, + 0xBE, + 0x60, + 0x79, + 0xF0, + 0xF6, + 0x01, + 0xD9, + 0x7F, + 0x2E, + 0x03, + 0x31, + 0x1C, + 0xFD, + 0xD3, + 0x40, + 0x0F, + 0x21, + 0x3C, + 0x06, + 0x97, + 0xE5, + 0xC3, + 0x57, + 0x11, + 0x76, + 0x6F, + 0xE3, + 0x70, + 0xED, + 0x49, + 0xCB, + 0xB5, + 0xC9, + 0x42, + 0x59, + 0x10, + 0x2F, + 0xBD, + 0xAE, + 0xB1, + 0x40, + 0x4D, + 0x9D, + 0x7C, + 0xE9, + 0xFC, + 0x48, + 0x3E, + 0xBC, + 0x7F, + 0x0B, + 0x23, + 0xB0, + 0x8A, + 0x4D, + 0x02, + 0x39, + 0xC4, + 0xFB, + 0x66, + 0x83, + 0x7F, + 0xA7, + 0xBD, + 0x12, + 0xAC, + 0xED, + 0x31, + 0x34, + 0x93, + 0x4D, + 0x8D, + 0xD7, + 0x94, + 0x93, + 0x1C, + 0x0A, + 0x50, + 0x54, + 0x4B, + 0x03, + 0x55, + 0x27, + 0xFE, + 0xCE, + 0x29, + 0x66, + 0x52, + 0x81, + 0xAE, + 0x69, + 0xA0, + 0x6A, + 0xF2, + 0x6F, + 0xFC, + 0xA1, + 0x8A, + 0x5D, + 0x61, + 0x7D, + 0xC5, + 0x94, + 0x0A, + 0x7D, + 0xED, + 0x11, + 0x0F + }; - private static byte[] ia64ResultData { get; } = new byte[] { - 0x4D, 0xF8, 0xF2, 0x0D, 0x06, 0x2F, 0x74, 0x0F, 0xF0, 0x91, 0x06, 0x0B, 0x19, 0x22, 0x91, 0x5A, 0x66, 0x56, 0xA7, 0x15, 0x77, 0x1E, 0x2F, 0xA3, 0xE4, 0xDE, - 0x93, 0x1C, 0xD5, 0xCE, 0x6E, 0x45, 0x36, 0x15, 0x15, 0x65, 0x4E, 0xC5, 0xA3, 0x8C, 0x5A, 0x8B, 0x8A, 0x1C, 0x12, 0x5B, 0x39, 0x1F, 0xA0, 0xF2, 0x93, 0x7C, - 0x7F, 0x5D, 0xD9, 0x30, 0x1F, 0xF6, 0x5C, 0x10, 0x62, 0x3E, 0xB4, 0x64, 0x56, 0x48, 0xB2, 0x20, 0x39, 0xE8, 0x44, 0x10, 0x87, 0x9E, 0x2C, 0xFC, 0x29, 0x0E, - 0x20, 0x76, 0xCE, 0xDA, 0x93, 0x1C, 0xED, 0x54, 0x0D, 0xAF, 0xEC, 0xDE, 0x93, 0x1C, 0x2B, 0x72, 0xD5, 0x0D - }; + private static byte[] ia64ResultData { get; } = + new byte[] + { + 0x4D, + 0xF8, + 0xF2, + 0x0D, + 0x06, + 0x2F, + 0x74, + 0x0F, + 0xF0, + 0x91, + 0x06, + 0x0B, + 0x19, + 0x22, + 0x91, + 0x5A, + 0x66, + 0x56, + 0xA7, + 0x15, + 0x77, + 0x1E, + 0x2F, + 0xA3, + 0xE4, + 0xDE, + 0x93, + 0x1C, + 0xD5, + 0xCE, + 0x6E, + 0x45, + 0x36, + 0x15, + 0x15, + 0x65, + 0x4E, + 0xC5, + 0xA3, + 0x8C, + 0x5A, + 0x8B, + 0x8A, + 0x1C, + 0x12, + 0x5B, + 0x39, + 0x1F, + 0xA0, + 0xF2, + 0x93, + 0x7C, + 0x7F, + 0x5D, + 0xD9, + 0x30, + 0x1F, + 0xF6, + 0x5C, + 0x10, + 0x62, + 0x3E, + 0xB4, + 0x64, + 0x56, + 0x48, + 0xB2, + 0x20, + 0x39, + 0xE8, + 0x44, + 0x10, + 0x87, + 0x9E, + 0x2C, + 0xFC, + 0x29, + 0x0E, + 0x20, + 0x76, + 0xCE, + 0xDA, + 0x93, + 0x1C, + 0xED, + 0x54, + 0x0D, + 0xAF, + 0xEC, + 0xDE, + 0x93, + 0x1C, + 0x2B, + 0x72, + 0xD5, + 0x0D + }; - private static byte[] ia64Data { get; } = new byte[] { - 0x4D, 0xF8, 0xF2, 0x0D, 0x06, 0x2F, 0x74, 0x0F, 0xF0, 0x91, 0x06, 0x0B, 0x19, 0x22, 0x91, 0x5A, 0x66, 0x56, 0xA7, 0x15, 0x77, 0x1E, 0x2F, 0xA3, 0xE4, 0xDE, - 0x93, 0x1C, 0xD5, 0xCE, 0x6E, 0x45, 0x36, 0x15, 0x15, 0x65, 0x4E, 0xC5, 0xA3, 0x8C, 0x5A, 0x8B, 0x8A, 0x1C, 0x12, 0x5B, 0x39, 0x1F, 0xA0, 0xF2, 0x93, 0x7C, - 0x7F, 0x5D, 0xD9, 0x30, 0x1F, 0xF6, 0x5C, 0x10, 0x62, 0x3E, 0xB4, 0x64, 0x56, 0x48, 0xB2, 0x20, 0x39, 0xE8, 0x44, 0x80, 0x8C, 0x9E, 0x2C, 0xFC, 0x29, 0x0E, - 0x20, 0x76, 0xCE, 0xDA, 0x93, 0x1C, 0xED, 0x54, 0x0D, 0xAF, 0xEC, 0xDE, 0x93, 0x1C, 0x2B, 0x72, 0xD5, 0x0D - }; + private static byte[] ia64Data { get; } = + new byte[] + { + 0x4D, + 0xF8, + 0xF2, + 0x0D, + 0x06, + 0x2F, + 0x74, + 0x0F, + 0xF0, + 0x91, + 0x06, + 0x0B, + 0x19, + 0x22, + 0x91, + 0x5A, + 0x66, + 0x56, + 0xA7, + 0x15, + 0x77, + 0x1E, + 0x2F, + 0xA3, + 0xE4, + 0xDE, + 0x93, + 0x1C, + 0xD5, + 0xCE, + 0x6E, + 0x45, + 0x36, + 0x15, + 0x15, + 0x65, + 0x4E, + 0xC5, + 0xA3, + 0x8C, + 0x5A, + 0x8B, + 0x8A, + 0x1C, + 0x12, + 0x5B, + 0x39, + 0x1F, + 0xA0, + 0xF2, + 0x93, + 0x7C, + 0x7F, + 0x5D, + 0xD9, + 0x30, + 0x1F, + 0xF6, + 0x5C, + 0x10, + 0x62, + 0x3E, + 0xB4, + 0x64, + 0x56, + 0x48, + 0xB2, + 0x20, + 0x39, + 0xE8, + 0x44, + 0x80, + 0x8C, + 0x9E, + 0x2C, + 0xFC, + 0x29, + 0x0E, + 0x20, + 0x76, + 0xCE, + 0xDA, + 0x93, + 0x1C, + 0xED, + 0x54, + 0x0D, + 0xAF, + 0xEC, + 0xDE, + 0x93, + 0x1C, + 0x2B, + 0x72, + 0xD5, + 0x0D + }; - private static byte[] sparcResultData { get; } = new byte[] { - 0x78, 0x2E, 0x73, 0x6F, 0x2E, 0x33, 0x00, 0x00, 0x07, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0xA2, 0x0D, - 0x10, 0x12, 0x30, 0x03, 0xC9, 0x37, 0x40, 0x1A, 0x85, 0xD9, 0x44, 0x34, 0x40, 0x32, 0x85, 0xA0, 0x30, 0x40, 0x00, 0x70, 0x00, 0x40, 0x84, 0x80, 0x04, 0x00, - 0xE4, 0xAC, 0x07, 0x04, 0x21, 0x44, 0x02, 0x20, 0x10, 0x00, 0x40, 0xC2, 0x89, 0x98, 0x85, 0x00, 0x58, 0x6A, 0x41, 0x8E, 0x18, 0xA1, 0x91, 0x00, 0x10, 0x00, - }; + private static byte[] sparcResultData { get; } = + new byte[] + { + 0x78, + 0x2E, + 0x73, + 0x6F, + 0x2E, + 0x33, + 0x00, + 0x00, + 0x07, + 0x01, + 0x00, + 0x00, + 0x09, + 0x00, + 0x00, + 0x00, + 0x40, + 0x00, + 0x00, + 0x00, + 0x0B, + 0x00, + 0x00, + 0x00, + 0xA2, + 0x0D, + 0x10, + 0x12, + 0x30, + 0x03, + 0xC9, + 0x37, + 0x40, + 0x1A, + 0x85, + 0xD9, + 0x44, + 0x34, + 0x40, + 0x32, + 0x85, + 0xA0, + 0x30, + 0x40, + 0x00, + 0x70, + 0x00, + 0x40, + 0x84, + 0x80, + 0x04, + 0x00, + 0xE4, + 0xAC, + 0x07, + 0x04, + 0x21, + 0x44, + 0x02, + 0x20, + 0x10, + 0x00, + 0x40, + 0xC2, + 0x89, + 0x98, + 0x85, + 0x00, + 0x58, + 0x6A, + 0x41, + 0x8E, + 0x18, + 0xA1, + 0x91, + 0x00, + 0x10, + 0x00, + }; - private static byte[] sparcData { get; } = new byte[] { - 0x78, 0x2E, 0x73, 0x6F, 0x2E, 0x33, 0x00, 0x00, 0x07, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x44, 0x0B, 0x00, 0x00, 0x00, 0xA2, 0x0D, - 0x10, 0x12, 0x30, 0x03, 0xC9, 0x37, 0x40, 0x1A, 0x86, 0x21, 0x44, 0x34, 0x40, 0x32, 0x85, 0xA0, 0x30, 0x40, 0x00, 0x70, 0x00, 0x40, 0x84, 0x80, 0x04, 0x00, - 0xE4, 0xAC, 0x07, 0x04, 0x21, 0x44, 0x02, 0x20, 0x10, 0x00, 0x40, 0xC2, 0x89, 0x98, 0x85, 0x00, 0x58, 0x6A, 0x41, 0x8E, 0x18, 0xA1, 0x91, 0x00, 0x10, 0x00, - }; + private static byte[] sparcData { get; } = + new byte[] + { + 0x78, + 0x2E, + 0x73, + 0x6F, + 0x2E, + 0x33, + 0x00, + 0x00, + 0x07, + 0x01, + 0x00, + 0x00, + 0x09, + 0x00, + 0x00, + 0x00, + 0x40, + 0x00, + 0x00, + 0x44, + 0x0B, + 0x00, + 0x00, + 0x00, + 0xA2, + 0x0D, + 0x10, + 0x12, + 0x30, + 0x03, + 0xC9, + 0x37, + 0x40, + 0x1A, + 0x86, + 0x21, + 0x44, + 0x34, + 0x40, + 0x32, + 0x85, + 0xA0, + 0x30, + 0x40, + 0x00, + 0x70, + 0x00, + 0x40, + 0x84, + 0x80, + 0x04, + 0x00, + 0xE4, + 0xAC, + 0x07, + 0x04, + 0x21, + 0x44, + 0x02, + 0x20, + 0x10, + 0x00, + 0x40, + 0xC2, + 0x89, + 0x98, + 0x85, + 0x00, + 0x58, + 0x6A, + 0x41, + 0x8E, + 0x18, + 0xA1, + 0x91, + 0x00, + 0x10, + 0x00, + }; private void CompareBuffer(byte[] testBuffer, byte[] targetBuffer) { diff --git a/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs index 15389a4f..cfe0bf51 100644 --- a/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipArchiveTests.cs @@ -30,8 +30,10 @@ namespace SharpCompress.Test.GZip Assert.Equal(size, scratch.Length); Assert.Equal(size, test.Length); } - CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"), - Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); + CompareArchivesByPath( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"), + Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar") + ); } [Fact] @@ -50,11 +52,12 @@ namespace SharpCompress.Test.GZip Assert.Equal(size, scratch.Length); Assert.Equal(size, test.Length); } - CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"), - Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); + CompareArchivesByPath( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"), + Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar") + ); } - [Fact] public void GZip_Archive_NoAdd() { @@ -62,12 +65,13 @@ namespace SharpCompress.Test.GZip using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz"))) using (var archive = GZipArchive.Open(stream)) { - Assert.Throws(() => archive.AddEntry("jpg\\test.jpg", jpg)); + Assert.Throws( + () => archive.AddEntry("jpg\\test.jpg", jpg) + ); archive.SaveTo(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz")); } } - [Fact] public void GZip_Archive_Multiple_Reads() { diff --git a/tests/SharpCompress.Test/GZip/GZipReaderTests.cs b/tests/SharpCompress.Test/GZip/GZipReaderTests.cs index ed308c98..a2c8071d 100644 --- a/tests/SharpCompress.Test/GZip/GZipReaderTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipReaderTests.cs @@ -18,13 +18,16 @@ namespace SharpCompress.Test.GZip Read("Tar.tar.gz", CompressionType.GZip); } - [Fact] public void GZip_Reader_Generic2() { //read only as GZip itme using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz"))) - using (var reader = SharpCompress.Readers.GZip.GZipReader.Open(new RewindableStream(stream))) + using ( + var reader = SharpCompress.Readers.GZip.GZipReader.Open( + new RewindableStream(stream) + ) + ) { while (reader.MoveToNextEntry()) // Crash here { diff --git a/tests/SharpCompress.Test/GZip/GZipWriterTests.cs b/tests/SharpCompress.Test/GZip/GZipWriterTests.cs index 5c109bd5..212e275e 100644 --- a/tests/SharpCompress.Test/GZip/GZipWriterTests.cs +++ b/tests/SharpCompress.Test/GZip/GZipWriterTests.cs @@ -8,8 +8,7 @@ namespace SharpCompress.Test.GZip { public class GZipWriterTests : WriterTests { - public GZipWriterTests() - : base(ArchiveType.GZip) + public GZipWriterTests() : base(ArchiveType.GZip) { UseExtensionInsteadOfNameToVerify = true; } @@ -17,25 +16,41 @@ namespace SharpCompress.Test.GZip [Fact] public void GZip_Writer_Generic() { - using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write)) + using ( + Stream stream = File.Open( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), + FileMode.OpenOrCreate, + FileAccess.Write + ) + ) using (var writer = WriterFactory.Open(stream, ArchiveType.GZip, CompressionType.GZip)) { writer.Write("Tar.tar", Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); } - CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), - Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); + CompareArchivesByPath( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), + Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz") + ); } [Fact] public void GZip_Writer() { - using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write)) + using ( + Stream stream = File.Open( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), + FileMode.OpenOrCreate, + FileAccess.Write + ) + ) using (var writer = new GZipWriter(stream)) { writer.Write("Tar.tar", Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); } - CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), - Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); + CompareArchivesByPath( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), + Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz") + ); } [Fact] @@ -43,24 +58,34 @@ namespace SharpCompress.Test.GZip { Assert.Throws(() => { - using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"))) - using (var writer = WriterFactory.Open(stream, ArchiveType.GZip, CompressionType.BZip2)) - { - } + using ( + Stream stream = File.OpenWrite(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz")) + ) + using ( + var writer = WriterFactory.Open(stream, ArchiveType.GZip, CompressionType.BZip2) + ) { } }); } [Fact] public void GZip_Writer_Entry_Path_With_Dir() { - using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write)) + using ( + Stream stream = File.Open( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), + FileMode.OpenOrCreate, + FileAccess.Write + ) + ) using (var writer = new GZipWriter(stream)) { var path = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"); writer.Write(path, path); //covers issue #532 } - CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), - Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz")); + CompareArchivesByPath( + Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), + Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz") + ); } } } diff --git a/tests/SharpCompress.Test/Mocks/FlushOnDisposeStream.cs b/tests/SharpCompress.Test/Mocks/FlushOnDisposeStream.cs index 22e84ef9..fb1106d5 100644 --- a/tests/SharpCompress.Test/Mocks/FlushOnDisposeStream.cs +++ b/tests/SharpCompress.Test/Mocks/FlushOnDisposeStream.cs @@ -24,7 +24,11 @@ namespace SharpCompress.Test.Mocks public override long Length => this.inner.Length; - public override long Position { get => this.inner.Position; set => this.inner.Position = value; } + public override long Position + { + get => this.inner.Position; + set => this.inner.Position = value; + } public override void Flush() { diff --git a/tests/SharpCompress.Test/Mocks/ForwardOnlyStream.cs b/tests/SharpCompress.Test/Mocks/ForwardOnlyStream.cs index aaa52c51..9c10941f 100644 --- a/tests/SharpCompress.Test/Mocks/ForwardOnlyStream.cs +++ b/tests/SharpCompress.Test/Mocks/ForwardOnlyStream.cs @@ -65,4 +65,4 @@ namespace SharpCompress.Test.Mocks throw new NotSupportedException(); } } -} \ No newline at end of file +} diff --git a/tests/SharpCompress.Test/Mocks/TestStream.cs b/tests/SharpCompress.Test/Mocks/TestStream.cs index 64bee443..000cf408 100644 --- a/tests/SharpCompress.Test/Mocks/TestStream.cs +++ b/tests/SharpCompress.Test/Mocks/TestStream.cs @@ -6,9 +6,8 @@ namespace SharpCompress.Test.Mocks { private readonly Stream stream; - public TestStream(Stream stream) : this(stream, stream.CanRead, stream.CanWrite, stream.CanSeek) - { - } + public TestStream(Stream stream) + : this(stream, stream.CanRead, stream.CanWrite, stream.CanSeek) { } public bool IsDisposed { get; private set; } diff --git a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs index 3adf92ea..6c61215c 100644 --- a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs @@ -20,7 +20,10 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_EncryptedFileAndHeader_NoPasswordExceptionTest() { - Assert.Throws(typeof(CryptographicException), () => ReadRarPassword("Rar.encrypted_filesAndHeader.rar", null)); + Assert.Throws( + typeof(CryptographicException), + () => ReadRarPassword("Rar.encrypted_filesAndHeader.rar", null) + ); } /*[Fact] @@ -32,7 +35,10 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar5_EncryptedFileAndHeader_NoPasswordExceptionTest() { - Assert.Throws(typeof(CryptographicException), () => ReadRarPassword("Rar5.encrypted_filesAndHeader.rar", null)); + Assert.Throws( + typeof(CryptographicException), + () => ReadRarPassword("Rar5.encrypted_filesAndHeader.rar", null) + ); } [Fact] @@ -62,22 +68,22 @@ namespace SharpCompress.Test.Rar private void ReadRarPassword(string testArchive, string? password) { using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, testArchive))) - using (var archive = RarArchive.Open(stream, new ReaderOptions() - { - Password = password, - LeaveStreamOpen = true - })) + using ( + var archive = RarArchive.Open( + stream, + new ReaderOptions() { Password = password, LeaveStreamOpen = true } + ) + ) { foreach (var entry in archive.Entries) { if (!entry.IsDirectory) { Assert.Equal(CompressionType.Rar, entry.CompressionType); - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -87,25 +93,26 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_Multi_Archive_Encrypted() { - Assert.Throws(() => ArchiveFileReadPassword("Rar.EncryptedParts.part01.rar", "test")); + Assert.Throws( + () => ArchiveFileReadPassword("Rar.EncryptedParts.part01.rar", "test") + ); } protected void ArchiveFileReadPassword(string archiveName, string password) { - using (var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, archiveName), new ReaderOptions() - { - Password = password, - LeaveStreamOpen = true - })) + using ( + var archive = RarArchive.Open( + Path.Combine(TEST_ARCHIVES_PATH, archiveName), + new ReaderOptions() { Password = password, LeaveStreamOpen = true } + ) + ) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -149,11 +156,10 @@ namespace SharpCompress.Test.Rar { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -164,19 +170,19 @@ namespace SharpCompress.Test.Rar { using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"))) { - using (var archive = RarArchive.Open(stream, new ReaderOptions() - { - LookForHeader = true - })) + using ( + var archive = RarArchive.Open( + stream, + new ReaderOptions() { LookForHeader = true } + ) + ) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -204,19 +210,16 @@ namespace SharpCompress.Test.Rar Assert.False(archive.IsSolid); foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } VerifyFiles(); } - [Fact] public void Rar_IsSolidEntryStreamCheck() { @@ -252,7 +255,6 @@ namespace SharpCompress.Test.Rar } } - [Fact] public void Rar_Solid_ArchiveStreamRead() { @@ -280,40 +282,52 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_Multi_ArchiveStreamRead() { - DoRar_Multi_ArchiveStreamRead(new string[] { - "Rar.multi.part01.rar", - "Rar.multi.part02.rar", - "Rar.multi.part03.rar", - "Rar.multi.part04.rar", - "Rar.multi.part05.rar", - "Rar.multi.part06.rar"}, false); + DoRar_Multi_ArchiveStreamRead( + new string[] + { + "Rar.multi.part01.rar", + "Rar.multi.part02.rar", + "Rar.multi.part03.rar", + "Rar.multi.part04.rar", + "Rar.multi.part05.rar", + "Rar.multi.part06.rar" + }, + false + ); } [Fact] public void Rar5_Multi_ArchiveStreamRead() { - DoRar_Multi_ArchiveStreamRead(new string[] { - "Rar5.multi.part01.rar", - "Rar5.multi.part02.rar", - "Rar5.multi.part03.rar", - "Rar5.multi.part04.rar", - "Rar5.multi.part05.rar", - "Rar5.multi.part06.rar"}, false); + DoRar_Multi_ArchiveStreamRead( + new string[] + { + "Rar5.multi.part01.rar", + "Rar5.multi.part02.rar", + "Rar5.multi.part03.rar", + "Rar5.multi.part04.rar", + "Rar5.multi.part05.rar", + "Rar5.multi.part06.rar" + }, + false + ); } private void DoRar_Multi_ArchiveStreamRead(string[] archives, bool isSolid) { - using (var archive = RarArchive.Open(archives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) - .Select(File.OpenRead))) + using ( + var archive = RarArchive.Open( + archives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)).Select(File.OpenRead) + ) + ) { Assert.Equal(archive.IsSolid, isSolid); foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -321,13 +335,18 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar5_MultiSolid_ArchiveStreamRead() { - DoRar_Multi_ArchiveStreamRead(new string[] { - "Rar.multi.solid.part01.rar", - "Rar.multi.solid.part02.rar", - "Rar.multi.solid.part03.rar", - "Rar.multi.solid.part04.rar", - "Rar.multi.solid.part05.rar", - "Rar.multi.solid.part06.rar"}, true); + DoRar_Multi_ArchiveStreamRead( + new string[] + { + "Rar.multi.solid.part01.rar", + "Rar.multi.solid.part02.rar", + "Rar.multi.solid.part03.rar", + "Rar.multi.solid.part04.rar", + "Rar.multi.solid.part05.rar", + "Rar.multi.solid.part06.rar" + }, + true + ); } [Fact] @@ -381,18 +400,19 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_Jpg_ArchiveFileRead() { - using (var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"), new ReaderOptions() - { - LookForHeader = true - })) + using ( + var archive = RarArchive.Open( + Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"), + new ReaderOptions() { LookForHeader = true } + ) + ) { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -413,14 +433,19 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar2_Multi_ArchiveStreamRead() { - DoRar_Multi_ArchiveStreamRead(new string[] { - "Rar2.multi.rar", - "Rar2.multi.r00", - "Rar2.multi.r01", - "Rar2.multi.r02", - "Rar2.multi.r03", - "Rar2.multi.r04", - "Rar2.multi.r05"}, false); + DoRar_Multi_ArchiveStreamRead( + new string[] + { + "Rar2.multi.rar", + "Rar2.multi.r00", + "Rar2.multi.r01", + "Rar2.multi.r02", + "Rar2.multi.r03", + "Rar2.multi.r04", + "Rar2.multi.r05" + }, + false + ); } [Fact] @@ -487,138 +512,174 @@ namespace SharpCompress.Test.Rar public void Rar_GetPartsSplit() { //uses first part to search for all parts and compares against this array - ArchiveGetParts(new string[] { - "Rar4.split.001", - "Rar4.split.002", - "Rar4.split.003", - "Rar4.split.004", - "Rar4.split.005", - "Rar4.split.006"}); + ArchiveGetParts( + new string[] + { + "Rar4.split.001", + "Rar4.split.002", + "Rar4.split.003", + "Rar4.split.004", + "Rar4.split.005", + "Rar4.split.006" + } + ); } + [Fact] public void Rar_GetPartsOld() { //uses first part to search for all parts and compares against this array - ArchiveGetParts(new string[] { - "Rar2.multi.rar", - "Rar2.multi.r00", - "Rar2.multi.r01", - "Rar2.multi.r02", - "Rar2.multi.r03", - "Rar2.multi.r04", - "Rar2.multi.r05"}); + ArchiveGetParts( + new string[] + { + "Rar2.multi.rar", + "Rar2.multi.r00", + "Rar2.multi.r01", + "Rar2.multi.r02", + "Rar2.multi.r03", + "Rar2.multi.r04", + "Rar2.multi.r05" + } + ); } + [Fact] public void Rar_GetPartsNew() { //uses first part to search for all parts and compares against this array - ArchiveGetParts(new string[] { - "Rar4.multi.part01.rar", - "Rar4.multi.part02.rar", - "Rar4.multi.part03.rar", - "Rar4.multi.part04.rar", - "Rar4.multi.part05.rar", - "Rar4.multi.part06.rar", - "Rar4.multi.part07.rar"}); + ArchiveGetParts( + new string[] + { + "Rar4.multi.part01.rar", + "Rar4.multi.part02.rar", + "Rar4.multi.part03.rar", + "Rar4.multi.part04.rar", + "Rar4.multi.part05.rar", + "Rar4.multi.part06.rar", + "Rar4.multi.part07.rar" + } + ); } [Fact] public void Rar4_Multi_ArchiveStreamRead() { - DoRar_Multi_ArchiveStreamRead(new string[] { - "Rar4.multi.part01.rar", - "Rar4.multi.part02.rar", - "Rar4.multi.part03.rar", - "Rar4.multi.part04.rar", - "Rar4.multi.part05.rar", - "Rar4.multi.part06.rar", - "Rar4.multi.part07.rar"}, false); + DoRar_Multi_ArchiveStreamRead( + new string[] + { + "Rar4.multi.part01.rar", + "Rar4.multi.part02.rar", + "Rar4.multi.part03.rar", + "Rar4.multi.part04.rar", + "Rar4.multi.part05.rar", + "Rar4.multi.part06.rar", + "Rar4.multi.part07.rar" + }, + false + ); } //no extension to test the lib identifies the archive by content not ext [Fact] public void Rar4_Split_ArchiveStreamRead() { - ArchiveStreamMultiRead(null, new string[] { - "Rar4.split.001", - "Rar4.split.002", - "Rar4.split.003", - "Rar4.split.004", - "Rar4.split.005", - "Rar4.split.006"}); + ArchiveStreamMultiRead( + null, + new string[] + { + "Rar4.split.001", + "Rar4.split.002", + "Rar4.split.003", + "Rar4.split.004", + "Rar4.split.005", + "Rar4.split.006" + } + ); } + //will detect and load other files [Fact] public void Rar4_Multi_ArchiveFirstFileRead() { ArchiveFileRead("Rar4.multi.part01.rar"); - //"Rar4.multi.part02.rar", - //"Rar4.multi.part03.rar", - //"Rar4.multi.part04.rar", - //"Rar4.multi.part05.rar", - //"Rar4.multi.part06.rar", - //"Rar4.multi.part07.rar" + //"Rar4.multi.part02.rar", + //"Rar4.multi.part03.rar", + //"Rar4.multi.part04.rar", + //"Rar4.multi.part05.rar", + //"Rar4.multi.part06.rar", + //"Rar4.multi.part07.rar" } - //will detect and load other files - [Fact] + + //will detect and load other files + [Fact] public void Rar4_Split_ArchiveFirstFileRead() { ArchiveFileRead("Rar4.split.001"); - //"Rar4.split.002", - //"Rar4.split.003", - //"Rar4.split.004", - //"Rar4.split.005", - //"Rar4.split.006" + //"Rar4.split.002", + //"Rar4.split.003", + //"Rar4.split.004", + //"Rar4.split.005", + //"Rar4.split.006" } + //will detect and load other files [Fact] public void Rar4_Split_ArchiveStreamFirstFileRead() { - ArchiveStreamMultiRead(null, new string[] { - "Rar4.split.001", - //"Rar4.split.002", - //"Rar4.split.003", - //"Rar4.split.004", - //"Rar4.split.005", - //"Rar4.split.006" - }); + ArchiveStreamMultiRead( + null, + new string[] + { + "Rar4.split.001", + //"Rar4.split.002", + //"Rar4.split.003", + //"Rar4.split.004", + //"Rar4.split.005", + //"Rar4.split.006" + } + ); } //open with ArchiveFactory.Open and stream [Fact] public void Rar4_Split_ArchiveOpen() { - ArchiveOpenStreamRead(null, + ArchiveOpenStreamRead( + null, "Rar4.split.001", "Rar4.split.002", "Rar4.split.003", "Rar4.split.004", "Rar4.split.005", - "Rar4.split.006"); + "Rar4.split.006" + ); } //open with ArchiveFactory.Open and stream [Fact] public void Rar4_Multi_ArchiveOpen() { - ArchiveOpenStreamRead(null, + ArchiveOpenStreamRead( + null, "Rar4.multi.part01.rar", "Rar4.multi.part02.rar", "Rar4.multi.part03.rar", "Rar4.multi.part04.rar", "Rar4.multi.part05.rar", "Rar4.multi.part06.rar", - "Rar4.multi.part07.rar"); + "Rar4.multi.part07.rar" + ); } [Fact] public void Rar4_Multi_ArchiveOpenEntryVolumeIndexTest() { ArchiveOpenEntryVolumeIndexTest( - new[] { + new[] + { new[] { 0, 1 }, //exe - Rar4.multi.part01.rar to Rar4.multi.part02.rar new[] { 1, 5 }, //jpg - Rar4.multi.part02.rar to Rar4.multi.part06.rar - new[] { 5, 6 } //txt - Rar4.multi.part06.rar to Rar4.multi.part07.rar + new[] { 5, 6 } //txt - Rar4.multi.part06.rar to Rar4.multi.part07.rar }, null, "Rar4.multi.part01.rar", @@ -627,10 +688,11 @@ namespace SharpCompress.Test.Rar "Rar4.multi.part04.rar", "Rar4.multi.part05.rar", "Rar4.multi.part06.rar", - "Rar4.multi.part07.rar"); + "Rar4.multi.part07.rar" + ); } - [Fact] + [Fact] public void Rar_Multi_ArchiveFileRead() { ArchiveFileRead("Rar.multi.part01.rar"); @@ -677,7 +739,9 @@ namespace SharpCompress.Test.Rar private void DoRar_IsFirstVolume_False(string notFirstFilename) { - using (var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, notFirstFilename))) + using ( + var archive = RarArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, notFirstFilename)) + ) { Assert.True(archive.IsMultipartVolume()); Assert.False(archive.IsFirstVolume()); diff --git a/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs index a9c4c798..745935d2 100644 --- a/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs +++ b/tests/SharpCompress.Test/Rar/RarHeaderFactoryTest.cs @@ -17,7 +17,8 @@ namespace SharpCompress.Test.Rar { rarHeaderFactory = new RarHeaderFactory( StreamingMode.Seekable, - new ReaderOptions { LeaveStreamOpen = true }); + new ReaderOptions { LeaveStreamOpen = true } + ); } [Fact] @@ -46,11 +47,20 @@ namespace SharpCompress.Test.Rar private void ReadEncryptedFlag(string testArchive, bool isEncrypted) { - using (var stream = new FileStream(Path.Combine(TEST_ARCHIVES_PATH, testArchive), FileMode.Open, FileAccess.Read)) + using ( + var stream = new FileStream( + Path.Combine(TEST_ARCHIVES_PATH, testArchive), + FileMode.Open, + FileAccess.Read + ) + ) { foreach (var header in rarHeaderFactory.ReadHeaders(stream)) { - if (header.HeaderType == HeaderType.Archive || header.HeaderType == HeaderType.Crypt) + if ( + header.HeaderType == HeaderType.Archive + || header.HeaderType == HeaderType.Crypt + ) { Assert.Equal(isEncrypted, rarHeaderFactory.IsEncrypted); break; diff --git a/tests/SharpCompress.Test/Rar/RarReaderTests.cs b/tests/SharpCompress.Test/Rar/RarReaderTests.cs index 0ac4e667..bb841475 100644 --- a/tests/SharpCompress.Test/Rar/RarReaderTests.cs +++ b/tests/SharpCompress.Test/Rar/RarReaderTests.cs @@ -13,39 +13,51 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_Multi_Reader() { - DoRar_Multi_Reader(new string[] { - "Rar.multi.part01.rar", - "Rar.multi.part02.rar", - "Rar.multi.part03.rar", - "Rar.multi.part04.rar", - "Rar.multi.part05.rar", - "Rar.multi.part06.rar"}); + DoRar_Multi_Reader( + new string[] + { + "Rar.multi.part01.rar", + "Rar.multi.part02.rar", + "Rar.multi.part03.rar", + "Rar.multi.part04.rar", + "Rar.multi.part05.rar", + "Rar.multi.part06.rar" + } + ); } [Fact] public void Rar5_Multi_Reader() { - DoRar_Multi_Reader(new string[] { - "Rar5.multi.part01.rar", - "Rar5.multi.part02.rar", - "Rar5.multi.part03.rar", - "Rar5.multi.part04.rar", - "Rar5.multi.part05.rar", - "Rar5.multi.part06.rar"}); + DoRar_Multi_Reader( + new string[] + { + "Rar5.multi.part01.rar", + "Rar5.multi.part02.rar", + "Rar5.multi.part03.rar", + "Rar5.multi.part04.rar", + "Rar5.multi.part05.rar", + "Rar5.multi.part06.rar" + } + ); } private void DoRar_Multi_Reader(string[] archives) { - using (var reader = RarReader.Open(archives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) - .Select(p => File.OpenRead(p)))) + using ( + var reader = RarReader.Open( + archives + .Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) + .Select(p => File.OpenRead(p)) + ) + ) { while (reader.MoveToNextEntry()) { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -54,81 +66,97 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_Multi_Reader_Encrypted() { - DoRar_Multi_Reader_Encrypted(new string[] { - "Rar.EncryptedParts.part01.rar", - "Rar.EncryptedParts.part02.rar", - "Rar.EncryptedParts.part03.rar", - "Rar.EncryptedParts.part04.rar", - "Rar.EncryptedParts.part05.rar", - "Rar.EncryptedParts.part06.rar"}); + DoRar_Multi_Reader_Encrypted( + new string[] + { + "Rar.EncryptedParts.part01.rar", + "Rar.EncryptedParts.part02.rar", + "Rar.EncryptedParts.part03.rar", + "Rar.EncryptedParts.part04.rar", + "Rar.EncryptedParts.part05.rar", + "Rar.EncryptedParts.part06.rar" + } + ); } private void DoRar_Multi_Reader_Encrypted(string[] archives) { Assert.Throws(() => - { - using (var reader = RarReader.Open(archives.Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) - .Select(p => File.OpenRead(p)), - new ReaderOptions() - { - Password = "test" - })) - { - while (reader.MoveToNextEntry()) - { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); - } - } - VerifyFiles(); - }); + { + using ( + var reader = RarReader.Open( + archives + .Select(s => Path.Combine(TEST_ARCHIVES_PATH, s)) + .Select(p => File.OpenRead(p)), + new ReaderOptions() { Password = "test" } + ) + ) + { + while (reader.MoveToNextEntry()) + { + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); + } + } + VerifyFiles(); + }); } [Fact] public void Rar_Multi_Reader_Delete_Files() { - DoRar_Multi_Reader_Delete_Files(new string[] { - "Rar.multi.part01.rar", - "Rar.multi.part02.rar", - "Rar.multi.part03.rar", - "Rar.multi.part04.rar", - "Rar.multi.part05.rar", - "Rar.multi.part06.rar"}); + DoRar_Multi_Reader_Delete_Files( + new string[] + { + "Rar.multi.part01.rar", + "Rar.multi.part02.rar", + "Rar.multi.part03.rar", + "Rar.multi.part04.rar", + "Rar.multi.part05.rar", + "Rar.multi.part06.rar" + } + ); } [Fact] public void Rar5_Multi_Reader_Delete_Files() { - DoRar_Multi_Reader_Delete_Files(new string[] { - "Rar5.multi.part01.rar", - "Rar5.multi.part02.rar", - "Rar5.multi.part03.rar", - "Rar5.multi.part04.rar", - "Rar5.multi.part05.rar", - "Rar5.multi.part06.rar"}); + DoRar_Multi_Reader_Delete_Files( + new string[] + { + "Rar5.multi.part01.rar", + "Rar5.multi.part02.rar", + "Rar5.multi.part03.rar", + "Rar5.multi.part04.rar", + "Rar5.multi.part05.rar", + "Rar5.multi.part06.rar" + } + ); } private void DoRar_Multi_Reader_Delete_Files(string[] archives) { - foreach (var file in archives) { - File.Copy(Path.Combine(TEST_ARCHIVES_PATH, file), Path.Combine(SCRATCH2_FILES_PATH, file)); + File.Copy( + Path.Combine(TEST_ARCHIVES_PATH, file), + Path.Combine(SCRATCH2_FILES_PATH, file) + ); } - var streams = archives.Select(s => Path.Combine(SCRATCH2_FILES_PATH, s)).Select(File.OpenRead).ToList(); + var streams = archives + .Select(s => Path.Combine(SCRATCH2_FILES_PATH, s)) + .Select(File.OpenRead) + .ToList(); using (var reader = RarReader.Open(streams)) { while (reader.MoveToNextEntry()) { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } foreach (var stream in streams) @@ -233,7 +261,9 @@ namespace SharpCompress.Test.Rar using (var entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); - string folder = Path.GetDirectoryName(reader.Entry.Key) ?? throw new ArgumentNullException(); + string folder = + Path.GetDirectoryName(reader.Entry.Key) + ?? throw new ArgumentNullException(); string destdir = Path.Combine(SCRATCH_FILES_PATH, folder); if (!Directory.Exists(destdir)) { @@ -255,43 +285,48 @@ namespace SharpCompress.Test.Rar [Fact] public void Rar_Reader_Audio_program() { - using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.Audio_program.rar"))) - using (var reader = ReaderFactory.Open(stream, new ReaderOptions() - { - LookForHeader = true - })) + using ( + var stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "Rar.Audio_program.rar") + ) + ) + using ( + var reader = ReaderFactory.Open( + stream, + new ReaderOptions() { LookForHeader = true } + ) + ) { while (reader.MoveToNextEntry()) { Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } - CompareFilesByPath(Path.Combine(SCRATCH_FILES_PATH, "test.dat"), - Path.Combine(MISC_TEST_FILES_PATH, "test.dat")); + CompareFilesByPath( + Path.Combine(SCRATCH_FILES_PATH, "test.dat"), + Path.Combine(MISC_TEST_FILES_PATH, "test.dat") + ); } [Fact] public void Rar_Jpg_Reader() { using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Rar.jpeg.jpg"))) - using (var reader = RarReader.Open(stream, new ReaderOptions() - { - LookForHeader = true - })) + using ( + var reader = RarReader.Open(stream, new ReaderOptions() { LookForHeader = true }) + ) { while (reader.MoveToNextEntry()) { Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -324,21 +359,22 @@ namespace SharpCompress.Test.Rar private void DoRar_Solid_Skip_Reader(string filename) { using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename))) - using (var reader = ReaderFactory.Open(stream, new ReaderOptions() - { - LookForHeader = true - })) + using ( + var reader = ReaderFactory.Open( + stream, + new ReaderOptions() { LookForHeader = true } + ) + ) { while (reader.MoveToNextEntry()) { if (reader.Entry.Key.Contains("jpg")) { Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -359,21 +395,22 @@ namespace SharpCompress.Test.Rar private void DoRar_Reader_Skip(string filename) { using (var stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, filename))) - using (var reader = ReaderFactory.Open(stream, new ReaderOptions() - { - LookForHeader = true - })) + using ( + var reader = ReaderFactory.Open( + stream, + new ReaderOptions() { LookForHeader = true } + ) + ) { while (reader.MoveToNextEntry()) { if (reader.Entry.Key.Contains("jpg")) { Assert.Equal(CompressionType.Rar, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } diff --git a/tests/SharpCompress.Test/ReaderTests.cs b/tests/SharpCompress.Test/ReaderTests.cs index 4d230a20..8d02d1e6 100644 --- a/tests/SharpCompress.Test/ReaderTests.cs +++ b/tests/SharpCompress.Test/ReaderTests.cs @@ -9,7 +9,11 @@ namespace SharpCompress.Test { public abstract class ReaderTests : TestBase { - protected void Read(string testArchive, CompressionType expectedCompression, ReaderOptions? options = null) + protected void Read( + string testArchive, + CompressionType expectedCompression, + ReaderOptions? options = null + ) { testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive); @@ -23,11 +27,20 @@ namespace SharpCompress.Test VerifyFiles(); } - private void ReadImpl(string testArchive, CompressionType expectedCompression, ReaderOptions options) + private void ReadImpl( + string testArchive, + CompressionType expectedCompression, + ReaderOptions options + ) { using (var file = File.OpenRead(testArchive)) { - using (var protectedStream = NonDisposingStream.Create(new ForwardOnlyStream(file), throwOnDispose: true)) + using ( + var protectedStream = NonDisposingStream.Create( + new ForwardOnlyStream(file), + throwOnDispose: true + ) + ) { using (var testStream = new TestStream(protectedStream)) { @@ -35,12 +48,16 @@ namespace SharpCompress.Test { UseReader(reader, expectedCompression); protectedStream.ThrowOnDispose = false; - Assert.False(testStream.IsDisposed, "{nameof(testStream)} prematurely closed"); + Assert.False( + testStream.IsDisposed, + "{nameof(testStream)} prematurely closed" + ); } // Boolean XOR -- If the stream should be left open (true), then the stream should not be diposed (false) // and if the stream should be closed (false), then the stream should be disposed (true) - var message = $"{nameof(options.LeaveStreamOpen)} is set to '{options.LeaveStreamOpen}', so {nameof(testStream.IsDisposed)} should be set to '{!testStream.IsDisposed}', but is set to {testStream.IsDisposed}"; + var message = + $"{nameof(options.LeaveStreamOpen)} is set to '{options.LeaveStreamOpen}', so {nameof(testStream.IsDisposed)} should be set to '{!testStream.IsDisposed}', but is set to {testStream.IsDisposed}"; Assert.True(options.LeaveStreamOpen != testStream.IsDisposed, message); } } @@ -54,11 +71,10 @@ namespace SharpCompress.Test if (!reader.Entry.IsDirectory) { Assert.Equal(expectedCompression, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } diff --git a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index ad1c71ed..4532a613 100644 --- a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -12,11 +12,13 @@ namespace SharpCompress.Test.SevenZip { ArchiveStreamRead("7Zip.solid.7z"); } + [Fact] public void SevenZipArchive_NonSolid_StreamRead() { ArchiveStreamRead("7Zip.nonsolid.7z"); } + [Fact] public void SevenZipArchive_LZMA_StreamRead() { @@ -32,7 +34,10 @@ namespace SharpCompress.Test.SevenZip [Fact] public void SevenZipArchive_LZMAAES_StreamRead() { - ArchiveStreamRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = "testpassword" }); + ArchiveStreamRead( + "7Zip.LZMA.Aes.7z", + new ReaderOptions() { Password = "testpassword" } + ); } [Fact] @@ -40,11 +45,16 @@ namespace SharpCompress.Test.SevenZip { ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = "testpassword" }); } + [Fact] public void SevenZipArchive_LZMAAES_NoPasswordExceptionTest() { - Assert.Throws(typeof(CryptographicException), () => ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = null })); //was failing with ArgumentNullException not CryptographicException like rar + Assert.Throws( + typeof(CryptographicException), + () => ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = null }) + ); //was failing with ArgumentNullException not CryptographicException like rar } + [Fact] public void SevenZipArchive_PPMd_StreamRead() { @@ -108,26 +118,35 @@ namespace SharpCompress.Test.SevenZip [Fact] public void SevenZipArchive_BZip2_Split() { - Assert.Throws(() => ArchiveStreamRead(null, "Original.7z.001", - "Original.7z.002", - "Original.7z.003", - "Original.7z.004", - "Original.7z.005", - "Original.7z.006", - "Original.7z.007")); + Assert.Throws( + () => + ArchiveStreamRead( + null, + "Original.7z.001", + "Original.7z.002", + "Original.7z.003", + "Original.7z.004", + "Original.7z.005", + "Original.7z.006", + "Original.7z.007" + ) + ); } //Same as archive as Original.7z.001 ... 007 files without the root directory 'Original\' in the archive - this caused the verify to fail [Fact] public void SevenZipArchive_BZip2_Split_Working() { - ArchiveStreamMultiRead(null, "7Zip.BZip2.split.001", - "7Zip.BZip2.split.002", - "7Zip.BZip2.split.003", - "7Zip.BZip2.split.004", - "7Zip.BZip2.split.005", - "7Zip.BZip2.split.006", - "7Zip.BZip2.split.007"); + ArchiveStreamMultiRead( + null, + "7Zip.BZip2.split.001", + "7Zip.BZip2.split.002", + "7Zip.BZip2.split.003", + "7Zip.BZip2.split.004", + "7Zip.BZip2.split.005", + "7Zip.BZip2.split.006", + "7Zip.BZip2.split.007" + ); } //will detect and load other files @@ -135,14 +154,12 @@ namespace SharpCompress.Test.SevenZip public void SevenZipArchive_BZip2_Split_FirstFileRead() { ArchiveFileRead("7Zip.BZip2.split.001"); - //"7Zip.BZip2.split.002", - //"7Zip.BZip2.split.003", - //"7Zip.BZip2.split.004", - //"7Zip.BZip2.split.005", - //"7Zip.BZip2.split.006", - //"7Zip.BZip2.split.007" + //"7Zip.BZip2.split.002", + //"7Zip.BZip2.split.003", + //"7Zip.BZip2.split.004", + //"7Zip.BZip2.split.005", + //"7Zip.BZip2.split.006", + //"7Zip.BZip2.split.007" } - - } } diff --git a/tests/SharpCompress.Test/Streams/LzmaStreamTests.cs b/tests/SharpCompress.Test/Streams/LzmaStreamTests.cs index fd14be48..54ac757b 100644 --- a/tests/SharpCompress.Test/Streams/LzmaStreamTests.cs +++ b/tests/SharpCompress.Test/Streams/LzmaStreamTests.cs @@ -1,4 +1,3 @@ - using System; using System.IO; using SharpCompress.Compressors.LZMA; @@ -19,44 +18,497 @@ namespace SharpCompress.Test.Streams Assert.Equal('X', decompressor.ReadByte()); } - private static byte[] lzmaData { get; } = new byte[] { - 0x5D, 0x00, 0x20, 0x00, 0x00, 0x48, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x24, 0x18, 0x2F, 0xEB, 0x20, 0x78, 0xBA, 0x78, 0x70, 0xDC, 0x43, 0x2C, 0x32, 0xC9, - 0xC3, 0x97, 0x4D, 0x10, 0x74, 0xE2, 0x20, 0xBF, 0x5A, 0xB4, 0xB3, 0xC4, 0x31, 0x80, 0x26, - 0x3E, 0x6A, 0xEA, 0x51, 0xFC, 0xE4, 0x8D, 0x54, 0x96, 0x05, 0xCC, 0x78, 0x59, 0xAC, 0xD4, - 0x21, 0x65, 0x8F, 0xA9, 0xC8, 0x0D, 0x9B, 0xE2, 0xC2, 0xF9, 0x7C, 0x3C, 0xDD, 0x4D, 0x38, - 0x04, 0x0B, 0xF8, 0x0B, 0x68, 0xA5, 0x93, 0x6C, 0x64, 0xAC, 0xCF, 0x71, 0x68, 0xE8, 0x69, - 0x25, 0xC6, 0x17, 0x28, 0xF1, 0x7C, 0xF1, 0xDC, 0x47, 0x51, 0x4D, 0x1E, 0x0E, 0x0B, 0x80, - 0x37, 0x24, 0x58, 0x80, 0xF7, 0xB4, 0xAC, 0x54, 0xF1, 0x0F, 0x7F, 0x0F, 0x0F, 0xF5, 0x9C, - 0xDE, 0x54, 0x4F, 0xA3, 0x7B, 0x20, 0xC5, 0xA8, 0x18, 0x3B, 0xED, 0xDC, 0x04, 0xF6, 0xFB, - 0x86, 0xE0, 0xAB, 0xB6, 0x87, 0x99, 0x92, 0x43, 0x7B, 0x2C, 0xCC, 0x31, 0x83, 0x90, 0xFF, - 0xF1, 0x76, 0x03, 0x90 - }; + private static byte[] lzmaData { get; } = + new byte[] + { + 0x5D, + 0x00, + 0x20, + 0x00, + 0x00, + 0x48, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x80, + 0x24, + 0x18, + 0x2F, + 0xEB, + 0x20, + 0x78, + 0xBA, + 0x78, + 0x70, + 0xDC, + 0x43, + 0x2C, + 0x32, + 0xC9, + 0xC3, + 0x97, + 0x4D, + 0x10, + 0x74, + 0xE2, + 0x20, + 0xBF, + 0x5A, + 0xB4, + 0xB3, + 0xC4, + 0x31, + 0x80, + 0x26, + 0x3E, + 0x6A, + 0xEA, + 0x51, + 0xFC, + 0xE4, + 0x8D, + 0x54, + 0x96, + 0x05, + 0xCC, + 0x78, + 0x59, + 0xAC, + 0xD4, + 0x21, + 0x65, + 0x8F, + 0xA9, + 0xC8, + 0x0D, + 0x9B, + 0xE2, + 0xC2, + 0xF9, + 0x7C, + 0x3C, + 0xDD, + 0x4D, + 0x38, + 0x04, + 0x0B, + 0xF8, + 0x0B, + 0x68, + 0xA5, + 0x93, + 0x6C, + 0x64, + 0xAC, + 0xCF, + 0x71, + 0x68, + 0xE8, + 0x69, + 0x25, + 0xC6, + 0x17, + 0x28, + 0xF1, + 0x7C, + 0xF1, + 0xDC, + 0x47, + 0x51, + 0x4D, + 0x1E, + 0x0E, + 0x0B, + 0x80, + 0x37, + 0x24, + 0x58, + 0x80, + 0xF7, + 0xB4, + 0xAC, + 0x54, + 0xF1, + 0x0F, + 0x7F, + 0x0F, + 0x0F, + 0xF5, + 0x9C, + 0xDE, + 0x54, + 0x4F, + 0xA3, + 0x7B, + 0x20, + 0xC5, + 0xA8, + 0x18, + 0x3B, + 0xED, + 0xDC, + 0x04, + 0xF6, + 0xFB, + 0x86, + 0xE0, + 0xAB, + 0xB6, + 0x87, + 0x99, + 0x92, + 0x43, + 0x7B, + 0x2C, + 0xCC, + 0x31, + 0x83, + 0x90, + 0xFF, + 0xF1, + 0x76, + 0x03, + 0x90 + }; - private static byte[] lzmaResultData { get; } = new byte[] { - 0x01, 0x00, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFA, 0x61, 0x18, 0x5F, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x02, 0x00, 0xB4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x61, 0xE5, 0x5E, 0x03, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x02, 0x00, 0xB4, 0x01, 0x00, 0x00, 0x00, 0x00, 0xE2, 0x61, 0x18, - 0x5F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, - 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x01, 0x00, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x14, - 0x62, 0x18, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00, 0xB4, 0x01, 0x00, 0x00, 0x00, - 0x00, 0x7F, 0x61, 0xE5, 0x5E, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x3B, 0x00, 0x00, 0x00, 0xCB, 0x15, 0x00, 0x00, 0x02, 0x00, 0xB4, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x7F, 0x61, 0xE5, 0x5E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x3B, 0x00, 0x00, 0x00, 0xCB, 0x15, 0x00, 0x00, 0x02, 0x00, 0xB4, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x61, 0xE5, 0x5E, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x02, - 0x00, 0xB4, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x96, 0x40, 0x5C, 0x08, 0x00, 0x00, 0x00, - 0x60, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x83, 0x12, - 0x00, 0xD4, 0x99, 0x00, 0x00, 0x43, 0x95, 0x00, 0x00, 0xEB, 0x7A, 0x00, 0x00, 0x40, 0x6F, - 0x00, 0x00, 0xD2, 0x6F, 0x00, 0x00, 0x67, 0x74, 0x00, 0x00, 0x02, 0x69, 0x00, 0x00, 0x76, - 0x79, 0x00, 0x00, 0x98, 0x66, 0x00, 0x00, 0x23, 0x25, 0x00, 0x00, 0x01, 0x00, 0xFD, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x3B, 0x2F, 0xC0, 0x5F, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x03, 0x00, 0x00, 0x00, 0x69, 0x00, 0x3D, 0x00, 0x0A, 0x00, 0x00, 0x00 - }; + private static byte[] lzmaResultData { get; } = + new byte[] + { + 0x01, + 0x00, + 0xFD, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0xFA, + 0x61, + 0x18, + 0x5F, + 0x02, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x03, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0xB4, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3D, + 0x61, + 0xE5, + 0x5E, + 0x03, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0xB4, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0xE2, + 0x61, + 0x18, + 0x5F, + 0x04, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x29, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0xFD, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x14, + 0x62, + 0x18, + 0x5F, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x03, + 0x00, + 0x00, + 0x00, + 0x40, + 0x00, + 0x00, + 0x00, + 0x09, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0xB4, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x7F, + 0x61, + 0xE5, + 0x5E, + 0x05, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3B, + 0x00, + 0x00, + 0x00, + 0xCB, + 0x15, + 0x00, + 0x00, + 0x02, + 0x00, + 0xB4, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x7F, + 0x61, + 0xE5, + 0x5E, + 0x06, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3B, + 0x00, + 0x00, + 0x00, + 0xCB, + 0x15, + 0x00, + 0x00, + 0x02, + 0x00, + 0xB4, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3D, + 0x61, + 0xE5, + 0x5E, + 0x07, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x12, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0xB4, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0xFC, + 0x96, + 0x40, + 0x5C, + 0x08, + 0x00, + 0x00, + 0x00, + 0x60, + 0x00, + 0x00, + 0x00, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0x00, + 0x00, + 0x00, + 0x00, + 0xF8, + 0x83, + 0x12, + 0x00, + 0xD4, + 0x99, + 0x00, + 0x00, + 0x43, + 0x95, + 0x00, + 0x00, + 0xEB, + 0x7A, + 0x00, + 0x00, + 0x40, + 0x6F, + 0x00, + 0x00, + 0xD2, + 0x6F, + 0x00, + 0x00, + 0x67, + 0x74, + 0x00, + 0x00, + 0x02, + 0x69, + 0x00, + 0x00, + 0x76, + 0x79, + 0x00, + 0x00, + 0x98, + 0x66, + 0x00, + 0x00, + 0x23, + 0x25, + 0x00, + 0x00, + 0x01, + 0x00, + 0xFD, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3B, + 0x2F, + 0xC0, + 0x5F, + 0x09, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x03, + 0x00, + 0x00, + 0x00, + 0x69, + 0x00, + 0x3D, + 0x00, + 0x0A, + 0x00, + 0x00, + 0x00 + }; [Fact] public void TestLzmaBuffer() diff --git a/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs b/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs index 51d2085b..99bdeb38 100644 --- a/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs +++ b/tests/SharpCompress.Test/Streams/ZlibBaseStreamTests.cs @@ -13,7 +13,29 @@ namespace SharpCompress.Test.Streams [Fact] public void TestChunkedZlibCompressesEverything() { - byte[] plainData = new byte[] { 0xf7, 0x1b, 0xda, 0x0f, 0xb6, 0x2b, 0x3d, 0x91, 0xd7, 0xe1, 0xb5, 0x11, 0x34, 0x5a, 0x51, 0x3f, 0x8b, 0xce, 0x49, 0xd2 }; + byte[] plainData = new byte[] + { + 0xf7, + 0x1b, + 0xda, + 0x0f, + 0xb6, + 0x2b, + 0x3d, + 0x91, + 0xd7, + 0xe1, + 0xb5, + 0x11, + 0x34, + 0x5a, + 0x51, + 0x3f, + 0x8b, + 0xce, + 0x49, + 0xd2 + }; byte[] buf = new byte[plainData.Length * 2]; MemoryStream plainStream1 = new MemoryStream(plainData); @@ -34,11 +56,11 @@ namespace SharpCompress.Test.Streams Assert.Equal(total, realCompressedSize); } - + [Fact] public void Zlib_should_read_the_previously_written_message() { - var message = new string('a', 131073); // 131073 causes the failure, but 131072 (-1) doesn't + var message = new string('a', 131073); // 131073 causes the failure, but 131072 (-1) doesn't var bytes = Encoding.ASCII.GetBytes(message); using (var inputStream = new MemoryStream(bytes)) @@ -63,7 +85,13 @@ namespace SharpCompress.Test.Streams private void Compress(Stream input, Stream output, int compressionLevel) { - using (var zlibStream = new ZlibStream(NonDisposingStream.Create(output), CompressionMode.Compress, (CompressionLevel)compressionLevel)) + using ( + var zlibStream = new ZlibStream( + NonDisposingStream.Create(output), + CompressionMode.Compress, + (CompressionLevel)compressionLevel + ) + ) { zlibStream.FlushMode = FlushType.Sync; input.CopyTo(zlibStream); @@ -72,7 +100,12 @@ namespace SharpCompress.Test.Streams private void Decompress(Stream input, Stream output) { - using (var zlibStream = new ZlibStream(NonDisposingStream.Create(input), CompressionMode.Decompress)) + using ( + var zlibStream = new ZlibStream( + NonDisposingStream.Create(input), + CompressionMode.Decompress + ) + ) { zlibStream.CopyTo(output); } diff --git a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs index 17da414d..45b32694 100644 --- a/tests/SharpCompress.Test/Tar/TarArchiveTests.cs +++ b/tests/SharpCompress.Test/Tar/TarArchiveTests.cs @@ -37,9 +37,9 @@ namespace SharpCompress.Test.Tar { string archive = "Tar_FileName_Exactly_100_Characters.tar"; - // create the 100 char filename - string filename = "filename_with_exactly_100_characters_______________________________________________________________X"; + string filename = + "filename_with_exactly_100_characters_______________________________________________________________X"; // Step 1: create a tar file containing a file with the test name using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive))) @@ -63,7 +63,10 @@ namespace SharpCompress.Test.Tar foreach (var entry in archive2.Entries) { - Assert.Equal("dummy filecontent", new StreamReader(entry.OpenEntryStream()).ReadLine()); + Assert.Equal( + "dummy filecontent", + new StreamReader(entry.OpenEntryStream()).ReadLine() + ); } } } @@ -76,7 +79,10 @@ namespace SharpCompress.Test.Tar { Assert.Equal(5, archive.Entries.Count); Assert.Contains("very long filename/", archive.Entries.Select(entry => entry.Key)); - Assert.Contains("very long filename/very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename.jpg", archive.Entries.Select(entry => entry.Key)); + Assert.Contains( + "very long filename/very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename.jpg", + archive.Entries.Select(entry => entry.Key) + ); Assert.Contains("z_file 1.txt", archive.Entries.Select(entry => entry.Key)); Assert.Contains("z_file 2.txt", archive.Entries.Select(entry => entry.Key)); Assert.Contains("z_file 3.txt", archive.Entries.Select(entry => entry.Key)); @@ -88,7 +94,6 @@ namespace SharpCompress.Test.Tar { string archive = "Tar_VeryLongFilepathReadback.tar"; - // create a very long filename string longFilename = ""; for (int i = 0; i < 600; i = longFilename.Length) @@ -120,7 +125,10 @@ namespace SharpCompress.Test.Tar foreach (var entry in archive2.Entries) { - Assert.Equal("dummy filecontent", new StreamReader(entry.OpenEntryStream()).ReadLine()); + Assert.Equal( + "dummy filecontent", + new StreamReader(entry.OpenEntryStream()).ReadLine() + ); } } } @@ -133,11 +141,26 @@ namespace SharpCompress.Test.Tar { Assert.Equal(6, archive.Entries.Count); Assert.Contains("Directory/", archive.Entries.Select(entry => entry.Key)); - Assert.Contains("Directory/Some file with veeeeeeeeeery loooooooooong name", archive.Entries.Select(entry => entry.Key)); - Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/", archive.Entries.Select(entry => entry.Key)); - Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name", archive.Entries.Select(entry => entry.Key)); - Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/", archive.Entries.Select(entry => entry.Key)); - Assert.Contains("Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name", archive.Entries.Select(entry => entry.Key)); + Assert.Contains( + "Directory/Some file with veeeeeeeeeery loooooooooong name", + archive.Entries.Select(entry => entry.Key) + ); + Assert.Contains( + "Directory/Directory with veeeeeeeeeery loooooooooong name/", + archive.Entries.Select(entry => entry.Key) + ); + Assert.Contains( + "Directory/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name", + archive.Entries.Select(entry => entry.Key) + ); + Assert.Contains( + "Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/", + archive.Entries.Select(entry => entry.Key) + ); + Assert.Contains( + "Directory/Directory with veeeeeeeeeery loooooooooong name/Directory with veeeeeeeeeery loooooooooong name/Some file with veeeeeeeeeery loooooooooong name", + archive.Entries.Select(entry => entry.Key) + ); } } @@ -161,6 +184,7 @@ namespace SharpCompress.Test.Tar } CompareArchivesByPath(unmodified, scratchPath); } + [Fact] public void Tar_Random_Write_Add() { @@ -186,7 +210,9 @@ namespace SharpCompress.Test.Tar using (var archive = TarArchive.Open(unmodified)) { - var entry = archive.Entries.Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)); + var entry = archive.Entries.Single( + x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ); archive.RemoveEntry(entry); archive.SaveTo(scratchPath, CompressionType.None); } @@ -214,6 +240,7 @@ namespace SharpCompress.Test.Tar Assert.True(archive.Type == ArchiveType.Tar); } } + [Theory] [InlineData(10)] [InlineData(128)] @@ -221,10 +248,7 @@ namespace SharpCompress.Test.Tar { using (var mstm = new MemoryStream()) { - var enc = new ArchiveEncoding() - { - Default = Encoding.UTF8 - }; + var enc = new ArchiveEncoding() { Default = Encoding.UTF8 }; var twopt = new TarWriterOptions(CompressionType.None, true); twopt.ArchiveEncoding = enc; var fname = new string((char)0x3042, length); @@ -235,10 +259,7 @@ namespace SharpCompress.Test.Tar } using (var inputMemory = new MemoryStream(mstm.ToArray())) { - var tropt = new ReaderOptions() - { - ArchiveEncoding = enc - }; + var tropt = new ReaderOptions() { ArchiveEncoding = enc }; using (var tr = TarReader.Open(inputMemory, tropt)) { while (tr.MoveToNextEntry()) @@ -254,7 +275,10 @@ namespace SharpCompress.Test.Tar public void Tar_Read_One_At_A_Time() { var archiveEncoding = new ArchiveEncoding { Default = Encoding.UTF8, }; - var tarWriterOptions = new TarWriterOptions(CompressionType.None, true) { ArchiveEncoding = archiveEncoding, }; + var tarWriterOptions = new TarWriterOptions(CompressionType.None, true) + { + ArchiveEncoding = archiveEncoding, + }; var testBytes = Encoding.UTF8.GetBytes("This is a test."); using (var memoryStream = new MemoryStream()) diff --git a/tests/SharpCompress.Test/Tar/TarReaderTests.cs b/tests/SharpCompress.Test/Tar/TarReaderTests.cs index 4e299dd2..966b82bf 100644 --- a/tests/SharpCompress.Test/Tar/TarReaderTests.cs +++ b/tests/SharpCompress.Test/Tar/TarReaderTests.cs @@ -25,7 +25,11 @@ namespace SharpCompress.Test.Tar [Fact] public void Tar_Skip() { - using (Stream stream = new ForwardOnlyStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")))) + using ( + Stream stream = new ForwardOnlyStream( + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")) + ) + ) using (IReader reader = ReaderFactory.Open(stream)) { int x = 0; @@ -36,12 +40,10 @@ namespace SharpCompress.Test.Tar x++; if (x % 2 == 0) { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -86,7 +88,9 @@ namespace SharpCompress.Test.Tar using (var entryStream = reader.OpenEntryStream()) { string file = Path.GetFileName(reader.Entry.Key); - string folder = Path.GetDirectoryName(reader.Entry.Key) ?? throw new ArgumentNullException(); + string folder = + Path.GetDirectoryName(reader.Entry.Key) + ?? throw new ArgumentNullException(); string destdir = Path.Combine(SCRATCH_FILES_PATH, folder); if (!Directory.Exists(destdir)) { @@ -110,7 +114,11 @@ namespace SharpCompress.Test.Tar { var filePaths = new List(); - using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Tar.LongPathsWithLongNameExtension.tar"))) + using ( + Stream stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "Tar.LongPathsWithLongNameExtension.tar") + ) + ) using (var reader = TarReader.Open(stream)) { while (reader.MoveToNextEntry()) @@ -124,8 +132,14 @@ namespace SharpCompress.Test.Tar Assert.Equal(3, filePaths.Count); Assert.Contains("a.txt", filePaths); - Assert.Contains("wp-content/plugins/gravityformsextend/lib/Aws/Symfony/Component/ClassLoader/Tests/Fixtures/Apc/beta/Apc/ApcPrefixCollision/A/B/Bar.php", filePaths); - Assert.Contains("wp-content/plugins/gravityformsextend/lib/Aws/Symfony/Component/ClassLoader/Tests/Fixtures/Apc/beta/Apc/ApcPrefixCollision/A/B/Foo.php", filePaths); + Assert.Contains( + "wp-content/plugins/gravityformsextend/lib/Aws/Symfony/Component/ClassLoader/Tests/Fixtures/Apc/beta/Apc/ApcPrefixCollision/A/B/Bar.php", + filePaths + ); + Assert.Contains( + "wp-content/plugins/gravityformsextend/lib/Aws/Symfony/Component/ClassLoader/Tests/Fixtures/Apc/beta/Apc/ApcPrefixCollision/A/B/Foo.php", + filePaths + ); } [Fact] @@ -174,17 +188,15 @@ namespace SharpCompress.Test.Tar using (var entryStream = reader.OpenEntryStream()) { - - using (FlushOnDisposeStream flushingStream = new FlushOnDisposeStream(entryStream)) + using ( + FlushOnDisposeStream flushingStream = new FlushOnDisposeStream(entryStream) + ) { - // Extract inner.tar.gz using (var innerReader = ReaderFactory.Open(flushingStream)) { - Assert.True(innerReader.MoveToNextEntry()); Assert.Equal("test", innerReader.Entry.Key); - } } } @@ -196,8 +208,13 @@ namespace SharpCompress.Test.Tar public void Tar_GZip_With_Symlink_Entries() { var isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform( - System.Runtime.InteropServices.OSPlatform.Windows); - using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "TarWithSymlink.tar.gz"))) + System.Runtime.InteropServices.OSPlatform.Windows + ); + using ( + Stream stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "TarWithSymlink.tar.gz") + ) + ) using (var reader = TarReader.Open(stream)) { List names = new List(); @@ -207,24 +224,26 @@ namespace SharpCompress.Test.Tar { continue; } - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true, - WriteSymbolicLink = (sourcePath, targetPath) => - { - if (!isWindows) - { - var link = new Mono.Unix.UnixSymbolicLinkInfo(sourcePath); - if (File.Exists(sourcePath)) - { - link.Delete(); // equivalent to ln -s -f - } - link.CreateSymbolicLinkTo(targetPath); - } - } - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() + { + ExtractFullPath = true, + Overwrite = true, + WriteSymbolicLink = (sourcePath, targetPath) => + { + if (!isWindows) + { + var link = new Mono.Unix.UnixSymbolicLinkInfo(sourcePath); + if (File.Exists(sourcePath)) + { + link.Delete(); // equivalent to ln -s -f + } + link.CreateSymbolicLinkTo(targetPath); + } + } + } + ); if (!isWindows) { if (reader.Entry.LinkTarget != null) @@ -236,8 +255,10 @@ namespace SharpCompress.Test.Tar // need to convert the link to an absolute path for comparison var target = reader.Entry.LinkTarget; var realTarget = System.IO.Path.GetFullPath( - System.IO.Path.Combine($"{System.IO.Path.GetDirectoryName(path)}", - target) + System.IO.Path.Combine( + $"{System.IO.Path.GetDirectoryName(path)}", + target + ) ); Assert.Equal(realTarget, link.GetContents().ToString()); @@ -252,6 +273,5 @@ namespace SharpCompress.Test.Tar } } #endif - } } diff --git a/tests/SharpCompress.Test/Tar/TarWriterTests.cs b/tests/SharpCompress.Test/Tar/TarWriterTests.cs index e38e61f9..d9bff3d8 100644 --- a/tests/SharpCompress.Test/Tar/TarWriterTests.cs +++ b/tests/SharpCompress.Test/Tar/TarWriterTests.cs @@ -8,8 +8,7 @@ namespace SharpCompress.Test.Tar { public class TarWriterTests : WriterTests { - public TarWriterTests() - : base(ArchiveType.Tar) + public TarWriterTests() : base(ArchiveType.Tar) { UseExtensionInsteadOfNameToVerify = true; } @@ -17,25 +16,47 @@ namespace SharpCompress.Test.Tar [Fact] public void Tar_Writer() { - Write(CompressionType.None, "Tar.noEmptyDirs.tar", "Tar.noEmptyDirs.tar", Encoding.GetEncoding(866)); + Write( + CompressionType.None, + "Tar.noEmptyDirs.tar", + "Tar.noEmptyDirs.tar", + Encoding.GetEncoding(866) + ); } [Fact] public void Tar_BZip2_Writer() { - Write(CompressionType.BZip2, "Tar.noEmptyDirs.tar.bz2", "Tar.noEmptyDirs.tar.bz2", Encoding.GetEncoding(866)); + Write( + CompressionType.BZip2, + "Tar.noEmptyDirs.tar.bz2", + "Tar.noEmptyDirs.tar.bz2", + Encoding.GetEncoding(866) + ); } [Fact] public void Tar_LZip_Writer() { - Write(CompressionType.LZip, "Tar.noEmptyDirs.tar.lz", "Tar.noEmptyDirs.tar.lz", Encoding.GetEncoding(866)); + Write( + CompressionType.LZip, + "Tar.noEmptyDirs.tar.lz", + "Tar.noEmptyDirs.tar.lz", + Encoding.GetEncoding(866) + ); } [Fact] public void Tar_Rar_Write() { - Assert.Throws(() => Write(CompressionType.Rar, "Zip.ppmd.noEmptyDirs.zip", "Zip.ppmd.noEmptyDirs.zip")); + Assert.Throws( + () => + Write( + CompressionType.Rar, + "Zip.ppmd.noEmptyDirs.zip", + "Zip.ppmd.noEmptyDirs.zip" + ) + ); } [Theory] @@ -44,15 +65,24 @@ namespace SharpCompress.Test.Tar public void Tar_Finalize_Archive(bool finalizeArchive) { using (MemoryStream stream = new MemoryStream()) - using (Stream content = File.OpenRead(Path.Combine(ORIGINAL_FILES_PATH, "jpg", "test.jpg"))) + using ( + Stream content = File.OpenRead(Path.Combine(ORIGINAL_FILES_PATH, "jpg", "test.jpg")) + ) { - using (TarWriter writer = new TarWriter(stream, new TarWriterOptions(CompressionType.None, finalizeArchive))) + using ( + TarWriter writer = new TarWriter( + stream, + new TarWriterOptions(CompressionType.None, finalizeArchive) + ) + ) { writer.Write("doesn't matter", content, null); } var paddedContentWithHeader = content.Length / 512 * 512 + 512 + 512; - var expectedStreamLength = finalizeArchive ? paddedContentWithHeader + 512 * 2 : paddedContentWithHeader; + var expectedStreamLength = finalizeArchive + ? paddedContentWithHeader + 512 * 2 + : paddedContentWithHeader; Assert.Equal(expectedStreamLength, stream.Length); } } diff --git a/tests/SharpCompress.Test/TestBase.cs b/tests/SharpCompress.Test/TestBase.cs index 1ec9a376..455d4845 100644 --- a/tests/SharpCompress.Test/TestBase.cs +++ b/tests/SharpCompress.Test/TestBase.cs @@ -20,7 +20,10 @@ namespace SharpCompress.Test public TestBase() { - var index = AppDomain.CurrentDomain.BaseDirectory.IndexOf("SharpCompress.Test", StringComparison.OrdinalIgnoreCase); + var index = AppDomain.CurrentDomain.BaseDirectory.IndexOf( + "SharpCompress.Test", + StringComparison.OrdinalIgnoreCase + ); var path = AppDomain.CurrentDomain.BaseDirectory.Substring(0, index); SOLUTION_BASE_PATH = Path.GetDirectoryName(path) ?? throw new ArgumentNullException(); @@ -28,7 +31,11 @@ namespace SharpCompress.Test ORIGINAL_FILES_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", "Original"); MISC_TEST_FILES_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", "MiscTest"); - SCRATCH_BASE_PATH = Path.Combine(SOLUTION_BASE_PATH, "TestArchives", Guid.NewGuid().ToString()); + SCRATCH_BASE_PATH = Path.Combine( + SOLUTION_BASE_PATH, + "TestArchives", + Guid.NewGuid().ToString() + ); SCRATCH_FILES_PATH = Path.Combine(SCRATCH_BASE_PATH, "Scratch"); SCRATCH2_FILES_PATH = Path.Combine(SCRATCH_BASE_PATH, "Scratch2"); @@ -70,11 +77,11 @@ namespace SharpCompress.Test protected void VerifyFilesByName() { - var extracted = - Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) + var extracted = Directory + .EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => path.Substring(SCRATCH_FILES_PATH.Length)); - var original = - Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) + var original = Directory + .EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => path.Substring(ORIGINAL_FILES_PATH.Length)); Assert.Equal(extracted.Count, original.Count); @@ -92,11 +99,11 @@ namespace SharpCompress.Test /// protected void VerifyFilesByNameEx() { - var extracted = - Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) + var extracted = Directory + .EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => path.Substring(SCRATCH_FILES_PATH.Length)); - var original = - Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) + var original = Directory + .EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => path.Substring(ORIGINAL_FILES_PATH.Length)); Assert.Equal(extracted.Count, original.Count); @@ -115,11 +122,11 @@ namespace SharpCompress.Test /// protected void VerifyFilesByExtensionEx() { - var extracted = - Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) + var extracted = Directory + .EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => Path.GetExtension(path)); - var original = - Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) + var original = Directory + .EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => Path.GetExtension(path)); Assert.Equal(extracted.Count, original.Count); @@ -137,11 +144,11 @@ namespace SharpCompress.Test protected void VerifyFilesByExtension() { - var extracted = - Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) + var extracted = Directory + .EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => Path.GetExtension(path)); - var original = - Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) + var original = Directory + .EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories) .ToLookup(path => Path.GetExtension(path)); Assert.Equal(extracted.Count, original.Count); @@ -215,6 +222,5 @@ namespace SharpCompress.Test Assert.Equal(archive1Entries[i], archive2Entries[i]); } } - } } diff --git a/tests/SharpCompress.Test/WriterTests.cs b/tests/SharpCompress.Test/WriterTests.cs index c38fed29..ad322949 100644 --- a/tests/SharpCompress.Test/WriterTests.cs +++ b/tests/SharpCompress.Test/WriterTests.cs @@ -16,7 +16,12 @@ namespace SharpCompress.Test this.type = type; } - protected void Write(CompressionType compressionType, string archive, string archiveToVerifyAgainst, Encoding? encoding = null) + protected void Write( + CompressionType compressionType, + string archive, + string archiveToVerifyAgainst, + Encoding? encoding = null + ) { using (Stream stream = File.OpenWrite(Path.Combine(SCRATCH2_FILES_PATH, archive))) { @@ -32,8 +37,10 @@ namespace SharpCompress.Test writer.WriteAll(ORIGINAL_FILES_PATH, "*", SearchOption.AllDirectories); } } - CompareArchivesByPath(Path.Combine(SCRATCH2_FILES_PATH, archive), - Path.Combine(TEST_ARCHIVES_PATH, archiveToVerifyAgainst)); + CompareArchivesByPath( + Path.Combine(SCRATCH2_FILES_PATH, archive), + Path.Combine(TEST_ARCHIVES_PATH, archiveToVerifyAgainst) + ); using (Stream stream = File.OpenRead(Path.Combine(SCRATCH2_FILES_PATH, archive))) { @@ -41,12 +48,17 @@ namespace SharpCompress.Test readerOptions.ArchiveEncoding.Default = encoding ?? Encoding.Default; - using (var reader = ReaderFactory.Open(NonDisposingStream.Create(stream), readerOptions)) + using ( + var reader = ReaderFactory.Open( + NonDisposingStream.Create(stream), + readerOptions + ) + ) { - reader.WriteAllToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true - }); + reader.WriteAllToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true } + ); } } VerifyFiles(); diff --git a/tests/SharpCompress.Test/Xz/Crc32Tests.cs b/tests/SharpCompress.Test/Xz/Crc32Tests.cs index 95082872..7afa27a1 100644 --- a/tests/SharpCompress.Test/Xz/Crc32Tests.cs +++ b/tests/SharpCompress.Test/Xz/Crc32Tests.cs @@ -9,7 +9,8 @@ namespace SharpCompress.Test.Xz { private const string SimpleString = @"The quick brown fox jumps over the lazy dog."; private readonly byte[] SimpleBytes = Encoding.ASCII.GetBytes(SimpleString); - private const string SimpleString2 = @"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it."; + private const string SimpleString2 = + @"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it."; private readonly byte[] SimpleBytes2 = Encoding.ASCII.GetBytes(SimpleString2); [Fact] @@ -27,6 +28,5 @@ namespace SharpCompress.Test.Xz Assert.Equal((UInt32)0x6ee3ad88, actual); } - } } diff --git a/tests/SharpCompress.Test/Xz/Crc64Tests.cs b/tests/SharpCompress.Test/Xz/Crc64Tests.cs index 3095dba4..f4ef9493 100644 --- a/tests/SharpCompress.Test/Xz/Crc64Tests.cs +++ b/tests/SharpCompress.Test/Xz/Crc64Tests.cs @@ -9,7 +9,8 @@ namespace SharpCompress.Test.Xz { private const string SimpleString = @"The quick brown fox jumps over the lazy dog."; private readonly byte[] SimpleBytes = Encoding.ASCII.GetBytes(SimpleString); - private const string SimpleString2 = @"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it."; + private const string SimpleString2 = + @"Life moves pretty fast. If you don't stop and look around once in a while, you could miss it."; private readonly byte[] SimpleBytes2 = Encoding.ASCII.GetBytes(SimpleString2); [Fact] @@ -27,6 +28,5 @@ namespace SharpCompress.Test.Xz Assert.Equal((UInt64)0x416B4150508661EE, actual); } - } } diff --git a/tests/SharpCompress.Test/Xz/Filters/BCJTests.cs b/tests/SharpCompress.Test/Xz/Filters/BCJTests.cs index c562a43b..a18005dd 100644 --- a/tests/SharpCompress.Test/Xz/Filters/BCJTests.cs +++ b/tests/SharpCompress.Test/Xz/Filters/BCJTests.cs @@ -17,6 +17,7 @@ namespace SharpCompress.Test.Xz.Filters private readonly PowerPCFilter ppcFilter; private readonly SparcFilter sparcFilter; private readonly X86Filter x86Filter; + public BCJTests() { armFilter = new ArmFilter(); diff --git a/tests/SharpCompress.Test/Xz/XZBlockTests.cs b/tests/SharpCompress.Test/Xz/XZBlockTests.cs index 97e2f704..0e070c67 100644 --- a/tests/SharpCompress.Test/Xz/XZBlockTests.cs +++ b/tests/SharpCompress.Test/Xz/XZBlockTests.cs @@ -36,7 +36,10 @@ namespace SharpCompress.Test.Xz using (Stream indexBlockStream = new MemoryStream(bytes)) { var XZBlock = new XZBlock(indexBlockStream, CheckType.CRC64, 8); - Assert.Throws(() => { ReadBytes(XZBlock, 1); }); + Assert.Throws(() => + { + ReadBytes(XZBlock, 1); + }); } } @@ -49,7 +52,10 @@ namespace SharpCompress.Test.Xz { Rewind(badCrcStream); var XZBlock = new XZBlock(badCrcStream, CheckType.CRC64, 8); - var ex = Assert.Throws(() => { ReadBytes(XZBlock, 1); }); + var ex = Assert.Throws(() => + { + ReadBytes(XZBlock, 1); + }); Assert.Equal("Block header corrupt", ex.Message); } } diff --git a/tests/SharpCompress.Test/Xz/XZHeaderTests.cs b/tests/SharpCompress.Test/Xz/XZHeaderTests.cs index 026c0c17..30893fbc 100644 --- a/tests/SharpCompress.Test/Xz/XZHeaderTests.cs +++ b/tests/SharpCompress.Test/Xz/XZHeaderTests.cs @@ -15,7 +15,10 @@ namespace SharpCompress.Test.Xz { BinaryReader br = new BinaryReader(badMagicNumberStream); var header = new XZHeader(br); - var ex = Assert.Throws(() => { header.Process(); }); + var ex = Assert.Throws(() => + { + header.Process(); + }); Assert.Equal("Invalid XZ Stream", ex.Message); } } @@ -29,7 +32,10 @@ namespace SharpCompress.Test.Xz { BinaryReader br = new BinaryReader(badCrcStream); var header = new XZHeader(br); - var ex = Assert.Throws(() => { header.Process(); }); + var ex = Assert.Throws(() => + { + header.Process(); + }); Assert.Equal("Stream header corrupt", ex.Message); } } @@ -46,7 +52,10 @@ namespace SharpCompress.Test.Xz { BinaryReader br = new BinaryReader(badFlagStream); var header = new XZHeader(br); - var ex = Assert.Throws(() => { header.Process(); }); + var ex = Assert.Throws(() => + { + header.Process(); + }); Assert.Equal("Unknown XZ Stream Version", ex.Message); } } diff --git a/tests/SharpCompress.Test/Xz/XZIndexTests.cs b/tests/SharpCompress.Test/Xz/XZIndexTests.cs index 543f984e..898d71f4 100644 --- a/tests/SharpCompress.Test/Xz/XZIndexTests.cs +++ b/tests/SharpCompress.Test/Xz/XZIndexTests.cs @@ -83,7 +83,26 @@ namespace SharpCompress.Test.Xz public void SkipsPadding() { // Index with 3-byte padding. - using (Stream badStream = new MemoryStream(new byte[] { 0x00, 0x01, 0x10, 0x80, 0x01, 0x00, 0x00, 0x00, 0xB1, 0x01, 0xD9, 0xC9, 0xFF })) + using ( + Stream badStream = new MemoryStream( + new byte[] + { + 0x00, + 0x01, + 0x10, + 0x80, + 0x01, + 0x00, + 0x00, + 0x00, + 0xB1, + 0x01, + 0xD9, + 0xC9, + 0xFF + } + ) + ) { BinaryReader br = new BinaryReader(badStream); var index = new XZIndex(br, false); diff --git a/tests/SharpCompress.Test/Xz/XZTestsBase.cs b/tests/SharpCompress.Test/Xz/XZTestsBase.cs index a0e3032e..e5a3b53c 100644 --- a/tests/SharpCompress.Test/Xz/XZTestsBase.cs +++ b/tests/SharpCompress.Test/Xz/XZTestsBase.cs @@ -37,10 +37,42 @@ namespace SharpCompress.Test.Xz protected Stream CompressedEmptyStream { get; } = new MemoryStream(CompressedEmpty); - protected static byte[] CompressedEmpty { get; } = new byte[] { - 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x01, 0x69, 0x22, 0xde, 0x36, 0x00, 0x00, 0x00, 0x00, - 0x1c, 0xdf, 0x44, 0x21, 0x90, 0x42, 0x99, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x59, 0x5a - }; + protected static byte[] CompressedEmpty { get; } = + new byte[] + { + 0xfd, + 0x37, + 0x7a, + 0x58, + 0x5a, + 0x00, + 0x00, + 0x01, + 0x69, + 0x22, + 0xde, + 0x36, + 0x00, + 0x00, + 0x00, + 0x00, + 0x1c, + 0xdf, + 0x44, + 0x21, + 0x90, + 0x42, + 0x99, + 0x0d, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x59, + 0x5a + }; protected static byte[] OriginalEmptyBytes => Encoding.ASCII.GetBytes(OriginalEmpty); @@ -48,102 +80,1071 @@ namespace SharpCompress.Test.Xz protected Stream CompressedStream { get; } = new MemoryStream(Compressed); - protected static byte[] Compressed { get; } = new byte[] { - 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x04, 0xe6, 0xd6, 0xb4, 0x46, 0x02, 0x00, 0x21, 0x01, - 0x16, 0x00, 0x00, 0x00, 0x74, 0x2f, 0xe5, 0xa3, 0xe0, 0x01, 0xe4, 0x01, 0x3c, 0x5d, 0x00, 0x26, - 0x98, 0x4a, 0x47, 0xc6, 0x6a, 0x27, 0xd7, 0x36, 0x7a, 0x05, 0xb9, 0x4f, 0xd7, 0xde, 0x52, 0x4c, - 0xca, 0x26, 0x4f, 0x23, 0x60, 0x4d, 0xf3, 0x1f, 0xa3, 0x67, 0x49, 0x53, 0xd0, 0xf5, 0xc7, 0xa9, - 0x3e, 0xd6, 0xb5, 0x3d, 0x2b, 0x02, 0xbe, 0x83, 0x27, 0xe2, 0xa6, 0xc3, 0x13, 0x4a, 0x31, 0x14, - 0x33, 0xed, 0x9a, 0x85, 0x1d, 0x05, 0x6e, 0x7e, 0xa4, 0x91, 0xbf, 0x46, 0x71, 0x7d, 0xa7, 0xfb, - 0x12, 0x10, 0xdf, 0x21, 0x73, 0x75, 0xd8, 0xd9, 0xab, 0x8f, 0x1f, 0x8b, 0xb0, 0xb9, 0x3f, 0x9a, - 0xa5, 0x1e, 0xd4, 0x2f, 0xdf, 0x09, 0xb3, 0xfe, 0x45, 0xef, 0x16, 0xec, 0x95, 0x68, 0x64, 0xbb, - 0x42, 0x0c, 0x8b, 0x96, 0x27, 0x30, 0x62, 0x42, 0x91, 0x7c, 0xf3, 0x6e, 0x4d, 0x03, 0xc5, 0x00, - 0x04, 0x73, 0xdd, 0xee, 0xb0, 0xaa, 0xd6, 0x0b, 0x11, 0x90, 0x81, 0xd4, 0xaa, 0x69, 0x63, 0xfa, - 0x2f, 0xb4, 0x25, 0x0a, 0x7f, 0xf9, 0x47, 0x77, 0xb1, 0x1f, 0xc3, 0xb4, 0x4d, 0x51, 0xf8, 0x23, - 0x3a, 0x7c, 0x44, 0xc8, 0xcc, 0xca, 0x72, 0x09, 0xae, 0xc9, 0x7b, 0x7e, 0x91, 0x5d, 0xff, 0xc4, - 0xeb, 0xfd, 0xa1, 0x9b, 0xd4, 0x8d, 0xd7, 0xd3, 0x57, 0xac, 0x7e, 0x3b, 0x97, 0x2e, 0xe4, 0xc2, - 0x2e, 0x93, 0x3d, 0xb0, 0x16, 0x64, 0x78, 0x45, 0xb1, 0xc9, 0x40, 0x96, 0xcf, 0x5b, 0xc2, 0x2f, - 0xaa, 0xba, 0xcf, 0x98, 0x38, 0x21, 0x3d, 0x1a, 0x13, 0xe8, 0xa6, 0xa6, 0xdf, 0xf4, 0x3d, 0x01, - 0xa1, 0x9d, 0xc1, 0x3e, 0x37, 0xac, 0x20, 0xc4, 0xef, 0x18, 0xb1, 0xeb, 0x35, 0xf4, 0x66, 0x9a, - 0x47, 0x3c, 0xce, 0x7c, 0xad, 0xdb, 0x2e, 0x39, 0xf5, 0x8d, 0x4a, 0x1d, 0x65, 0xc2, 0x0f, 0xa4, - 0x40, 0x7e, 0xe6, 0xa7, 0x17, 0xce, 0x75, 0x7f, 0xd9, 0xa3, 0xf9, 0x27, 0x42, 0xd7, 0x98, 0x54, - 0x17, 0xa7, 0x7a, 0x7c, 0x82, 0xdf, 0xeb, 0x08, 0x28, 0x86, 0xdd, 0x57, 0x77, 0x92, 0x80, 0x5f, - 0x7b, 0x3b, 0xce, 0x77, 0x72, 0xff, 0xa3, 0x85, 0xd8, 0x5c, 0x8a, 0xb7, 0x83, 0x58, 0xfa, 0xbd, - 0x72, 0xe3, 0x66, 0x9d, 0x3b, 0xff, 0x13, 0x5b, 0x0b, 0xf1, 0x6c, 0xa6, 0xb1, 0x3b, 0x85, 0x3b, - 0x47, 0x91, 0xc8, 0x7c, 0x38, 0xe2, 0xe5, 0x54, 0xf8, 0x27, 0xee, 0x00, 0xff, 0xd3, 0x68, 0xf1, - 0xc6, 0xc7, 0xd7, 0x24, 0x00, 0x01, 0xd8, 0x02, 0xe5, 0x03, 0x00, 0x00, 0xac, 0x16, 0x1f, 0xa4, - 0xb1, 0xc4, 0x67, 0xfb, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x59, 0x5a - }; + protected static byte[] Compressed { get; } = + new byte[] + { + 0xfd, + 0x37, + 0x7a, + 0x58, + 0x5a, + 0x00, + 0x00, + 0x04, + 0xe6, + 0xd6, + 0xb4, + 0x46, + 0x02, + 0x00, + 0x21, + 0x01, + 0x16, + 0x00, + 0x00, + 0x00, + 0x74, + 0x2f, + 0xe5, + 0xa3, + 0xe0, + 0x01, + 0xe4, + 0x01, + 0x3c, + 0x5d, + 0x00, + 0x26, + 0x98, + 0x4a, + 0x47, + 0xc6, + 0x6a, + 0x27, + 0xd7, + 0x36, + 0x7a, + 0x05, + 0xb9, + 0x4f, + 0xd7, + 0xde, + 0x52, + 0x4c, + 0xca, + 0x26, + 0x4f, + 0x23, + 0x60, + 0x4d, + 0xf3, + 0x1f, + 0xa3, + 0x67, + 0x49, + 0x53, + 0xd0, + 0xf5, + 0xc7, + 0xa9, + 0x3e, + 0xd6, + 0xb5, + 0x3d, + 0x2b, + 0x02, + 0xbe, + 0x83, + 0x27, + 0xe2, + 0xa6, + 0xc3, + 0x13, + 0x4a, + 0x31, + 0x14, + 0x33, + 0xed, + 0x9a, + 0x85, + 0x1d, + 0x05, + 0x6e, + 0x7e, + 0xa4, + 0x91, + 0xbf, + 0x46, + 0x71, + 0x7d, + 0xa7, + 0xfb, + 0x12, + 0x10, + 0xdf, + 0x21, + 0x73, + 0x75, + 0xd8, + 0xd9, + 0xab, + 0x8f, + 0x1f, + 0x8b, + 0xb0, + 0xb9, + 0x3f, + 0x9a, + 0xa5, + 0x1e, + 0xd4, + 0x2f, + 0xdf, + 0x09, + 0xb3, + 0xfe, + 0x45, + 0xef, + 0x16, + 0xec, + 0x95, + 0x68, + 0x64, + 0xbb, + 0x42, + 0x0c, + 0x8b, + 0x96, + 0x27, + 0x30, + 0x62, + 0x42, + 0x91, + 0x7c, + 0xf3, + 0x6e, + 0x4d, + 0x03, + 0xc5, + 0x00, + 0x04, + 0x73, + 0xdd, + 0xee, + 0xb0, + 0xaa, + 0xd6, + 0x0b, + 0x11, + 0x90, + 0x81, + 0xd4, + 0xaa, + 0x69, + 0x63, + 0xfa, + 0x2f, + 0xb4, + 0x25, + 0x0a, + 0x7f, + 0xf9, + 0x47, + 0x77, + 0xb1, + 0x1f, + 0xc3, + 0xb4, + 0x4d, + 0x51, + 0xf8, + 0x23, + 0x3a, + 0x7c, + 0x44, + 0xc8, + 0xcc, + 0xca, + 0x72, + 0x09, + 0xae, + 0xc9, + 0x7b, + 0x7e, + 0x91, + 0x5d, + 0xff, + 0xc4, + 0xeb, + 0xfd, + 0xa1, + 0x9b, + 0xd4, + 0x8d, + 0xd7, + 0xd3, + 0x57, + 0xac, + 0x7e, + 0x3b, + 0x97, + 0x2e, + 0xe4, + 0xc2, + 0x2e, + 0x93, + 0x3d, + 0xb0, + 0x16, + 0x64, + 0x78, + 0x45, + 0xb1, + 0xc9, + 0x40, + 0x96, + 0xcf, + 0x5b, + 0xc2, + 0x2f, + 0xaa, + 0xba, + 0xcf, + 0x98, + 0x38, + 0x21, + 0x3d, + 0x1a, + 0x13, + 0xe8, + 0xa6, + 0xa6, + 0xdf, + 0xf4, + 0x3d, + 0x01, + 0xa1, + 0x9d, + 0xc1, + 0x3e, + 0x37, + 0xac, + 0x20, + 0xc4, + 0xef, + 0x18, + 0xb1, + 0xeb, + 0x35, + 0xf4, + 0x66, + 0x9a, + 0x47, + 0x3c, + 0xce, + 0x7c, + 0xad, + 0xdb, + 0x2e, + 0x39, + 0xf5, + 0x8d, + 0x4a, + 0x1d, + 0x65, + 0xc2, + 0x0f, + 0xa4, + 0x40, + 0x7e, + 0xe6, + 0xa7, + 0x17, + 0xce, + 0x75, + 0x7f, + 0xd9, + 0xa3, + 0xf9, + 0x27, + 0x42, + 0xd7, + 0x98, + 0x54, + 0x17, + 0xa7, + 0x7a, + 0x7c, + 0x82, + 0xdf, + 0xeb, + 0x08, + 0x28, + 0x86, + 0xdd, + 0x57, + 0x77, + 0x92, + 0x80, + 0x5f, + 0x7b, + 0x3b, + 0xce, + 0x77, + 0x72, + 0xff, + 0xa3, + 0x85, + 0xd8, + 0x5c, + 0x8a, + 0xb7, + 0x83, + 0x58, + 0xfa, + 0xbd, + 0x72, + 0xe3, + 0x66, + 0x9d, + 0x3b, + 0xff, + 0x13, + 0x5b, + 0x0b, + 0xf1, + 0x6c, + 0xa6, + 0xb1, + 0x3b, + 0x85, + 0x3b, + 0x47, + 0x91, + 0xc8, + 0x7c, + 0x38, + 0xe2, + 0xe5, + 0x54, + 0xf8, + 0x27, + 0xee, + 0x00, + 0xff, + 0xd3, + 0x68, + 0xf1, + 0xc6, + 0xc7, + 0xd7, + 0x24, + 0x00, + 0x01, + 0xd8, + 0x02, + 0xe5, + 0x03, + 0x00, + 0x00, + 0xac, + 0x16, + 0x1f, + 0xa4, + 0xb1, + 0xc4, + 0x67, + 0xfb, + 0x02, + 0x00, + 0x00, + 0x00, + 0x00, + 0x04, + 0x59, + 0x5a + }; protected static byte[] OriginalBytes => Encoding.ASCII.GetBytes(Original); protected static string Original { get; } = - "Mary had a little lamb,\r\n" + - "His fleece was white as snow,\r\n" + - "And everywhere that Mary went,\r\n" + - "The lamb was sure to go.\r\n" + - "\r\n" + - "He followed her to school one day,\r\n" + - "Which was against the rule,\r\n" + - "It made the children laugh and play\r\n" + - "To see a lamb at school.\r\n" + - "\r\n" + - "And so the teacher turned it out,\r\n" + - "But still it lingered near,\r\n" + - "And waited patiently about,\r\n" + - "Till Mary did appear.\r\n" + - "\r\n" + - "\"Why does the lamb love Mary so?\"\r\n" + - "The eager children cry.\r\n" + - "\"Why, Mary loves the lamb, you know.\"\r\n" + - "The teacher did reply."; + "Mary had a little lamb,\r\n" + + "His fleece was white as snow,\r\n" + + "And everywhere that Mary went,\r\n" + + "The lamb was sure to go.\r\n" + + "\r\n" + + "He followed her to school one day,\r\n" + + "Which was against the rule,\r\n" + + "It made the children laugh and play\r\n" + + "To see a lamb at school.\r\n" + + "\r\n" + + "And so the teacher turned it out,\r\n" + + "But still it lingered near,\r\n" + + "And waited patiently about,\r\n" + + "Till Mary did appear.\r\n" + + "\r\n" + + "\"Why does the lamb love Mary so?\"\r\n" + + "The eager children cry.\r\n" + + "\"Why, Mary loves the lamb, you know.\"\r\n" + + "The teacher did reply."; protected Stream CompressedIndexedStream { get; } = new MemoryStream(CompressedIndexed); - protected static byte[] CompressedIndexed { get; } = new byte[] { - 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x01, 0x69, 0x22, 0xde, 0x36, 0x03, 0xc0, 0xe3, 0x02, - 0x80, 0x20, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xe5, 0xd7, 0x32, 0xe0, 0x0f, 0xff, 0x01, - 0x5b, 0x5d, 0x00, 0x26, 0x98, 0x4a, 0x47, 0xc6, 0x6a, 0x27, 0xd7, 0x36, 0x7a, 0x05, 0xb9, 0x4f, - 0xd7, 0xde, 0x3a, 0x0e, 0xee, 0x1b, 0xd7, 0x81, 0xe9, 0xf5, 0x90, 0x1e, 0xd5, 0x9e, 0x88, 0x32, - 0x1c, 0x7b, 0x43, 0x84, 0x02, 0x58, 0x92, 0xcf, 0x97, 0xfc, 0xae, 0x01, 0x83, 0x23, 0x48, 0x93, - 0xc6, 0x56, 0xcc, 0x6d, 0xb1, 0x23, 0x10, 0x24, 0x3b, 0x9e, 0x06, 0xaa, 0xc0, 0xce, 0x86, 0x0a, - 0xb7, 0x9f, 0x99, 0x61, 0xbe, 0x3b, 0x6d, 0xfe, 0x60, 0xef, 0x14, 0x35, 0x7f, 0x21, 0xe8, 0x96, - 0x0e, 0xbd, 0x41, 0x7c, 0x65, 0x89, 0x96, 0x28, 0x5e, 0x85, 0xa6, 0x4b, 0xf3, 0xf9, 0xf8, 0x25, - 0x31, 0x4a, 0xbb, 0x72, 0xce, 0xcf, 0x53, 0xdf, 0x13, 0x42, 0x2d, 0xbc, 0x95, 0xa5, 0x6d, 0xc4, - 0x8c, 0x72, 0x99, 0xe8, 0x9a, 0xcf, 0x80, 0xd4, 0xc4, 0x3f, 0x55, 0xc3, 0x9b, 0x00, 0xce, 0x65, - 0x27, 0x6e, 0xbf, 0xb2, 0x88, 0xab, 0xc0, 0x5f, 0xf9, 0xd0, 0xc8, 0xbb, 0xd7, 0x48, 0xd7, 0x2e, - 0x5e, 0xbb, 0x23, 0x35, 0x6e, 0x62, 0xb6, 0x13, 0xd4, 0x06, 0xd1, 0x5b, 0x97, 0xee, 0x5b, 0x89, - 0x78, 0x07, 0x24, 0x74, 0x59, 0x06, 0x1e, 0x7f, 0x8c, 0xb0, 0x48, 0xff, 0x0a, 0x76, 0xb2, 0x07, - 0xa0, 0x99, 0xf5, 0x4b, 0x68, 0xd4, 0x55, 0x32, 0xb3, 0x17, 0x7b, 0xb6, 0x26, 0xdb, 0x1c, 0xc3, - 0x0b, 0xda, 0x3e, 0x46, 0xba, 0x1a, 0x67, 0x23, 0xb7, 0x2a, 0x40, 0xdc, 0xc9, 0xa2, 0xe4, 0xb5, - 0x68, 0x5c, 0x81, 0x60, 0xa7, 0xad, 0xe6, 0xba, 0xbb, 0x0d, 0x82, 0x8a, 0xe2, 0x03, 0xa9, 0x22, - 0x09, 0x5e, 0xd8, 0x69, 0xfa, 0x29, 0xd1, 0x32, 0xa1, 0xf0, 0x9b, 0x3c, 0xc3, 0x0b, 0x9a, 0x53, - 0xf0, 0x3e, 0xf3, 0x1b, 0x77, 0xee, 0x8f, 0xa6, 0x15, 0x02, 0x77, 0x14, 0x54, 0x60, 0xae, 0xbe, - 0x91, 0x9e, 0xe6, 0x8b, 0x87, 0x6e, 0x46, 0x44, 0x64, 0xc7, 0x58, 0x90, 0x62, 0x25, 0x32, 0xf9, - 0xcd, 0xd2, 0x73, 0x2e, 0x3f, 0xd7, 0x5d, 0x3c, 0x86, 0x1c, 0xa8, 0x35, 0xa9, 0xc2, 0xcb, 0x59, - 0xcb, 0xac, 0xb3, 0x03, 0x12, 0xd4, 0x8a, 0xde, 0xd5, 0xc1, 0xd8, 0x0c, 0x32, 0x49, 0x87, 0x97, - 0x62, 0x4f, 0x32, 0x39, 0x63, 0x5b, 0x8b, 0xd1, 0x6c, 0x5c, 0x90, 0xd9, 0x93, 0x13, 0xae, 0x70, - 0xf5, 0x2f, 0x40, 0xaf, 0x01, 0x95, 0x01, 0x0c, 0xc5, 0xfa, 0x82, 0xf8, 0x71, 0x9d, 0x53, 0xe6, - 0x47, 0x6e, 0x99, 0x54, 0x57, 0x41, 0x72, 0xea, 0xf5, 0x78, 0xdd, 0x86, 0xbd, 0x00, 0x00, 0x00, - 0x72, 0x6a, 0xf2, 0x47, 0x03, 0xc0, 0xcb, 0x01, 0x8d, 0x02, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, - 0xfb, 0xa7, 0xf7, 0x94, 0xe0, 0x01, 0x0c, 0x00, 0xc3, 0x5d, 0x00, 0x06, 0x82, 0xca, 0x9b, 0x77, - 0x93, 0x57, 0xb3, 0x76, 0xbd, 0x8b, 0xcb, 0xee, 0xf4, 0x2c, 0xff, 0x7f, 0x95, 0x33, 0x15, 0x10, - 0xa5, 0xf9, 0xfd, 0xa6, 0xbb, 0x9e, 0xf9, 0x75, 0x67, 0xee, 0xec, 0x8b, 0x40, 0xea, 0x32, 0x47, - 0x3d, 0x26, 0xbe, 0x11, 0x9c, 0xa6, 0x40, 0xbe, 0x84, 0x1f, 0x1b, 0x35, 0x1a, 0x66, 0x10, 0x9c, - 0xf4, 0x12, 0x1a, 0x95, 0x81, 0xb5, 0x55, 0x6b, 0xc5, 0x42, 0xfd, 0x37, 0x70, 0xc5, 0x08, 0xa4, - 0x27, 0x67, 0x11, 0x0b, 0x1f, 0xcc, 0xdb, 0x54, 0x9b, 0x5a, 0x5f, 0xee, 0x21, 0x63, 0xdd, 0x4b, - 0xbc, 0x49, 0x95, 0x6d, 0xf4, 0xcb, 0x9a, 0x9a, 0x5e, 0xe4, 0x7d, 0x0f, 0x02, 0x22, 0xa9, 0x42, - 0x46, 0x1a, 0x04, 0x87, 0x43, 0x72, 0x59, 0xa4, 0xd6, 0xeb, 0x69, 0x36, 0xde, 0xea, 0x53, 0x8c, - 0x89, 0xd7, 0x22, 0xa6, 0xf7, 0xa8, 0x4c, 0x72, 0x6c, 0x80, 0x69, 0x01, 0xb2, 0xa7, 0xe8, 0x8b, - 0x94, 0xaf, 0x0e, 0x47, 0x58, 0x1d, 0x0e, 0x5c, 0x7c, 0x33, 0x9f, 0x21, 0x17, 0x2c, 0x4f, 0x3d, - 0x72, 0xff, 0xcf, 0x7a, 0x4f, 0x82, 0x5b, 0x85, 0x28, 0x70, 0xf4, 0x8c, 0x81, 0x41, 0xb8, 0x20, - 0x5c, 0x3e, 0x02, 0x5e, 0x5a, 0x61, 0xbb, 0x2f, 0x64, 0xc5, 0x4e, 0x53, 0xe4, 0xca, 0xe4, 0xd9, - 0x75, 0xaf, 0x15, 0x4d, 0xff, 0x01, 0xec, 0x13, 0x4a, 0x70, 0x00, 0x04, 0xf9, 0xfa, 0x00, 0x00, - 0x99, 0x57, 0xc4, 0x96, 0x00, 0x02, 0xf7, 0x02, 0x80, 0x20, 0xdf, 0x01, 0x8d, 0x02, 0x00, 0x00, - 0x4c, 0x41, 0xe6, 0xa1, 0x9b, 0xe3, 0x51, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x59, 0x5a - }; + protected static byte[] CompressedIndexed { get; } = + new byte[] + { + 0xfd, + 0x37, + 0x7a, + 0x58, + 0x5a, + 0x00, + 0x00, + 0x01, + 0x69, + 0x22, + 0xde, + 0x36, + 0x03, + 0xc0, + 0xe3, + 0x02, + 0x80, + 0x20, + 0x21, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x7e, + 0xe5, + 0xd7, + 0x32, + 0xe0, + 0x0f, + 0xff, + 0x01, + 0x5b, + 0x5d, + 0x00, + 0x26, + 0x98, + 0x4a, + 0x47, + 0xc6, + 0x6a, + 0x27, + 0xd7, + 0x36, + 0x7a, + 0x05, + 0xb9, + 0x4f, + 0xd7, + 0xde, + 0x3a, + 0x0e, + 0xee, + 0x1b, + 0xd7, + 0x81, + 0xe9, + 0xf5, + 0x90, + 0x1e, + 0xd5, + 0x9e, + 0x88, + 0x32, + 0x1c, + 0x7b, + 0x43, + 0x84, + 0x02, + 0x58, + 0x92, + 0xcf, + 0x97, + 0xfc, + 0xae, + 0x01, + 0x83, + 0x23, + 0x48, + 0x93, + 0xc6, + 0x56, + 0xcc, + 0x6d, + 0xb1, + 0x23, + 0x10, + 0x24, + 0x3b, + 0x9e, + 0x06, + 0xaa, + 0xc0, + 0xce, + 0x86, + 0x0a, + 0xb7, + 0x9f, + 0x99, + 0x61, + 0xbe, + 0x3b, + 0x6d, + 0xfe, + 0x60, + 0xef, + 0x14, + 0x35, + 0x7f, + 0x21, + 0xe8, + 0x96, + 0x0e, + 0xbd, + 0x41, + 0x7c, + 0x65, + 0x89, + 0x96, + 0x28, + 0x5e, + 0x85, + 0xa6, + 0x4b, + 0xf3, + 0xf9, + 0xf8, + 0x25, + 0x31, + 0x4a, + 0xbb, + 0x72, + 0xce, + 0xcf, + 0x53, + 0xdf, + 0x13, + 0x42, + 0x2d, + 0xbc, + 0x95, + 0xa5, + 0x6d, + 0xc4, + 0x8c, + 0x72, + 0x99, + 0xe8, + 0x9a, + 0xcf, + 0x80, + 0xd4, + 0xc4, + 0x3f, + 0x55, + 0xc3, + 0x9b, + 0x00, + 0xce, + 0x65, + 0x27, + 0x6e, + 0xbf, + 0xb2, + 0x88, + 0xab, + 0xc0, + 0x5f, + 0xf9, + 0xd0, + 0xc8, + 0xbb, + 0xd7, + 0x48, + 0xd7, + 0x2e, + 0x5e, + 0xbb, + 0x23, + 0x35, + 0x6e, + 0x62, + 0xb6, + 0x13, + 0xd4, + 0x06, + 0xd1, + 0x5b, + 0x97, + 0xee, + 0x5b, + 0x89, + 0x78, + 0x07, + 0x24, + 0x74, + 0x59, + 0x06, + 0x1e, + 0x7f, + 0x8c, + 0xb0, + 0x48, + 0xff, + 0x0a, + 0x76, + 0xb2, + 0x07, + 0xa0, + 0x99, + 0xf5, + 0x4b, + 0x68, + 0xd4, + 0x55, + 0x32, + 0xb3, + 0x17, + 0x7b, + 0xb6, + 0x26, + 0xdb, + 0x1c, + 0xc3, + 0x0b, + 0xda, + 0x3e, + 0x46, + 0xba, + 0x1a, + 0x67, + 0x23, + 0xb7, + 0x2a, + 0x40, + 0xdc, + 0xc9, + 0xa2, + 0xe4, + 0xb5, + 0x68, + 0x5c, + 0x81, + 0x60, + 0xa7, + 0xad, + 0xe6, + 0xba, + 0xbb, + 0x0d, + 0x82, + 0x8a, + 0xe2, + 0x03, + 0xa9, + 0x22, + 0x09, + 0x5e, + 0xd8, + 0x69, + 0xfa, + 0x29, + 0xd1, + 0x32, + 0xa1, + 0xf0, + 0x9b, + 0x3c, + 0xc3, + 0x0b, + 0x9a, + 0x53, + 0xf0, + 0x3e, + 0xf3, + 0x1b, + 0x77, + 0xee, + 0x8f, + 0xa6, + 0x15, + 0x02, + 0x77, + 0x14, + 0x54, + 0x60, + 0xae, + 0xbe, + 0x91, + 0x9e, + 0xe6, + 0x8b, + 0x87, + 0x6e, + 0x46, + 0x44, + 0x64, + 0xc7, + 0x58, + 0x90, + 0x62, + 0x25, + 0x32, + 0xf9, + 0xcd, + 0xd2, + 0x73, + 0x2e, + 0x3f, + 0xd7, + 0x5d, + 0x3c, + 0x86, + 0x1c, + 0xa8, + 0x35, + 0xa9, + 0xc2, + 0xcb, + 0x59, + 0xcb, + 0xac, + 0xb3, + 0x03, + 0x12, + 0xd4, + 0x8a, + 0xde, + 0xd5, + 0xc1, + 0xd8, + 0x0c, + 0x32, + 0x49, + 0x87, + 0x97, + 0x62, + 0x4f, + 0x32, + 0x39, + 0x63, + 0x5b, + 0x8b, + 0xd1, + 0x6c, + 0x5c, + 0x90, + 0xd9, + 0x93, + 0x13, + 0xae, + 0x70, + 0xf5, + 0x2f, + 0x40, + 0xaf, + 0x01, + 0x95, + 0x01, + 0x0c, + 0xc5, + 0xfa, + 0x82, + 0xf8, + 0x71, + 0x9d, + 0x53, + 0xe6, + 0x47, + 0x6e, + 0x99, + 0x54, + 0x57, + 0x41, + 0x72, + 0xea, + 0xf5, + 0x78, + 0xdd, + 0x86, + 0xbd, + 0x00, + 0x00, + 0x00, + 0x72, + 0x6a, + 0xf2, + 0x47, + 0x03, + 0xc0, + 0xcb, + 0x01, + 0x8d, + 0x02, + 0x21, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0xfb, + 0xa7, + 0xf7, + 0x94, + 0xe0, + 0x01, + 0x0c, + 0x00, + 0xc3, + 0x5d, + 0x00, + 0x06, + 0x82, + 0xca, + 0x9b, + 0x77, + 0x93, + 0x57, + 0xb3, + 0x76, + 0xbd, + 0x8b, + 0xcb, + 0xee, + 0xf4, + 0x2c, + 0xff, + 0x7f, + 0x95, + 0x33, + 0x15, + 0x10, + 0xa5, + 0xf9, + 0xfd, + 0xa6, + 0xbb, + 0x9e, + 0xf9, + 0x75, + 0x67, + 0xee, + 0xec, + 0x8b, + 0x40, + 0xea, + 0x32, + 0x47, + 0x3d, + 0x26, + 0xbe, + 0x11, + 0x9c, + 0xa6, + 0x40, + 0xbe, + 0x84, + 0x1f, + 0x1b, + 0x35, + 0x1a, + 0x66, + 0x10, + 0x9c, + 0xf4, + 0x12, + 0x1a, + 0x95, + 0x81, + 0xb5, + 0x55, + 0x6b, + 0xc5, + 0x42, + 0xfd, + 0x37, + 0x70, + 0xc5, + 0x08, + 0xa4, + 0x27, + 0x67, + 0x11, + 0x0b, + 0x1f, + 0xcc, + 0xdb, + 0x54, + 0x9b, + 0x5a, + 0x5f, + 0xee, + 0x21, + 0x63, + 0xdd, + 0x4b, + 0xbc, + 0x49, + 0x95, + 0x6d, + 0xf4, + 0xcb, + 0x9a, + 0x9a, + 0x5e, + 0xe4, + 0x7d, + 0x0f, + 0x02, + 0x22, + 0xa9, + 0x42, + 0x46, + 0x1a, + 0x04, + 0x87, + 0x43, + 0x72, + 0x59, + 0xa4, + 0xd6, + 0xeb, + 0x69, + 0x36, + 0xde, + 0xea, + 0x53, + 0x8c, + 0x89, + 0xd7, + 0x22, + 0xa6, + 0xf7, + 0xa8, + 0x4c, + 0x72, + 0x6c, + 0x80, + 0x69, + 0x01, + 0xb2, + 0xa7, + 0xe8, + 0x8b, + 0x94, + 0xaf, + 0x0e, + 0x47, + 0x58, + 0x1d, + 0x0e, + 0x5c, + 0x7c, + 0x33, + 0x9f, + 0x21, + 0x17, + 0x2c, + 0x4f, + 0x3d, + 0x72, + 0xff, + 0xcf, + 0x7a, + 0x4f, + 0x82, + 0x5b, + 0x85, + 0x28, + 0x70, + 0xf4, + 0x8c, + 0x81, + 0x41, + 0xb8, + 0x20, + 0x5c, + 0x3e, + 0x02, + 0x5e, + 0x5a, + 0x61, + 0xbb, + 0x2f, + 0x64, + 0xc5, + 0x4e, + 0x53, + 0xe4, + 0xca, + 0xe4, + 0xd9, + 0x75, + 0xaf, + 0x15, + 0x4d, + 0xff, + 0x01, + 0xec, + 0x13, + 0x4a, + 0x70, + 0x00, + 0x04, + 0xf9, + 0xfa, + 0x00, + 0x00, + 0x99, + 0x57, + 0xc4, + 0x96, + 0x00, + 0x02, + 0xf7, + 0x02, + 0x80, + 0x20, + 0xdf, + 0x01, + 0x8d, + 0x02, + 0x00, + 0x00, + 0x4c, + 0x41, + 0xe6, + 0xa1, + 0x9b, + 0xe3, + 0x51, + 0x40, + 0x03, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x59, + 0x5a + }; protected static byte[] OriginalIndexedBytes => Encoding.ASCII.GetBytes(OriginalIndexed); - protected static string OriginalIndexed { get; } = Original + Original + Original + Original + Original + Original + Original + Original + Original; + protected static string OriginalIndexed { get; } = + Original + + Original + + Original + + Original + + Original + + Original + + Original + + Original + + Original; } } diff --git a/tests/SharpCompress.Test/Zip/Zip64Tests.cs b/tests/SharpCompress.Test/Zip/Zip64Tests.cs index 8e683f9e..c1f4453f 100644 --- a/tests/SharpCompress.Test/Zip/Zip64Tests.cs +++ b/tests/SharpCompress.Test/Zip/Zip64Tests.cs @@ -14,10 +14,7 @@ namespace SharpCompress.Test.Zip { public class Zip64Tests : WriterTests { - public Zip64Tests() - : base(ArchiveType.Zip) - { - } + public Zip64Tests() : base(ArchiveType.Zip) { } // 4GiB + 1 private const long FOUR_GB_LIMIT = ((long)uint.MaxValue) + 1; @@ -66,9 +63,7 @@ namespace SharpCompress.Test.Zip RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: false, forward_only: false); throw new InvalidOperationException("Test did not fail?"); } - catch (NotSupportedException) - { - } + catch (NotSupportedException) { } } [Trait("zip64", "true")] @@ -80,9 +75,7 @@ namespace SharpCompress.Test.Zip RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: true, forward_only: true); throw new InvalidOperationException("Test did not fail?"); } - catch (NotSupportedException) - { - } + catch (NotSupportedException) { } } [Trait("zip64", "true")] @@ -94,12 +87,17 @@ namespace SharpCompress.Test.Zip RunSingleTest(1, FOUR_GB_LIMIT, set_zip64: false, forward_only: true); throw new InvalidOperationException("Test did not fail?"); } - catch (NotSupportedException) - { - } + catch (NotSupportedException) { } } - public void RunSingleTest(long files, long filesize, bool set_zip64, bool forward_only, long write_chunk_size = 1024 * 1024, string filename = "zip64-test.zip") + public void RunSingleTest( + long files, + long filesize, + bool set_zip64, + bool forward_only, + long write_chunk_size = 1024 * 1024, + string filename = "zip64-test.zip" + ) { filename = Path.Combine(SCRATCH2_FILES_PATH, filename); @@ -110,33 +108,55 @@ namespace SharpCompress.Test.Zip if (!File.Exists(filename)) { - CreateZipArchive(filename, files, filesize, write_chunk_size, set_zip64, forward_only); + CreateZipArchive( + filename, + files, + filesize, + write_chunk_size, + set_zip64, + forward_only + ); } var resForward = ReadForwardOnly(filename); if (resForward.Item1 != files) { - throw new InvalidOperationException($"Incorrect number of items reported: {resForward.Item1}, should have been {files}"); + throw new InvalidOperationException( + $"Incorrect number of items reported: {resForward.Item1}, should have been {files}" + ); } if (resForward.Item2 != files * filesize) { - throw new InvalidOperationException($"Incorrect combined size reported: {resForward.Item2}, should have been {files * filesize}"); + throw new InvalidOperationException( + $"Incorrect combined size reported: {resForward.Item2}, should have been {files * filesize}" + ); } var resArchive = ReadArchive(filename); if (resArchive.Item1 != files) { - throw new InvalidOperationException($"Incorrect number of items reported: {resArchive.Item1}, should have been {files}"); + throw new InvalidOperationException( + $"Incorrect number of items reported: {resArchive.Item1}, should have been {files}" + ); } if (resArchive.Item2 != files * filesize) { - throw new InvalidOperationException($"Incorrect number of items reported: {resArchive.Item2}, should have been {files * filesize}"); + throw new InvalidOperationException( + $"Incorrect number of items reported: {resArchive.Item2}, should have been {files * filesize}" + ); } } - public void CreateZipArchive(string filename, long files, long filesize, long chunksize, bool set_zip64, bool forward_only) + public void CreateZipArchive( + string filename, + long files, + long filesize, + long chunksize, + bool set_zip64, + bool forward_only + ) { var data = new byte[chunksize]; @@ -144,13 +164,15 @@ namespace SharpCompress.Test.Zip var opts = new ZipWriterOptions(CompressionType.Deflate) { UseZip64 = set_zip64 }; // Use no compression to ensure we hit the limits (actually inflates a bit, but seems better than using method==Store) - var eo = new ZipWriterEntryOptions() { DeflateCompressionLevel = Compressors.Deflate.CompressionLevel.None }; + var eo = new ZipWriterEntryOptions() + { + DeflateCompressionLevel = Compressors.Deflate.CompressionLevel.None + }; using (var zip = File.OpenWrite(filename)) using (var st = forward_only ? (Stream)new ForwardOnlyStream(zip) : zip) using (var zipWriter = (ZipWriter)WriterFactory.Open(st, ArchiveType.Zip, opts)) { - for (var i = 0; i < files; i++) { using (var str = zipWriter.WriteToStream(i.ToString(), eo)) @@ -177,8 +199,7 @@ namespace SharpCompress.Test.Zip { while (rd.MoveToNextEntry()) { - using (rd.OpenEntryStream()) - { } + using (rd.OpenEntryStream()) { } count++; if (prev != null) diff --git a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs index 07f158b1..c1375801 100644 --- a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs @@ -30,26 +30,31 @@ namespace SharpCompress.Test.Zip { ArchiveStreamRead("Zip.bzip2.dd.zip"); } + [Fact] public void Zip_BZip2_ArchiveStreamRead() { ArchiveStreamRead("Zip.bzip2.zip"); } + [Fact] public void Zip_Deflate_Streamed2_ArchiveStreamRead() { ArchiveStreamRead("Zip.deflate.dd-.zip"); } + [Fact] public void Zip_Deflate_Streamed_ArchiveStreamRead() { ArchiveStreamRead("Zip.deflate.dd.zip"); } + [Fact] public void Zip_Deflate_ArchiveStreamRead() { ArchiveStreamRead("Zip.deflate.zip"); } + [Fact] public void Zip_Deflate64_ArchiveStreamRead() { @@ -61,21 +66,25 @@ namespace SharpCompress.Test.Zip { ArchiveStreamRead("Zip.lzma.dd.zip"); } + [Fact] public void Zip_LZMA_ArchiveStreamRead() { ArchiveStreamRead("Zip.lzma.zip"); } + [Fact] public void Zip_PPMd_Streamed_ArchiveStreamRead() { ArchiveStreamRead("Zip.ppmd.dd.zip"); } + [Fact] public void Zip_PPMd_ArchiveStreamRead() { ArchiveStreamRead("Zip.ppmd.zip"); } + [Fact] public void Zip_None_ArchiveStreamRead() { @@ -87,53 +96,65 @@ namespace SharpCompress.Test.Zip { ArchiveFileRead("Zip.bzip2.dd.zip"); } + [Fact] public void Zip_BZip2_ArchiveFileRead() { ArchiveFileRead("Zip.bzip2.zip"); } + [Fact] public void WinZip26_ArchiveFileRead() { ArchiveFileRead("WinZip26.zip"); } + [Fact] public void WinZip26_Multi_ArchiveFileRead() { - ArchiveStreamMultiRead(null, "WinZip26.nocomp.multi.zip", - "WinZip26.nocomp.multi.z01"); //min split size is 64k so no compression used + ArchiveStreamMultiRead(null, "WinZip26.nocomp.multi.zip", "WinZip26.nocomp.multi.z01"); //min split size is 64k so no compression used } + [Fact] public void WinZip26_X_BZip2_ArchiveFileRead() { ArchiveFileRead("WinZip26_BZip2.zipx"); } + [Fact] public void WinZip26_X_Lzma_ArchiveFileRead() { ArchiveFileRead("WinZip26_LZMA.zipx"); } + [Fact] public void WinZip26_X_Multi_ArchiveFileRead() { - ArchiveStreamMultiRead(null, "WinZip26.nocomp.multi.zipx", - "WinZip26.nocomp.multi.zx01"); //min split size is 64k so no compression used + ArchiveStreamMultiRead( + null, + "WinZip26.nocomp.multi.zipx", + "WinZip26.nocomp.multi.zx01" + ); //min split size is 64k so no compression used } + [Fact] public void Zip_Deflate_Streamed2_ArchiveFileRead() { ArchiveFileRead("Zip.deflate.dd-.zip"); } + [Fact] public void Zip_Deflate_Streamed_ArchiveFileRead() { ArchiveFileRead("Zip.deflate.dd.zip"); } + [Fact] public void Zip_Deflate_ArchiveFileRead() { ArchiveFileRead("Zip.deflate.zip"); } + //will detect and load other files [Fact] public void Zip_Deflate_Multi_ArchiveFirstFileRead() @@ -141,68 +162,82 @@ namespace SharpCompress.Test.Zip ArchiveFileRead("WinZip26.nocomp.multi.zip"); //"WinZip26.nocomp.multi.z01" } + //will detect and load other files [Fact] public void ZipX_Deflate_Multi_ArchiveFirstFileRead() { ArchiveFileRead("WinZip26.nocomp.multi.zipx"); - //"WinZip26.nocomp.multi.zx01" + //"WinZip26.nocomp.multi.zx01" } + [Fact] public void Zip_GetParts() { //uses first part to search for all parts and compares against this array - ArchiveGetParts(new string[] { - "Infozip.nocomp.multi.zip", - "Infozip.nocomp.multi.z01"}); + ArchiveGetParts( + new string[] { "Infozip.nocomp.multi.zip", "Infozip.nocomp.multi.z01" } + ); } + [Fact] public void ZipX_GetParts() { //uses first part to search for all parts and compares against this array - ArchiveGetParts(new string[] { - "WinZip26.nocomp.multi.zipx", - "WinZip26.nocomp.multi.zx01"}); + ArchiveGetParts( + new string[] { "WinZip26.nocomp.multi.zipx", "WinZip26.nocomp.multi.zx01" } + ); } + [Fact] public void Zip_GetPartsSplit() { //uses first part to search for all parts and compares against this array - ArchiveGetParts(new string[] { - "Zip.deflate.split.001", - "Zip.deflate.split.002", - "Zip.deflate.split.003", - "Zip.deflate.split.004", - "Zip.deflate.split.005", - "Zip.deflate.split.006"}); + ArchiveGetParts( + new string[] + { + "Zip.deflate.split.001", + "Zip.deflate.split.002", + "Zip.deflate.split.003", + "Zip.deflate.split.004", + "Zip.deflate.split.005", + "Zip.deflate.split.006" + } + ); } + //will detect and load other files [Fact] public void Zip_Deflate_Split_ArchiveFirstFileRead() { ArchiveFileRead("Zip.deflate.split.001"); - //"Zip.deflate.split.002", - //"Zip.deflate.split.003", - //"Zip.deflate.split.004", - //"Zip.deflate.split.005", - //"Zip.deflate.split.006" + //"Zip.deflate.split.002", + //"Zip.deflate.split.003", + //"Zip.deflate.split.004", + //"Zip.deflate.split.005", + //"Zip.deflate.split.006" } + [Fact] public void Zip_Deflate_Split_ArchiveFileRead() { - ArchiveStreamMultiRead(null, "Zip.deflate.split.001", - "Zip.deflate.split.002", - "Zip.deflate.split.003", - "Zip.deflate.split.004", - "Zip.deflate.split.005", - "Zip.deflate.split.006"); + ArchiveStreamMultiRead( + null, + "Zip.deflate.split.001", + "Zip.deflate.split.002", + "Zip.deflate.split.003", + "Zip.deflate.split.004", + "Zip.deflate.split.005", + "Zip.deflate.split.006" + ); } + [Fact] public void Zip_InfoZip_Multi_ArchiveFileRead() { - ArchiveStreamMultiRead(null, "Infozip.nocomp.multi.zip", - "Infozip.nocomp.multi.z01"); //min split size is 64k so no compression used + ArchiveStreamMultiRead(null, "Infozip.nocomp.multi.zip", "Infozip.nocomp.multi.z01"); //min split size is 64k so no compression used } + [Fact] public void Zip_Deflate64_ArchiveFileRead() { @@ -214,21 +249,25 @@ namespace SharpCompress.Test.Zip { ArchiveFileRead("Zip.lzma.dd.zip"); } + [Fact] public void Zip_LZMA_ArchiveFileRead() { ArchiveFileRead("Zip.lzma.zip"); } + [Fact] public void Zip_PPMd_Streamed_ArchiveFileRead() { ArchiveFileRead("Zip.ppmd.dd.zip"); } + [Fact] public void Zip_PPMd_ArchiveFileRead() { ArchiveFileRead("Zip.ppmd.zip"); } + [Fact] public void Zip_None_ArchiveFileRead() { @@ -256,7 +295,9 @@ namespace SharpCompress.Test.Zip using (var archive = ZipArchive.Open(unmodified)) { - var entry = archive.Entries.Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)); + var entry = archive.Entries.Single( + x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ); archive.RemoveEntry(entry); WriterOptions writerOptions = new ZipWriterOptions(CompressionType.Deflate); @@ -308,17 +349,24 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Removal_Poly() { - string scratchPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.noEmptyDirs.zip"); - - using (ZipArchive vfs = (ZipArchive)ArchiveFactory.Open(scratchPath)) { - var e = vfs.Entries.First(v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)); + var e = vfs.Entries.First( + v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ); vfs.RemoveEntry(e); - Assert.Null(vfs.Entries.FirstOrDefault(v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))); - Assert.Null(((IArchive)vfs).Entries.FirstOrDefault(v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))); + Assert.Null( + vfs.Entries.FirstOrDefault( + v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ) + ); + Assert.Null( + ((IArchive)vfs).Entries.FirstOrDefault( + v => v.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ) + ); } } @@ -355,15 +403,27 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Create_New() { - foreach (var file in Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)) + foreach ( + var file in Directory.EnumerateFiles( + ORIGINAL_FILES_PATH, + "*.*", + SearchOption.AllDirectories + ) + ) { var newFileName = file.Substring(ORIGINAL_FILES_PATH.Length); - if (newFileName.StartsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) + if ( + newFileName.StartsWith( + Path.DirectorySeparatorChar.ToString(), + StringComparison.OrdinalIgnoreCase + ) + ) { newFileName = newFileName.Substring(1); } newFileName = Path.Combine(SCRATCH_FILES_PATH, newFileName); - var newDir = Path.GetDirectoryName(newFileName) ?? throw new ArgumentNullException(); + var newDir = + Path.GetDirectoryName(newFileName) ?? throw new ArgumentNullException(); if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); @@ -411,15 +471,27 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Create_New_Add_Remove() { - foreach (var file in Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)) + foreach ( + var file in Directory.EnumerateFiles( + ORIGINAL_FILES_PATH, + "*.*", + SearchOption.AllDirectories + ) + ) { var newFileName = file.Substring(ORIGINAL_FILES_PATH.Length); - if (newFileName.StartsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase)) + if ( + newFileName.StartsWith( + Path.DirectorySeparatorChar.ToString(), + StringComparison.OrdinalIgnoreCase + ) + ) { newFileName = newFileName.Substring(1); } newFileName = Path.Combine(SCRATCH_FILES_PATH, newFileName); - var newDir = Path.GetDirectoryName(newFileName) ?? throw new ArgumentNullException(); + var newDir = + Path.GetDirectoryName(newFileName) ?? throw new ArgumentNullException(); if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); @@ -431,8 +503,16 @@ namespace SharpCompress.Test.Zip using (var archive = ZipArchive.Create()) { archive.AddAllFromDirectory(SCRATCH_FILES_PATH); - archive.RemoveEntry(archive.Entries.Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))); - Assert.Null(archive.Entries.FirstOrDefault(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))); + archive.RemoveEntry( + archive.Entries.Single( + x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ) + ); + Assert.Null( + archive.Entries.FirstOrDefault( + x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) + ) + ); } Directory.Delete(SCRATCH_FILES_PATH, true); } @@ -440,18 +520,19 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Deflate_WinzipAES_Read() { - using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip"), new ReaderOptions() - { - Password = "test" - })) + using ( + var reader = ZipArchive.Open( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip"), + new ReaderOptions() { Password = "test" } + ) + ) { foreach (var entry in reader.Entries.Where(x => !x.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -460,10 +541,12 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Deflate_WinzipAES_MultiOpenEntryStream() { - using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES2.zip"), new ReaderOptions() - { - Password = "test" - })) + using ( + var reader = ZipArchive.Open( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES2.zip"), + new ReaderOptions() { Password = "test" } + ) + ) { foreach (var entry in reader.Entries.Where(x => !x.IsDirectory)) { @@ -478,15 +561,18 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Read_Volume_Comment() { - using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.zip64.zip"), new ReaderOptions() - { - Password = "test" - })) + using ( + var reader = ZipArchive.Open( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.zip64.zip"), + new ReaderOptions() { Password = "test" } + ) + ) { var isComplete = reader.IsComplete; Assert.Equal(1, reader.Volumes.Count); - string expectedComment = "Encoding:utf-8 || Compression:Deflate levelDefault || Encrypt:None || ZIP64:Always\r\nCreated at 2017-Jan-23 14:10:43 || DotNetZip Tool v1.9.1.8\r\nTest zip64 archive"; + string expectedComment = + "Encoding:utf-8 || Compression:Deflate levelDefault || Encrypt:None || ZIP64:Always\r\nCreated at 2017-Jan-23 14:10:43 || DotNetZip Tool v1.9.1.8\r\nTest zip64 archive"; Assert.Equal(expectedComment, reader.Volumes.First().Comment); } } @@ -494,18 +580,19 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_BZip2_Pkware_Read() { - using (var reader = ZipArchive.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip"), new ReaderOptions() - { - Password = "test" - })) + using ( + var reader = ZipArchive.Open( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip"), + new ReaderOptions() { Password = "test" } + ) + ) { foreach (var entry in reader.Entries.Where(x => !x.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } VerifyFiles(); @@ -560,7 +647,12 @@ namespace SharpCompress.Test.Zip using (FileStream fileStream = File.Open(zipFile, FileMode.Open)) { - using (IArchive archive = ArchiveFactory.Open(fileStream, new ReaderOptions { Password = "12345678" })) + using ( + IArchive archive = ArchiveFactory.Open( + fileStream, + new ReaderOptions { Password = "12345678" } + ) + ) { var entries = archive.Entries.Where(entry => !entry.IsDirectory); foreach (IArchiveEntry entry in entries) @@ -592,11 +684,10 @@ namespace SharpCompress.Test.Zip { foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory)) { - entry.WriteToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + entry.WriteToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } }); @@ -612,7 +703,13 @@ namespace SharpCompress.Test.Zip { MemoryStream stream = new NonSeekableMemoryStream(); - using (IWriter zipWriter = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate)) + using ( + IWriter zipWriter = WriterFactory.Open( + stream, + ArchiveType.Zip, + CompressionType.Deflate + ) + ) { zipWriter.Write("foo.txt", new MemoryStream(Array.Empty())); zipWriter.Write("foo2.txt", new MemoryStream(new byte[10])); @@ -738,7 +835,14 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Uncompressed_Skip_All() { - var keys = new string[] { "Folder/File1.txt", "Folder/File2.rtf", "Folder2/File1.txt", "Folder2/File2.txt", "DEADBEEF" }; + var keys = new string[] + { + "Folder/File1.txt", + "Folder/File2.rtf", + "Folder2/File1.txt", + "Folder2/File2.txt", + "DEADBEEF" + }; var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.uncompressed.zip"); using (var stream = File.Open(zipPath, FileMode.Open, FileAccess.Read)) { @@ -761,26 +865,32 @@ namespace SharpCompress.Test.Zip var zipPath = Path.Combine(TEST_ARCHIVES_PATH, "Zip.UnicodePathExtra.zip"); using (var stream = File.Open(zipPath, FileMode.Open, FileAccess.Read)) { - IArchive archive = ArchiveFactory.Open(stream, new ReaderOptions - { - ArchiveEncoding = new ArchiveEncoding + IArchive archive = ArchiveFactory.Open( + stream, + new ReaderOptions { - Default = Encoding.GetEncoding("shift_jis"), + ArchiveEncoding = new ArchiveEncoding + { + Default = Encoding.GetEncoding("shift_jis"), + } } - }); + ); IReader reader = archive.ExtractAllEntries(); reader.MoveToNextEntry(); Assert.Equal("궖귛궖귙귪궖귗귪궖귙_wav.frq", reader.Entry.Key); } using (var stream = File.Open(zipPath, FileMode.Open, FileAccess.Read)) { - IArchive archive = ArchiveFactory.Open(stream, new ReaderOptions - { - ArchiveEncoding = new ArchiveEncoding + IArchive archive = ArchiveFactory.Open( + stream, + new ReaderOptions { - Forced = Encoding.GetEncoding("shift_jis"), + ArchiveEncoding = new ArchiveEncoding + { + Forced = Encoding.GetEncoding("shift_jis"), + } } - }); + ); IReader reader = archive.ExtractAllEntries(); reader.MoveToNextEntry(); Assert.Equal("きょきゅんきゃんきゅ_wav.frq", reader.Entry.Key); diff --git a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs index 65ae9326..446c0e82 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -56,25 +56,33 @@ namespace SharpCompress.Test.Zip { Read("Zip.bzip2.dd.zip", CompressionType.BZip2); } + [Fact] public void Zip_BZip2_Read() { Read("Zip.bzip2.zip", CompressionType.BZip2); } + [Fact] public void Zip_Deflate_Streamed2_Read() { Read("Zip.deflate.dd-.zip", CompressionType.Deflate); } + [Fact] public void Zip_Deflate_Streamed_Read() { Read("Zip.deflate.dd.zip", CompressionType.Deflate); } + [Fact] public void Zip_Deflate_Streamed_Skip() { - using (Stream stream = new ForwardOnlyStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")))) + using ( + Stream stream = new ForwardOnlyStream( + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) + ) + ) using (IReader reader = ReaderFactory.Open(stream)) { int x = 0; @@ -85,22 +93,22 @@ namespace SharpCompress.Test.Zip x++; if (x % 2 == 0) { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } } } + [Fact] public void Zip_Deflate_Read() { Read("Zip.deflate.zip", CompressionType.Deflate); } + [Fact] public void Zip_Deflate64_Read() { @@ -112,16 +120,19 @@ namespace SharpCompress.Test.Zip { Read("Zip.lzma.dd.zip", CompressionType.LZMA); } + [Fact] public void Zip_LZMA_Read() { Read("Zip.lzma.zip", CompressionType.LZMA); } + [Fact] public void Zip_PPMd_Streamed_Read() { Read("Zip.ppmd.dd.zip", CompressionType.PPMd); } + [Fact] public void Zip_PPMd_Read() { @@ -143,22 +154,22 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_BZip2_PkwareEncryption_Read() { - using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip"))) - using (var reader = ZipReader.Open(stream, new ReaderOptions() - { - Password = "test" - })) + using ( + Stream stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.pkware.zip") + ) + ) + using (var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" })) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { Assert.Equal(CompressionType.BZip2, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -168,7 +179,11 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Reader_Disposal_Test() { - using (TestStream stream = new TestStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")))) + using ( + TestStream stream = new TestStream( + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) + ) + ) { using (var reader = ReaderFactory.Open(stream)) { @@ -176,12 +191,10 @@ namespace SharpCompress.Test.Zip { if (!reader.Entry.IsDirectory) { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -192,19 +205,21 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_Reader_Disposal_Test2() { - using (TestStream stream = new TestStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")))) + using ( + TestStream stream = new TestStream( + File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")) + ) + ) { var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } Assert.False(stream.IsDisposed); @@ -215,54 +230,51 @@ namespace SharpCompress.Test.Zip public void Zip_LZMA_WinzipAES_Read() { Assert.Throws(() => - { - using ( - Stream stream = - File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, - "Zip.lzma.WinzipAES.zip"))) - using (var reader = ZipReader.Open(stream, new ReaderOptions() - { - Password = "test" - })) - { - while (reader.MoveToNextEntry()) - { - if (!reader.Entry.IsDirectory) - { - Assert.Equal(CompressionType.Unknown, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); - } - } - } - VerifyFiles(); - }); + { + using ( + Stream stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.lzma.WinzipAES.zip") + ) + ) + using ( + var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" }) + ) + { + while (reader.MoveToNextEntry()) + { + if (!reader.Entry.IsDirectory) + { + Assert.Equal(CompressionType.Unknown, reader.Entry.CompressionType); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); + } + } + } + VerifyFiles(); + }); } [Fact] public void Zip_Deflate_WinzipAES_Read() { - using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip"))) - using (var reader = ZipReader.Open(stream, new ReaderOptions() - { - Password = "test" - })) + using ( + Stream stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.WinzipAES.zip") + ) + ) + using (var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" })) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { Assert.Equal(CompressionType.Unknown, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); } } } @@ -274,22 +286,17 @@ namespace SharpCompress.Test.Zip { int count = 0; using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "zipcrypto.zip"))) - using (var reader = ZipReader.Open(stream, new ReaderOptions() - { - Password = "test" - })) + using (var reader = ZipReader.Open(stream, new ReaderOptions() { Password = "test" })) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { Assert.Equal(CompressionType.None, reader.Entry.CompressionType); - reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, - new ExtractionOptions() - { - ExtractFullPath = true, - Overwrite = true - }); + reader.WriteEntryToDirectory( + SCRATCH_FILES_PATH, + new ExtractionOptions() { ExtractFullPath = true, Overwrite = true } + ); count++; } } @@ -310,7 +317,13 @@ namespace SharpCompress.Test.Zip { Stream stream = new TestStream(memory, read: true, write: true, seek: false); - using (IWriter zipWriter = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate)) + using ( + IWriter zipWriter = WriterFactory.Open( + stream, + ArchiveType.Zip, + CompressionType.Deflate + ) + ) { zipWriter.Write(expected[0].Item1, new MemoryStream(expected[0].Item2)); zipWriter.Write(expected[1].Item1, new MemoryStream(expected[1].Item2)); @@ -347,9 +360,22 @@ namespace SharpCompress.Test.Zip [Fact] public void Zip_None_Issue86_Streamed_Read() { - var keys = new string[] { "Empty1", "Empty2", "Dir1/", "Dir2/", "Fake1", "Fake2", "Internal.zip" }; + var keys = new string[] + { + "Empty1", + "Empty2", + "Dir1/", + "Dir2/", + "Fake1", + "Fake2", + "Internal.zip" + }; - using (Stream stream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.issue86.zip"))) + using ( + Stream stream = File.OpenRead( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.issue86.zip") + ) + ) using (var reader = ZipReader.Open(stream)) { foreach (var key in keys) @@ -376,7 +402,7 @@ namespace SharpCompress.Test.Zip using (var fileStream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "test_477.zip"))) using (var reader = ZipReader.Open(fileStream)) { - foreach( var key in keys) + foreach (var key in keys) { reader.MoveToNextEntry(); @@ -384,14 +410,16 @@ namespace SharpCompress.Test.Zip } } } + [Fact] public void Issue_685() { var count = 0; - using (var fileStream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Issue_685.zip"))) + using ( + var fileStream = File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Issue_685.zip")) + ) using (var reader = ZipReader.Open(fileStream)) { - while (reader.MoveToNextEntry()) { count++; @@ -433,6 +461,5 @@ namespace SharpCompress.Test.Zip Assert.Equal(4, x); } } - } } diff --git a/tests/SharpCompress.Test/Zip/ZipWriterTests.cs b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs index 8d546cec..28e90f51 100644 --- a/tests/SharpCompress.Test/Zip/ZipWriterTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipWriterTests.cs @@ -7,47 +7,74 @@ namespace SharpCompress.Test.Zip { public class ZipWriterTests : WriterTests { - public ZipWriterTests() - : base(ArchiveType.Zip) - { - } - + public ZipWriterTests() : base(ArchiveType.Zip) { } [Fact] public void Zip_Deflate_Write() { - Write(CompressionType.Deflate, "Zip.deflate.noEmptyDirs.zip", "Zip.deflate.noEmptyDirs.zip", Encoding.UTF8); + Write( + CompressionType.Deflate, + "Zip.deflate.noEmptyDirs.zip", + "Zip.deflate.noEmptyDirs.zip", + Encoding.UTF8 + ); } [Fact] public void Zip_BZip2_Write() { - Write(CompressionType.BZip2, "Zip.bzip2.noEmptyDirs.zip", "Zip.bzip2.noEmptyDirs.zip", Encoding.UTF8); + Write( + CompressionType.BZip2, + "Zip.bzip2.noEmptyDirs.zip", + "Zip.bzip2.noEmptyDirs.zip", + Encoding.UTF8 + ); } [Fact] public void Zip_None_Write() { - Write(CompressionType.None, "Zip.none.noEmptyDirs.zip", "Zip.none.noEmptyDirs.zip", Encoding.UTF8); + Write( + CompressionType.None, + "Zip.none.noEmptyDirs.zip", + "Zip.none.noEmptyDirs.zip", + Encoding.UTF8 + ); } [Fact] public void Zip_LZMA_Write() { - Write(CompressionType.LZMA, "Zip.lzma.noEmptyDirs.zip", "Zip.lzma.noEmptyDirs.zip", Encoding.UTF8); + Write( + CompressionType.LZMA, + "Zip.lzma.noEmptyDirs.zip", + "Zip.lzma.noEmptyDirs.zip", + Encoding.UTF8 + ); } [Fact] public void Zip_PPMd_Write() { - Write(CompressionType.PPMd, "Zip.ppmd.noEmptyDirs.zip", "Zip.ppmd.noEmptyDirs.zip", Encoding.UTF8); + Write( + CompressionType.PPMd, + "Zip.ppmd.noEmptyDirs.zip", + "Zip.ppmd.noEmptyDirs.zip", + Encoding.UTF8 + ); } - [Fact] public void Zip_Rar_Write() { - Assert.Throws(() => Write(CompressionType.Rar, "Zip.ppmd.noEmptyDirs.zip", "Zip.ppmd.noEmptyDirs.zip")); + Assert.Throws( + () => + Write( + CompressionType.Rar, + "Zip.ppmd.noEmptyDirs.zip", + "Zip.ppmd.noEmptyDirs.zip" + ) + ); } } }