mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-09 21:24:08 +00:00
Compare commits
8 Commits
adam/clean
...
adam/make-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
436b2f4a11 | ||
|
|
61133bc010 | ||
|
|
8f64d351ac | ||
|
|
6bfe4071aa | ||
|
|
9fa425d8c5 | ||
|
|
56c3c92f30 | ||
|
|
8f3ff5fd65 | ||
|
|
0e96aa4263 |
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using SharpCompress.Common.Rar.Headers;
|
||||
@@ -12,7 +10,7 @@ internal class CryptKey3 : ICryptKey
|
||||
|
||||
private string _password;
|
||||
|
||||
public CryptKey3(string password) => _password = password ?? "";
|
||||
public CryptKey3(string? password) => _password = password ?? "";
|
||||
|
||||
public ICryptoTransform Transformer(byte[] salt)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common.Rar;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using SharpCompress.Common.Rar;
|
||||
using SharpCompress.IO;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public partial class RarHeaderFactory
|
||||
if (_isRar5 && _cryptInfo != null)
|
||||
{
|
||||
await _cryptInfo.ReadInitVAsync(new AsyncMarkingBinaryReader(stream));
|
||||
var _headerKey = new CryptKey5(Options.Password!, _cryptInfo);
|
||||
var _headerKey = new CryptKey5(Options.Password.NotNull(), _cryptInfo);
|
||||
|
||||
reader = await AsyncRarCryptoBinaryReader.Create(
|
||||
stream,
|
||||
@@ -189,7 +189,7 @@ public partial class RarHeaderFactory
|
||||
Options.Password,
|
||||
fh.Rar5CryptoInfo.NotNull()
|
||||
)
|
||||
: new CryptKey3(Options.Password)
|
||||
: new CryptKey3(Options.Password.NotNull())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public partial class RarHeaderFactory
|
||||
if (_isRar5 && _cryptInfo != null)
|
||||
{
|
||||
_cryptInfo.ReadInitV(new MarkingBinaryReader(stream));
|
||||
var _headerKey = new CryptKey5(Options.Password!, _cryptInfo);
|
||||
var _headerKey = new CryptKey5(Options.Password.NotNull(), _cryptInfo);
|
||||
|
||||
reader = RarCryptoBinaryReader.Create(stream, _headerKey, _cryptInfo.Salt);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -18,7 +16,7 @@ internal partial class ArchiveDatabase
|
||||
internal List<long> _packSizes = new();
|
||||
internal List<uint?> _packCrCs = new();
|
||||
internal List<CFolder> _folders = new();
|
||||
internal List<int> _numUnpackStreamsVector;
|
||||
internal List<int>? _numUnpackStreamsVector;
|
||||
internal List<CFileItem> _files = new();
|
||||
|
||||
internal List<long> _packStreamStartPositions = new();
|
||||
@@ -47,7 +45,7 @@ internal partial class ArchiveDatabase
|
||||
_packSizes.Count == 0
|
||||
&& _packCrCs.Count == 0
|
||||
&& _folders.Count == 0
|
||||
&& _numUnpackStreamsVector.Count == 0
|
||||
&& (_numUnpackStreamsVector?.Count ?? 0) == 0
|
||||
&& _files.Count == 0;
|
||||
|
||||
private void FillStartPos()
|
||||
@@ -94,7 +92,7 @@ internal partial class ArchiveDatabase
|
||||
|
||||
_folderStartFileIndex.Add(i); // check it
|
||||
|
||||
if (_numUnpackStreamsVector![folderIndex] != 0)
|
||||
if (_numUnpackStreamsVector.NotNull()[folderIndex] != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#nullable disable
|
||||
|
||||
namespace SharpCompress.Common.SevenZip;
|
||||
|
||||
internal class CCoderInfo
|
||||
{
|
||||
internal CMethodId _methodId;
|
||||
internal byte[] _props;
|
||||
internal byte[]? _props;
|
||||
internal int _numInStreams;
|
||||
internal int _numOutStreams;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Common.SevenZip;
|
||||
@@ -10,7 +8,7 @@ internal class CFileItem
|
||||
public uint? Attrib { get; internal set; }
|
||||
public uint? ExtendedAttrib { get; internal set; }
|
||||
public uint? Crc { get; internal set; }
|
||||
public string Name { get; internal set; }
|
||||
public string? Name { get; internal set; }
|
||||
|
||||
public bool HasStream { get; internal set; }
|
||||
public bool IsDir { get; internal set; }
|
||||
|
||||
@@ -34,7 +34,7 @@ internal class SevenZipFilePart : FilePart
|
||||
internal CFileItem Header { get; }
|
||||
internal CFolder? Folder { get; }
|
||||
|
||||
internal override string FilePartName => Header.Name;
|
||||
internal override string? FilePartName => Header.Name;
|
||||
|
||||
internal override Stream? GetRawStream() => null;
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -78,11 +76,12 @@ public sealed partial class ADCStream
|
||||
var toCopy = count;
|
||||
var copied = 0;
|
||||
|
||||
while (_outPosition + toCopy >= _outBuffer.Length)
|
||||
var outBuf = _outBuffer.NotNull();
|
||||
while (_outPosition + toCopy >= outBuf.Length)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var piece = _outBuffer.Length - _outPosition;
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, piece);
|
||||
var piece = outBuf.Length - _outPosition;
|
||||
Array.Copy(outBuf, _outPosition, buffer, inPosition, piece);
|
||||
inPosition += piece;
|
||||
copied += piece;
|
||||
_position += piece;
|
||||
@@ -97,9 +96,10 @@ public sealed partial class ADCStream
|
||||
{
|
||||
return copied;
|
||||
}
|
||||
outBuf = _outBuffer;
|
||||
}
|
||||
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, toCopy);
|
||||
Array.Copy(outBuf, _outPosition, buffer, inPosition, toCopy);
|
||||
_outPosition += toCopy;
|
||||
_position += toCopy;
|
||||
copied += toCopy;
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -56,7 +54,7 @@ public sealed partial class ADCStream : Stream
|
||||
/// <summary>
|
||||
/// Buffer with currently used chunk of decompressed data
|
||||
/// </summary>
|
||||
private byte[] _outBuffer;
|
||||
private byte[]? _outBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Position in buffer of decompressed data
|
||||
@@ -139,10 +137,11 @@ public sealed partial class ADCStream : Stream
|
||||
var toCopy = count;
|
||||
var copied = 0;
|
||||
|
||||
while (_outPosition + toCopy >= _outBuffer.Length)
|
||||
while (_outPosition + toCopy >= _outBuffer.NotNull().Length)
|
||||
{
|
||||
var piece = _outBuffer.Length - _outPosition;
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, piece);
|
||||
var outBuf = _outBuffer.NotNull();
|
||||
var piece = outBuf.Length - _outPosition;
|
||||
Array.Copy(outBuf, _outPosition, buffer, inPosition, piece);
|
||||
inPosition += piece;
|
||||
copied += piece;
|
||||
_position += piece;
|
||||
@@ -155,7 +154,7 @@ public sealed partial class ADCStream : Stream
|
||||
}
|
||||
}
|
||||
|
||||
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, toCopy);
|
||||
Array.Copy(_outBuffer.NotNull(), _outPosition, buffer, inPosition, toCopy);
|
||||
_outPosition += toCopy;
|
||||
_position += toCopy;
|
||||
copied += toCopy;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -11,8 +9,8 @@ internal sealed class BinTree : InWindow
|
||||
private uint _cyclicBufferSize;
|
||||
private uint _matchMaxLen;
|
||||
|
||||
private uint[] _son;
|
||||
private uint[] _hash;
|
||||
private uint[]? _son;
|
||||
private uint[]? _hash;
|
||||
|
||||
private uint _cutValue = 0xFF;
|
||||
private uint _hashMask;
|
||||
@@ -56,9 +54,10 @@ internal sealed class BinTree : InWindow
|
||||
public new void Init()
|
||||
{
|
||||
base.Init();
|
||||
var hash = _hash.NotNull();
|
||||
for (uint i = 0; i < _hashSizeSum; i++)
|
||||
{
|
||||
_hash[i] = K_EMPTY_HASH_VALUE;
|
||||
hash[i] = K_EMPTY_HASH_VALUE;
|
||||
}
|
||||
_cyclicBufferPos = 0;
|
||||
ReduceOffsets(-1);
|
||||
@@ -141,6 +140,8 @@ internal sealed class BinTree : InWindow
|
||||
|
||||
public uint GetMatches(uint[] distances)
|
||||
{
|
||||
var son = _son.NotNull();
|
||||
var hash = _hash.NotNull();
|
||||
uint lenLimit;
|
||||
if (_pos + _matchMaxLen <= _streamPos)
|
||||
{
|
||||
@@ -164,26 +165,27 @@ internal sealed class BinTree : InWindow
|
||||
hash2Value = 0,
|
||||
hash3Value = 0;
|
||||
|
||||
var bufferBase = _bufferBase.NotNull();
|
||||
if (_hashArray)
|
||||
{
|
||||
var temp = Crc.TABLE[_bufferBase[cur]] ^ _bufferBase[cur + 1];
|
||||
var temp = Crc.TABLE[bufferBase[cur]] ^ bufferBase[cur + 1];
|
||||
hash2Value = temp & (K_HASH2_SIZE - 1);
|
||||
temp ^= ((uint)(_bufferBase[cur + 2]) << 8);
|
||||
temp ^= ((uint)(bufferBase[cur + 2]) << 8);
|
||||
hash3Value = temp & (K_HASH3_SIZE - 1);
|
||||
hashValue = (temp ^ (Crc.TABLE[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
hashValue = (temp ^ (Crc.TABLE[bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashValue = _bufferBase[cur] ^ ((uint)(_bufferBase[cur + 1]) << 8);
|
||||
hashValue = bufferBase[cur] ^ ((uint)(bufferBase[cur + 1]) << 8);
|
||||
}
|
||||
|
||||
var curMatch = _hash[_kFixHashSize + hashValue];
|
||||
var curMatch = hash[_kFixHashSize + hashValue];
|
||||
if (_hashArray)
|
||||
{
|
||||
var curMatch2 = _hash[hash2Value];
|
||||
var curMatch3 = _hash[K_HASH3_OFFSET + hash3Value];
|
||||
_hash[hash2Value] = _pos;
|
||||
_hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
var curMatch2 = hash[hash2Value];
|
||||
var curMatch3 = hash[K_HASH3_OFFSET + hash3Value];
|
||||
hash[hash2Value] = _pos;
|
||||
hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
if (curMatch2 > matchMinPos)
|
||||
{
|
||||
if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
|
||||
@@ -212,7 +214,7 @@ internal sealed class BinTree : InWindow
|
||||
}
|
||||
}
|
||||
|
||||
_hash[_kFixHashSize + hashValue] = _pos;
|
||||
hash[_kFixHashSize + hashValue] = _pos;
|
||||
|
||||
var ptr0 = (_cyclicBufferPos << 1) + 1;
|
||||
var ptr1 = (_cyclicBufferPos << 1);
|
||||
@@ -242,7 +244,7 @@ internal sealed class BinTree : InWindow
|
||||
{
|
||||
if (curMatch <= matchMinPos || count-- == 0)
|
||||
{
|
||||
_son[ptr0] = _son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
son[ptr0] = son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
break;
|
||||
}
|
||||
var delta = _pos - curMatch;
|
||||
@@ -270,24 +272,24 @@ internal sealed class BinTree : InWindow
|
||||
distances[offset++] = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
_son[ptr0] = _son[cyclicPos + 1];
|
||||
son[ptr1] = son[cyclicPos];
|
||||
son[ptr0] = son[cyclicPos + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
|
||||
{
|
||||
_son[ptr1] = curMatch;
|
||||
son[ptr1] = curMatch;
|
||||
ptr1 = cyclicPos + 1;
|
||||
curMatch = _son[ptr1];
|
||||
curMatch = son[ptr1];
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
_son[ptr0] = curMatch;
|
||||
son[ptr0] = curMatch;
|
||||
ptr0 = cyclicPos;
|
||||
curMatch = _son[ptr0];
|
||||
curMatch = son[ptr0];
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
@@ -297,6 +299,8 @@ internal sealed class BinTree : InWindow
|
||||
|
||||
public void Skip(uint num)
|
||||
{
|
||||
var son = _son.NotNull();
|
||||
var hash = _hash.NotNull();
|
||||
do
|
||||
{
|
||||
uint lenLimit;
|
||||
@@ -323,10 +327,10 @@ internal sealed class BinTree : InWindow
|
||||
{
|
||||
var temp = Crc.TABLE[_bufferBase[cur]] ^ _bufferBase[cur + 1];
|
||||
var hash2Value = temp & (K_HASH2_SIZE - 1);
|
||||
_hash[hash2Value] = _pos;
|
||||
hash[hash2Value] = _pos;
|
||||
temp ^= ((uint)(_bufferBase[cur + 2]) << 8);
|
||||
var hash3Value = temp & (K_HASH3_SIZE - 1);
|
||||
_hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
hash[K_HASH3_OFFSET + hash3Value] = _pos;
|
||||
hashValue = (temp ^ (Crc.TABLE[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
@@ -334,8 +338,8 @@ internal sealed class BinTree : InWindow
|
||||
hashValue = _bufferBase[cur] ^ ((uint)(_bufferBase[cur + 1]) << 8);
|
||||
}
|
||||
|
||||
var curMatch = _hash[_kFixHashSize + hashValue];
|
||||
_hash[_kFixHashSize + hashValue] = _pos;
|
||||
var curMatch = hash[_kFixHashSize + hashValue];
|
||||
hash[_kFixHashSize + hashValue] = _pos;
|
||||
|
||||
var ptr0 = (_cyclicBufferPos << 1) + 1;
|
||||
var ptr1 = (_cyclicBufferPos << 1);
|
||||
@@ -349,7 +353,7 @@ internal sealed class BinTree : InWindow
|
||||
{
|
||||
if (curMatch <= matchMinPos || count-- == 0)
|
||||
{
|
||||
_son[ptr0] = _son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
son[ptr0] = son[ptr1] = K_EMPTY_HASH_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -374,23 +378,23 @@ internal sealed class BinTree : InWindow
|
||||
}
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
_son[ptr0] = _son[cyclicPos + 1];
|
||||
son[ptr1] = son[cyclicPos];
|
||||
son[ptr0] = son[cyclicPos + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
|
||||
{
|
||||
_son[ptr1] = curMatch;
|
||||
son[ptr1] = curMatch;
|
||||
ptr1 = cyclicPos + 1;
|
||||
curMatch = _son[ptr1];
|
||||
curMatch = son[ptr1];
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
_son[ptr0] = curMatch;
|
||||
son[ptr0] = curMatch;
|
||||
ptr0 = cyclicPos;
|
||||
curMatch = _son[ptr0];
|
||||
curMatch = son[ptr0];
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
@@ -418,8 +422,8 @@ internal sealed class BinTree : InWindow
|
||||
private void Normalize()
|
||||
{
|
||||
var subValue = _pos - _cyclicBufferSize;
|
||||
NormalizeLinks(_son, _cyclicBufferSize * 2, subValue);
|
||||
NormalizeLinks(_hash, _hashSizeSum, subValue);
|
||||
NormalizeLinks(_son.NotNull(), _cyclicBufferSize * 2, subValue);
|
||||
NormalizeLinks(_hash.NotNull(), _hashSizeSum, subValue);
|
||||
ReduceOffsets((int)subValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -25,6 +23,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
)
|
||||
{
|
||||
return await _lowCoder[posState]
|
||||
.NotNull()
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -35,6 +34,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
)
|
||||
{
|
||||
symbol += await _midCoder[posState]
|
||||
.NotNull()
|
||||
.DecodeAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -108,7 +108,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
byte prevByte,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
await _coders[GetState(pos, prevByte)]
|
||||
await _coders
|
||||
.NotNull()[GetState(pos, prevByte)]
|
||||
.DecodeNormalAsync(rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@@ -119,7 +120,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
byte matchByte,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
await _coders[GetState(pos, prevByte)]
|
||||
await _coders
|
||||
.NotNull()[GetState(pos, prevByte)]
|
||||
.DecodeWithMatchByteAsync(rangeDecoder, matchByte, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -137,26 +139,26 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
await _outWindow.InitAsync(outStream);
|
||||
await _outWindow.NotNull().InitAsync(outStream);
|
||||
if (outSize > 0)
|
||||
{
|
||||
_outWindow.SetLimit(outSize);
|
||||
_outWindow.NotNull().SetLimit(outSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
_outWindow.SetLimit(long.MaxValue - _outWindow.Total);
|
||||
_outWindow.NotNull().SetLimit(long.MaxValue - _outWindow.NotNull().Total);
|
||||
}
|
||||
|
||||
var rangeDecoder = new RangeCoder.Decoder();
|
||||
await rangeDecoder.InitAsync(inStream, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await CodeAsync(_dictionarySize, _outWindow, rangeDecoder, cancellationToken)
|
||||
await CodeAsync(_dictionarySize, _outWindow.NotNull(), rangeDecoder, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
await _outWindow.ReleaseStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
await _outWindow.NotNull().ReleaseStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
rangeDecoder.ReleaseStream();
|
||||
|
||||
await _outWindow.DisposeAsync().ConfigureAwait(false);
|
||||
await _outWindow.NotNull().DisposeAsync().ConfigureAwait(false);
|
||||
_outWindow = null;
|
||||
}
|
||||
|
||||
@@ -339,6 +341,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
await _outWindow.TrainAsync(stream);
|
||||
await _outWindow.NotNull().TrainAsync(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
@@ -15,8 +13,12 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
{
|
||||
private BitDecoder _choice = new();
|
||||
private BitDecoder _choice2 = new();
|
||||
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(Base.K_NUM_HIGH_LEN_BITS);
|
||||
private uint _numPosStates;
|
||||
|
||||
@@ -35,8 +37,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
_choice.Init();
|
||||
for (uint posState = 0; posState < _numPosStates; posState++)
|
||||
{
|
||||
_lowCoder[posState].Init();
|
||||
_midCoder[posState].Init();
|
||||
_lowCoder[posState].NotNull().Init();
|
||||
_midCoder[posState].NotNull().Init();
|
||||
}
|
||||
_choice2.Init();
|
||||
_highCoder.Init();
|
||||
@@ -46,12 +48,12 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
{
|
||||
if (_choice.Decode(rangeDecoder) == 0)
|
||||
{
|
||||
return _lowCoder[posState].Decode(rangeDecoder);
|
||||
return _lowCoder[posState].NotNull().Decode(rangeDecoder);
|
||||
}
|
||||
var symbol = Base.K_NUM_LOW_LEN_SYMBOLS;
|
||||
if (_choice2.Decode(rangeDecoder) == 0)
|
||||
{
|
||||
symbol += _midCoder[posState].Decode(rangeDecoder);
|
||||
symbol += _midCoder[posState].NotNull().Decode(rangeDecoder);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -110,7 +112,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
}
|
||||
}
|
||||
|
||||
private Decoder2[] _coders;
|
||||
private Decoder2[]? _coders;
|
||||
private int _numPrevBits;
|
||||
private int _numPosBits;
|
||||
private uint _posMask;
|
||||
@@ -134,10 +136,11 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
|
||||
public void Init()
|
||||
{
|
||||
var coders = _coders.NotNull();
|
||||
var numStates = (uint)1 << (_numPrevBits + _numPosBits);
|
||||
for (uint i = 0; i < numStates; i++)
|
||||
{
|
||||
_coders[i].Init();
|
||||
coders[i].Init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,17 +148,18 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
((pos & _posMask) << _numPrevBits) + (uint)(prevByte >> (8 - _numPrevBits));
|
||||
|
||||
public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte) =>
|
||||
_coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder);
|
||||
_coders.NotNull()[GetState(pos, prevByte)].DecodeNormal(rangeDecoder);
|
||||
|
||||
public byte DecodeWithMatchByte(
|
||||
RangeCoder.Decoder rangeDecoder,
|
||||
uint pos,
|
||||
byte prevByte,
|
||||
byte matchByte
|
||||
) => _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte);
|
||||
) =>
|
||||
_coders.NotNull()[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte);
|
||||
}
|
||||
|
||||
private OutWindow _outWindow;
|
||||
private OutWindow? _outWindow;
|
||||
|
||||
private readonly BitDecoder[] _isMatchDecoders = new BitDecoder[
|
||||
Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX
|
||||
@@ -285,32 +289,32 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
Stream outStream,
|
||||
long inSize,
|
||||
long outSize,
|
||||
ICodeProgress progress
|
||||
ICodeProgress? progress
|
||||
)
|
||||
{
|
||||
if (_outWindow is null)
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
_outWindow.Init(outStream);
|
||||
_outWindow.NotNull().Init(outStream);
|
||||
if (outSize > 0)
|
||||
{
|
||||
_outWindow.SetLimit(outSize);
|
||||
_outWindow.NotNull().SetLimit(outSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
_outWindow.SetLimit(long.MaxValue - _outWindow.Total);
|
||||
_outWindow.NotNull().SetLimit(long.MaxValue - _outWindow.NotNull().Total);
|
||||
}
|
||||
|
||||
var rangeDecoder = new RangeCoder.Decoder();
|
||||
rangeDecoder.Init(inStream);
|
||||
|
||||
Code(_dictionarySize, _outWindow, rangeDecoder);
|
||||
Code(_dictionarySize, _outWindow.NotNull(), rangeDecoder);
|
||||
|
||||
_outWindow.ReleaseStream();
|
||||
_outWindow.NotNull().ReleaseStream();
|
||||
rangeDecoder.ReleaseStream();
|
||||
|
||||
_outWindow.Dispose();
|
||||
_outWindow.NotNull().Dispose();
|
||||
_outWindow = null;
|
||||
}
|
||||
|
||||
@@ -473,6 +477,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
|
||||
{
|
||||
CreateDictionary();
|
||||
}
|
||||
_outWindow.Train(stream);
|
||||
_outWindow.NotNull().Train(stream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public partial class LzmaStream
|
||||
_decoder.SetDecoderProperties(Properties);
|
||||
}
|
||||
|
||||
await _rangeDecoder.InitAsync(_inputStream, cancellationToken);
|
||||
await _rangeDecoder.InitAsync(_inputStream.NotNull(), cancellationToken);
|
||||
}
|
||||
else if (control > 0x02)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -17,7 +15,7 @@ internal partial class Encoder
|
||||
{
|
||||
var b = (byte)(temp + (_low >> 32));
|
||||
var buffer = new[] { b };
|
||||
await _stream.WriteAsync(buffer, 0, 1, cancellationToken).ConfigureAwait(false);
|
||||
await Stream.WriteAsync(buffer, 0, 1, cancellationToken).ConfigureAwait(false);
|
||||
temp = 0xFF;
|
||||
} while (--_cacheSize != 0);
|
||||
_cache = (byte)(((uint)_low) >> 24);
|
||||
@@ -72,7 +70,7 @@ internal partial class Encoder
|
||||
}
|
||||
|
||||
public async ValueTask FlushStreamAsync(CancellationToken cancellationToken = default) =>
|
||||
await _stream.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
await Stream.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal partial class Decoder
|
||||
@@ -103,7 +101,7 @@ internal partial class Decoder
|
||||
while (_range < K_TOP_VALUE)
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var read = await _stream
|
||||
var read = await Stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
@@ -121,7 +119,7 @@ internal partial class Decoder
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var read = await _stream
|
||||
var read = await Stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
@@ -152,7 +150,7 @@ internal partial class Decoder
|
||||
|
||||
if (range < K_TOP_VALUE)
|
||||
{
|
||||
var read = await _stream
|
||||
var read = await Stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -9,7 +7,7 @@ internal partial class Encoder
|
||||
{
|
||||
public const uint K_TOP_VALUE = (1 << 24);
|
||||
|
||||
private Stream _stream;
|
||||
private Stream? _stream;
|
||||
|
||||
public ulong _low;
|
||||
public uint _range;
|
||||
@@ -22,6 +20,8 @@ internal partial class Encoder
|
||||
|
||||
public void ReleaseStream() => _stream = null;
|
||||
|
||||
private Stream Stream => _stream.NotNull();
|
||||
|
||||
public void Init()
|
||||
{
|
||||
//StartPosition = Stream.Position;
|
||||
@@ -40,9 +40,9 @@ internal partial class Encoder
|
||||
}
|
||||
}
|
||||
|
||||
public void FlushStream() => _stream.Flush();
|
||||
public void FlushStream() => Stream.Flush();
|
||||
|
||||
public void CloseStream() => _stream.Dispose();
|
||||
public void CloseStream() => Stream.Dispose();
|
||||
|
||||
public void ShiftLow()
|
||||
{
|
||||
@@ -51,7 +51,7 @@ internal partial class Encoder
|
||||
var temp = _cache;
|
||||
do
|
||||
{
|
||||
_stream.WriteByte((byte)(temp + (_low >> 32)));
|
||||
Stream.WriteByte((byte)(temp + (_low >> 32)));
|
||||
temp = 0xFF;
|
||||
} while (--_cacheSize != 0);
|
||||
_cache = (byte)(((uint)_low) >> 24);
|
||||
@@ -86,7 +86,7 @@ internal partial class Decoder
|
||||
public uint _range;
|
||||
public uint _code;
|
||||
|
||||
public Stream _stream;
|
||||
public Stream? _stream;
|
||||
public long _total;
|
||||
|
||||
public void Init(Stream stream)
|
||||
@@ -97,7 +97,7 @@ internal partial class Decoder
|
||||
_range = 0xFFFFFFFF;
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
_code = (_code << 8) | (byte)_stream.ReadByte();
|
||||
_code = (_code << 8) | (byte)stream.ReadByte();
|
||||
}
|
||||
_total = 5;
|
||||
}
|
||||
@@ -106,11 +106,13 @@ internal partial class Decoder
|
||||
// Stream.ReleaseStream();
|
||||
_stream = null;
|
||||
|
||||
private Stream Stream => _stream.NotNull();
|
||||
|
||||
public void Normalize()
|
||||
{
|
||||
while (_range < K_TOP_VALUE)
|
||||
{
|
||||
_code = (_code << 8) | (byte)_stream.ReadByte();
|
||||
_code = (_code << 8) | (byte)Stream.ReadByte();
|
||||
_range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
@@ -121,7 +123,7 @@ internal partial class Decoder
|
||||
{
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
_code = (_code << 8) | (byte)_stream.ReadByte();
|
||||
_code = (_code << 8) | (byte)Stream.ReadByte();
|
||||
_range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
@@ -150,7 +152,7 @@ internal partial class Decoder
|
||||
|
||||
if (range < K_TOP_VALUE)
|
||||
{
|
||||
code = (code << 8) | (byte)_stream.ReadByte();
|
||||
code = (code << 8) | (byte)Stream.ReadByte();
|
||||
range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -15,9 +13,9 @@ public class PpmdStream : Stream
|
||||
private readonly PpmdProperties _properties;
|
||||
private readonly Stream _stream;
|
||||
private readonly bool _compress;
|
||||
private Model _model;
|
||||
private ModelPpm _modelH;
|
||||
private Decoder _decoder;
|
||||
private Model? _model;
|
||||
private ModelPpm? _modelH;
|
||||
private Decoder? _decoder;
|
||||
private long _position;
|
||||
private bool _isDisposed;
|
||||
|
||||
@@ -178,7 +176,7 @@ public class PpmdStream : Stream
|
||||
{
|
||||
if (_compress)
|
||||
{
|
||||
_model.EncodeBlock(_stream, new MemoryStream(), true);
|
||||
_model.NotNull().EncodeBlock(_stream, new MemoryStream(), true);
|
||||
}
|
||||
}
|
||||
base.Dispose(isDisposing);
|
||||
@@ -201,12 +199,12 @@ public class PpmdStream : Stream
|
||||
var size = 0;
|
||||
if (_properties.Version == PpmdVersion.I1)
|
||||
{
|
||||
size = _model.DecodeBlock(_stream, buffer, offset, count);
|
||||
size = _model.NotNull().DecodeBlock(_stream, buffer, offset, count);
|
||||
}
|
||||
if (_properties.Version == PpmdVersion.H)
|
||||
{
|
||||
int c;
|
||||
while (size < count && (c = _modelH.DecodeChar()) >= 0)
|
||||
while (size < count && (c = _modelH.NotNull().DecodeChar()) >= 0)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
size++;
|
||||
@@ -215,7 +213,7 @@ public class PpmdStream : Stream
|
||||
if (_properties.Version == PpmdVersion.H7Z)
|
||||
{
|
||||
int c;
|
||||
while (size < count && (c = _modelH.DecodeChar(_decoder)) >= 0)
|
||||
while (size < count && (c = _modelH.NotNull().DecodeChar(_decoder.NotNull())) >= 0)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
size++;
|
||||
@@ -247,6 +245,7 @@ public class PpmdStream : Stream
|
||||
if (_properties.Version == PpmdVersion.I1)
|
||||
{
|
||||
size = await _model
|
||||
.NotNull()
|
||||
.DecodeBlockAsync(_stream, buffer, offset, count, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
@@ -255,7 +254,12 @@ public class PpmdStream : Stream
|
||||
int c;
|
||||
while (
|
||||
size < count
|
||||
&& (c = await _modelH.DecodeCharAsync(cancellationToken).ConfigureAwait(false)) >= 0
|
||||
&& (
|
||||
c = await _modelH
|
||||
.NotNull()
|
||||
.DecodeCharAsync(cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
{
|
||||
buffer[offset++] = (byte)c;
|
||||
@@ -269,7 +273,8 @@ public class PpmdStream : Stream
|
||||
size < count
|
||||
&& (
|
||||
c = await _modelH
|
||||
.DecodeCharAsync(_decoder, cancellationToken)
|
||||
.NotNull()
|
||||
.DecodeCharAsync(_decoder.NotNull(), cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
@@ -304,6 +309,7 @@ public class PpmdStream : Stream
|
||||
// Need to use a temporary buffer since DecodeBlockAsync works with byte[]
|
||||
var tempBuffer = new byte[count];
|
||||
size = await _model
|
||||
.NotNull()
|
||||
.DecodeBlockAsync(_stream, tempBuffer, 0, count, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
tempBuffer.AsMemory(0, size).CopyTo(buffer);
|
||||
@@ -313,7 +319,12 @@ public class PpmdStream : Stream
|
||||
int c;
|
||||
while (
|
||||
size < count
|
||||
&& (c = await _modelH.DecodeCharAsync(cancellationToken).ConfigureAwait(false)) >= 0
|
||||
&& (
|
||||
c = await _modelH
|
||||
.NotNull()
|
||||
.DecodeCharAsync(cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
{
|
||||
buffer.Span[offset++] = (byte)c;
|
||||
@@ -327,7 +338,8 @@ public class PpmdStream : Stream
|
||||
size < count
|
||||
&& (
|
||||
c = await _modelH
|
||||
.DecodeCharAsync(_decoder, cancellationToken)
|
||||
.NotNull()
|
||||
.DecodeCharAsync(_decoder.NotNull(), cancellationToken)
|
||||
.ConfigureAwait(false)
|
||||
) >= 0
|
||||
)
|
||||
@@ -345,7 +357,7 @@ public class PpmdStream : Stream
|
||||
{
|
||||
if (_compress)
|
||||
{
|
||||
_model.EncodeBlock(_stream, new MemoryStream(buffer, offset, count), false);
|
||||
_model.NotNull().EncodeBlock(_stream, new MemoryStream(buffer, offset, count), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
@@ -47,7 +45,7 @@ internal partial class RarStream
|
||||
if (tmpCount > 0)
|
||||
{
|
||||
var toCopy = tmpCount < count ? tmpCount : count;
|
||||
Buffer.BlockCopy(tmpBuffer, tmpOffset, buffer, offset, toCopy);
|
||||
Buffer.BlockCopy(tmpBuffer.NotNull(), tmpOffset, buffer, offset, toCopy);
|
||||
tmpOffset += toCopy;
|
||||
tmpCount -= toCopy;
|
||||
offset += toCopy;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
@@ -15,11 +13,11 @@ internal partial class RarStream : Stream
|
||||
|
||||
private bool fetch;
|
||||
|
||||
private byte[] tmpBuffer = ArrayPool<byte>.Shared.Rent(65536);
|
||||
private byte[]? tmpBuffer = ArrayPool<byte>.Shared.Rent(65536);
|
||||
private int tmpOffset;
|
||||
private int tmpCount;
|
||||
|
||||
private byte[] outBuffer;
|
||||
private byte[]? outBuffer;
|
||||
private int outOffset;
|
||||
private int outCount;
|
||||
private int outTotal;
|
||||
@@ -47,8 +45,11 @@ internal partial class RarStream : Stream
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(this.tmpBuffer);
|
||||
this.tmpBuffer = null;
|
||||
if (this.tmpBuffer is not null)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(this.tmpBuffer);
|
||||
this.tmpBuffer = null;
|
||||
}
|
||||
readStream.Dispose();
|
||||
}
|
||||
isDisposed = true;
|
||||
@@ -79,7 +80,7 @@ internal partial class RarStream : Stream
|
||||
if (tmpCount > 0)
|
||||
{
|
||||
var toCopy = tmpCount < count ? tmpCount : count;
|
||||
Buffer.BlockCopy(tmpBuffer, tmpOffset, buffer, offset, toCopy);
|
||||
Buffer.BlockCopy(tmpBuffer.NotNull(), tmpOffset, buffer, offset, toCopy);
|
||||
tmpOffset += toCopy;
|
||||
tmpCount -= toCopy;
|
||||
offset += toCopy;
|
||||
@@ -119,7 +120,7 @@ internal partial class RarStream : Stream
|
||||
if (outCount > 0)
|
||||
{
|
||||
var toCopy = outCount < count ? outCount : count;
|
||||
Buffer.BlockCopy(buffer, offset, outBuffer, outOffset, toCopy);
|
||||
Buffer.BlockCopy(buffer, offset, outBuffer.NotNull(), outOffset, toCopy);
|
||||
outOffset += toCopy;
|
||||
outCount -= toCopy;
|
||||
offset += toCopy;
|
||||
@@ -129,7 +130,7 @@ internal partial class RarStream : Stream
|
||||
if (count > 0)
|
||||
{
|
||||
EnsureBufferCapacity(count);
|
||||
Buffer.BlockCopy(buffer, offset, tmpBuffer, tmpCount, count);
|
||||
Buffer.BlockCopy(buffer, offset, tmpBuffer.NotNull(), tmpCount, count);
|
||||
tmpCount += count;
|
||||
tmpOffset = 0;
|
||||
unpack.Suspended = true;
|
||||
@@ -142,15 +143,16 @@ internal partial class RarStream : Stream
|
||||
|
||||
private void EnsureBufferCapacity(int count)
|
||||
{
|
||||
if (this.tmpBuffer.Length < this.tmpCount + count)
|
||||
var buffer = this.tmpBuffer.NotNull();
|
||||
if (buffer.Length < this.tmpCount + count)
|
||||
{
|
||||
var newLength =
|
||||
this.tmpBuffer.Length * 2 > this.tmpCount + count
|
||||
? this.tmpBuffer.Length * 2
|
||||
buffer.Length * 2 > this.tmpCount + count
|
||||
? buffer.Length * 2
|
||||
: this.tmpCount + count;
|
||||
var newBuffer = ArrayPool<byte>.Shared.Rent(newLength);
|
||||
Buffer.BlockCopy(this.tmpBuffer, 0, newBuffer, 0, this.tmpCount);
|
||||
var oldBuffer = this.tmpBuffer;
|
||||
Buffer.BlockCopy(buffer, 0, newBuffer, 0, this.tmpCount);
|
||||
var oldBuffer = buffer;
|
||||
this.tmpBuffer = newBuffer;
|
||||
ArrayPool<byte>.Shared.Return(oldBuffer);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
@@ -10,7 +8,7 @@ public static class Crc32
|
||||
public const uint DefaultPolynomial = 0xedb88320u;
|
||||
public const uint DefaultSeed = 0xffffffffu;
|
||||
|
||||
private static uint[] defaultTable;
|
||||
private static uint[]? defaultTable;
|
||||
|
||||
public static uint Compute(byte[] buffer) => Compute(DefaultSeed, buffer);
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
@@ -9,7 +7,7 @@ public static class Crc64
|
||||
{
|
||||
public const ulong DefaultSeed = 0x0;
|
||||
|
||||
internal static ulong[] Table;
|
||||
internal static ulong[]? Table;
|
||||
|
||||
public const ulong Iso3309Polynomial = 0xD800000000000000;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -36,7 +34,7 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
|
||||
private void AssertBlockCheckTypeIsSupported()
|
||||
{
|
||||
switch (Header.BlockCheckType)
|
||||
switch (Header.NotNull().BlockCheckType)
|
||||
{
|
||||
case CheckType.NONE:
|
||||
case CheckType.CRC32:
|
||||
@@ -49,11 +47,11 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
}
|
||||
|
||||
private readonly Stream _baseStream;
|
||||
public XZHeader Header { get; private set; }
|
||||
public XZIndex Index { get; private set; }
|
||||
public XZFooter Footer { get; private set; }
|
||||
public XZHeader? Header { get; private set; }
|
||||
public XZIndex? Index { get; private set; }
|
||||
public XZFooter? Footer { get; private set; }
|
||||
public bool HeaderIsRead { get; private set; }
|
||||
private XZBlock _currentBlock;
|
||||
private XZBlock? _currentBlock;
|
||||
|
||||
private bool _endOfStream;
|
||||
|
||||
@@ -113,7 +111,7 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
|
||||
var remaining = count - bytesRead;
|
||||
var newOffset = offset + bytesRead;
|
||||
var justRead = _currentBlock.Read(buffer, newOffset, remaining);
|
||||
var justRead = _currentBlock.NotNull().Read(buffer, newOffset, remaining);
|
||||
if (justRead < remaining)
|
||||
{
|
||||
NextBlock();
|
||||
@@ -130,5 +128,9 @@ public sealed partial class XZStream : XZReadOnlyStream
|
||||
}
|
||||
|
||||
private void NextBlock() =>
|
||||
_currentBlock = new XZBlock(BaseStream, Header.BlockCheckType, Header.BlockCheckSize);
|
||||
_currentBlock = new XZBlock(
|
||||
BaseStream,
|
||||
Header.NotNull().BlockCheckType,
|
||||
Header.NotNull().BlockCheckSize
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -15,7 +13,7 @@ public sealed class Crc32Stream : Stream
|
||||
public const uint DEFAULT_POLYNOMIAL = 0xedb88320u;
|
||||
public const uint DEFAULT_SEED = 0xffffffffu;
|
||||
|
||||
private static uint[] _defaultTable;
|
||||
private static uint[]? _defaultTable;
|
||||
|
||||
public Crc32Stream(Stream stream)
|
||||
: this(stream, DEFAULT_POLYNOMIAL, DEFAULT_SEED) { }
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -43,7 +41,7 @@ internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
|
||||
|
||||
#region IEnumerator Members
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
object? IEnumerator.Current => Current;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,7 +13,7 @@ namespace SharpCompress.Readers.Ace;
|
||||
internal class MultiVolumeAceReader : AceReader
|
||||
{
|
||||
private readonly IEnumerator<Stream> streams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
|
||||
internal MultiVolumeAceReader(IEnumerable<Stream> streams, ReaderOptions options)
|
||||
: base(options) => this.streams = streams.GetEnumerator();
|
||||
@@ -54,13 +52,13 @@ internal class MultiVolumeAceReader : AceReader
|
||||
{
|
||||
private readonly MultiVolumeAceReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamEnumerator(
|
||||
MultiVolumeAceReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -72,7 +70,12 @@ internal class MultiVolumeAceReader : AceReader
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => this;
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -82,7 +85,7 @@ internal class MultiVolumeAceReader : AceReader
|
||||
{
|
||||
if (isFirst)
|
||||
{
|
||||
Current = reader.Entry.Parts.First();
|
||||
_current = reader.Entry.Parts.First();
|
||||
isFirst = false; //first stream already to go
|
||||
return true;
|
||||
}
|
||||
@@ -93,7 +96,7 @@ internal class MultiVolumeAceReader : AceReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
reader.LoadStreamForReading(tempStream);
|
||||
reader.LoadStreamForReading(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
@@ -107,7 +110,7 @@ internal class MultiVolumeAceReader : AceReader
|
||||
reader.LoadStreamForReading(nextReadableStreams.Current);
|
||||
}
|
||||
|
||||
Current = reader.Entry.Parts.First();
|
||||
_current = reader.Entry.Parts.First();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -16,7 +14,7 @@ namespace SharpCompress.Readers.Arj;
|
||||
internal class MultiVolumeArjReader : ArjReader
|
||||
{
|
||||
private readonly IEnumerator<Stream> streams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
|
||||
internal MultiVolumeArjReader(IEnumerable<Stream> streams, ReaderOptions options)
|
||||
: base(options) => this.streams = streams.GetEnumerator();
|
||||
@@ -55,13 +53,13 @@ internal class MultiVolumeArjReader : ArjReader
|
||||
{
|
||||
private readonly MultiVolumeArjReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamEnumerator(
|
||||
MultiVolumeArjReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -73,7 +71,12 @@ internal class MultiVolumeArjReader : ArjReader
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => this;
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -94,7 +97,7 @@ internal class MultiVolumeArjReader : ArjReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
reader.LoadStreamForReading(tempStream);
|
||||
reader.LoadStreamForReading(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -26,13 +24,13 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
{
|
||||
private readonly MultiVolumeRarReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamAsyncEnumerator(
|
||||
MultiVolumeRarReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -40,7 +38,12 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
this.tempStream = tempStream;
|
||||
}
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> MoveNextAsync()
|
||||
{
|
||||
@@ -57,7 +60,7 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
await reader.LoadStreamForReadingAsync(tempStream);
|
||||
await reader.LoadStreamForReadingAsync(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#nullable disable
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -14,7 +12,7 @@ namespace SharpCompress.Readers.Rar;
|
||||
internal partial class MultiVolumeRarReader : RarReader
|
||||
{
|
||||
private readonly IEnumerator<Stream> streams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
|
||||
internal MultiVolumeRarReader(IEnumerable<Stream> streams, ReaderOptions options)
|
||||
: base(options) => this.streams = streams.GetEnumerator();
|
||||
@@ -55,13 +53,13 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
{
|
||||
private readonly MultiVolumeRarReader reader;
|
||||
private readonly IEnumerator<Stream> nextReadableStreams;
|
||||
private Stream tempStream;
|
||||
private Stream? tempStream;
|
||||
private bool isFirst = true;
|
||||
|
||||
internal MultiVolumeStreamEnumerator(
|
||||
MultiVolumeRarReader r,
|
||||
IEnumerator<Stream> nextReadableStreams,
|
||||
Stream tempStream
|
||||
Stream? tempStream
|
||||
)
|
||||
{
|
||||
reader = r;
|
||||
@@ -73,7 +71,12 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => this;
|
||||
|
||||
public FilePart Current { get; private set; }
|
||||
private FilePart? _current;
|
||||
public FilePart Current
|
||||
{
|
||||
get => _current.NotNull();
|
||||
private set => _current = value;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
@@ -94,7 +97,7 @@ internal partial class MultiVolumeRarReader : RarReader
|
||||
}
|
||||
if (tempStream != null)
|
||||
{
|
||||
reader.LoadStreamForReading(tempStream);
|
||||
reader.LoadStreamForReading(tempStream.NotNull());
|
||||
tempStream = null;
|
||||
}
|
||||
else if (!nextReadableStreams.MoveNext())
|
||||
|
||||
Reference in New Issue
Block a user