Compare commits

...

8 Commits

Author SHA1 Message Date
Adam Hathcock
436b2f4a11 some nullability 2026-02-09 14:04:33 +00:00
Adam Hathcock
61133bc010 more nullabilty 2026-02-09 13:45:13 +00:00
Adam Hathcock
8f64d351ac remove more nullability 2026-02-09 13:03:59 +00:00
Adam Hathcock
6bfe4071aa more nullable removed 2026-02-09 12:30:00 +00:00
Adam Hathcock
9fa425d8c5 even more lzma 2026-02-09 12:00:23 +00:00
Adam Hathcock
56c3c92f30 another round 2026-02-09 11:51:20 +00:00
Adam Hathcock
8f3ff5fd65 more nullability 2026-02-09 11:44:55 +00:00
Adam Hathcock
0e96aa4263 easy nullables 2026-02-09 11:30:37 +00:00
35 changed files with 219 additions and 211 deletions

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using SharpCompress.Common.Rar.Headers; using SharpCompress.Common.Rar.Headers;
@@ -12,7 +10,7 @@ internal class CryptKey3 : ICryptKey
private string _password; private string _password;
public CryptKey3(string password) => _password = password ?? ""; public CryptKey3(string? password) => _password = password ?? "";
public ICryptoTransform Transformer(byte[] salt) public ICryptoTransform Transformer(byte[] salt)
{ {

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using SharpCompress.Common.Rar; using SharpCompress.Common.Rar;

View File

@@ -1,5 +1,3 @@
#nullable disable
using SharpCompress.Common.Rar; using SharpCompress.Common.Rar;
using SharpCompress.IO; using SharpCompress.IO;

View File

@@ -65,7 +65,7 @@ public partial class RarHeaderFactory
if (_isRar5 && _cryptInfo != null) if (_isRar5 && _cryptInfo != null)
{ {
await _cryptInfo.ReadInitVAsync(new AsyncMarkingBinaryReader(stream)); 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( reader = await AsyncRarCryptoBinaryReader.Create(
stream, stream,
@@ -189,7 +189,7 @@ public partial class RarHeaderFactory
Options.Password, Options.Password,
fh.Rar5CryptoInfo.NotNull() fh.Rar5CryptoInfo.NotNull()
) )
: new CryptKey3(Options.Password) : new CryptKey3(Options.Password.NotNull())
); );
} }
} }

View File

@@ -62,7 +62,7 @@ public partial class RarHeaderFactory
if (_isRar5 && _cryptInfo != null) if (_isRar5 && _cryptInfo != null)
{ {
_cryptInfo.ReadInitV(new MarkingBinaryReader(stream)); _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); reader = RarCryptoBinaryReader.Create(stream, _headerKey, _cryptInfo.Salt);
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -18,7 +16,7 @@ internal partial class ArchiveDatabase
internal List<long> _packSizes = new(); internal List<long> _packSizes = new();
internal List<uint?> _packCrCs = new(); internal List<uint?> _packCrCs = new();
internal List<CFolder> _folders = new(); internal List<CFolder> _folders = new();
internal List<int> _numUnpackStreamsVector; internal List<int>? _numUnpackStreamsVector;
internal List<CFileItem> _files = new(); internal List<CFileItem> _files = new();
internal List<long> _packStreamStartPositions = new(); internal List<long> _packStreamStartPositions = new();
@@ -47,7 +45,7 @@ internal partial class ArchiveDatabase
_packSizes.Count == 0 _packSizes.Count == 0
&& _packCrCs.Count == 0 && _packCrCs.Count == 0
&& _folders.Count == 0 && _folders.Count == 0
&& _numUnpackStreamsVector.Count == 0 && (_numUnpackStreamsVector?.Count ?? 0) == 0
&& _files.Count == 0; && _files.Count == 0;
private void FillStartPos() private void FillStartPos()
@@ -94,7 +92,7 @@ internal partial class ArchiveDatabase
_folderStartFileIndex.Add(i); // check it _folderStartFileIndex.Add(i); // check it
if (_numUnpackStreamsVector![folderIndex] != 0) if (_numUnpackStreamsVector.NotNull()[folderIndex] != 0)
{ {
break; break;
} }

View File

@@ -1,11 +1,9 @@
#nullable disable
namespace SharpCompress.Common.SevenZip; namespace SharpCompress.Common.SevenZip;
internal class CCoderInfo internal class CCoderInfo
{ {
internal CMethodId _methodId; internal CMethodId _methodId;
internal byte[] _props; internal byte[]? _props;
internal int _numInStreams; internal int _numInStreams;
internal int _numOutStreams; internal int _numOutStreams;
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
namespace SharpCompress.Common.SevenZip; namespace SharpCompress.Common.SevenZip;
@@ -10,7 +8,7 @@ internal class CFileItem
public uint? Attrib { get; internal set; } public uint? Attrib { get; internal set; }
public uint? ExtendedAttrib { get; internal set; } public uint? ExtendedAttrib { get; internal set; }
public uint? Crc { 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 HasStream { get; internal set; }
public bool IsDir { get; internal set; } public bool IsDir { get; internal set; }

View File

@@ -34,7 +34,7 @@ internal class SevenZipFilePart : FilePart
internal CFileItem Header { get; } internal CFileItem Header { get; }
internal CFolder? Folder { get; } internal CFolder? Folder { get; }
internal override string FilePartName => Header.Name; internal override string? FilePartName => Header.Name;
internal override Stream? GetRawStream() => null; internal override Stream? GetRawStream() => null;

View File

@@ -24,8 +24,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#nullable disable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@@ -78,11 +76,12 @@ public sealed partial class ADCStream
var toCopy = count; var toCopy = count;
var copied = 0; var copied = 0;
while (_outPosition + toCopy >= _outBuffer.Length) var outBuf = _outBuffer.NotNull();
while (_outPosition + toCopy >= outBuf.Length)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var piece = _outBuffer.Length - _outPosition; var piece = outBuf.Length - _outPosition;
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, piece); Array.Copy(outBuf, _outPosition, buffer, inPosition, piece);
inPosition += piece; inPosition += piece;
copied += piece; copied += piece;
_position += piece; _position += piece;
@@ -97,9 +96,10 @@ public sealed partial class ADCStream
{ {
return copied; return copied;
} }
outBuf = _outBuffer;
} }
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, toCopy); Array.Copy(outBuf, _outPosition, buffer, inPosition, toCopy);
_outPosition += toCopy; _outPosition += toCopy;
_position += toCopy; _position += toCopy;
copied += toCopy; copied += toCopy;

View File

@@ -24,8 +24,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#nullable disable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@@ -56,7 +54,7 @@ public sealed partial class ADCStream : Stream
/// <summary> /// <summary>
/// Buffer with currently used chunk of decompressed data /// Buffer with currently used chunk of decompressed data
/// </summary> /// </summary>
private byte[] _outBuffer; private byte[]? _outBuffer;
/// <summary> /// <summary>
/// Position in buffer of decompressed data /// Position in buffer of decompressed data
@@ -139,10 +137,11 @@ public sealed partial class ADCStream : Stream
var toCopy = count; var toCopy = count;
var copied = 0; var copied = 0;
while (_outPosition + toCopy >= _outBuffer.Length) while (_outPosition + toCopy >= _outBuffer.NotNull().Length)
{ {
var piece = _outBuffer.Length - _outPosition; var outBuf = _outBuffer.NotNull();
Array.Copy(_outBuffer, _outPosition, buffer, inPosition, piece); var piece = outBuf.Length - _outPosition;
Array.Copy(outBuf, _outPosition, buffer, inPosition, piece);
inPosition += piece; inPosition += piece;
copied += piece; copied += piece;
_position += 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; _outPosition += toCopy;
_position += toCopy; _position += toCopy;
copied += toCopy; copied += toCopy;

View File

@@ -1,3 +1,5 @@
#nullable disable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.IO; using System.IO;
@@ -11,8 +9,8 @@ internal sealed class BinTree : InWindow
private uint _cyclicBufferSize; private uint _cyclicBufferSize;
private uint _matchMaxLen; private uint _matchMaxLen;
private uint[] _son; private uint[]? _son;
private uint[] _hash; private uint[]? _hash;
private uint _cutValue = 0xFF; private uint _cutValue = 0xFF;
private uint _hashMask; private uint _hashMask;
@@ -56,9 +54,10 @@ internal sealed class BinTree : InWindow
public new void Init() public new void Init()
{ {
base.Init(); base.Init();
var hash = _hash.NotNull();
for (uint i = 0; i < _hashSizeSum; i++) for (uint i = 0; i < _hashSizeSum; i++)
{ {
_hash[i] = K_EMPTY_HASH_VALUE; hash[i] = K_EMPTY_HASH_VALUE;
} }
_cyclicBufferPos = 0; _cyclicBufferPos = 0;
ReduceOffsets(-1); ReduceOffsets(-1);
@@ -141,6 +140,8 @@ internal sealed class BinTree : InWindow
public uint GetMatches(uint[] distances) public uint GetMatches(uint[] distances)
{ {
var son = _son.NotNull();
var hash = _hash.NotNull();
uint lenLimit; uint lenLimit;
if (_pos + _matchMaxLen <= _streamPos) if (_pos + _matchMaxLen <= _streamPos)
{ {
@@ -164,26 +165,27 @@ internal sealed class BinTree : InWindow
hash2Value = 0, hash2Value = 0,
hash3Value = 0; hash3Value = 0;
var bufferBase = _bufferBase.NotNull();
if (_hashArray) 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); hash2Value = temp & (K_HASH2_SIZE - 1);
temp ^= ((uint)(_bufferBase[cur + 2]) << 8); temp ^= ((uint)(bufferBase[cur + 2]) << 8);
hash3Value = temp & (K_HASH3_SIZE - 1); 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 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) if (_hashArray)
{ {
var curMatch2 = _hash[hash2Value]; var curMatch2 = hash[hash2Value];
var curMatch3 = _hash[K_HASH3_OFFSET + hash3Value]; var curMatch3 = hash[K_HASH3_OFFSET + hash3Value];
_hash[hash2Value] = _pos; hash[hash2Value] = _pos;
_hash[K_HASH3_OFFSET + hash3Value] = _pos; hash[K_HASH3_OFFSET + hash3Value] = _pos;
if (curMatch2 > matchMinPos) if (curMatch2 > matchMinPos)
{ {
if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur]) 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 ptr0 = (_cyclicBufferPos << 1) + 1;
var ptr1 = (_cyclicBufferPos << 1); var ptr1 = (_cyclicBufferPos << 1);
@@ -242,7 +244,7 @@ internal sealed class BinTree : InWindow
{ {
if (curMatch <= matchMinPos || count-- == 0) if (curMatch <= matchMinPos || count-- == 0)
{ {
_son[ptr0] = _son[ptr1] = K_EMPTY_HASH_VALUE; son[ptr0] = son[ptr1] = K_EMPTY_HASH_VALUE;
break; break;
} }
var delta = _pos - curMatch; var delta = _pos - curMatch;
@@ -270,24 +272,24 @@ internal sealed class BinTree : InWindow
distances[offset++] = delta - 1; distances[offset++] = delta - 1;
if (len == lenLimit) if (len == lenLimit)
{ {
_son[ptr1] = _son[cyclicPos]; son[ptr1] = son[cyclicPos];
_son[ptr0] = _son[cyclicPos + 1]; son[ptr0] = son[cyclicPos + 1];
break; break;
} }
} }
} }
if (_bufferBase[pby1 + len] < _bufferBase[cur + len]) if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
{ {
_son[ptr1] = curMatch; son[ptr1] = curMatch;
ptr1 = cyclicPos + 1; ptr1 = cyclicPos + 1;
curMatch = _son[ptr1]; curMatch = son[ptr1];
len1 = len; len1 = len;
} }
else else
{ {
_son[ptr0] = curMatch; son[ptr0] = curMatch;
ptr0 = cyclicPos; ptr0 = cyclicPos;
curMatch = _son[ptr0]; curMatch = son[ptr0];
len0 = len; len0 = len;
} }
} }
@@ -297,6 +299,8 @@ internal sealed class BinTree : InWindow
public void Skip(uint num) public void Skip(uint num)
{ {
var son = _son.NotNull();
var hash = _hash.NotNull();
do do
{ {
uint lenLimit; uint lenLimit;
@@ -323,10 +327,10 @@ internal sealed class BinTree : InWindow
{ {
var temp = Crc.TABLE[_bufferBase[cur]] ^ _bufferBase[cur + 1]; var temp = Crc.TABLE[_bufferBase[cur]] ^ _bufferBase[cur + 1];
var hash2Value = temp & (K_HASH2_SIZE - 1); var hash2Value = temp & (K_HASH2_SIZE - 1);
_hash[hash2Value] = _pos; hash[hash2Value] = _pos;
temp ^= ((uint)(_bufferBase[cur + 2]) << 8); temp ^= ((uint)(_bufferBase[cur + 2]) << 8);
var hash3Value = temp & (K_HASH3_SIZE - 1); 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; hashValue = (temp ^ (Crc.TABLE[_bufferBase[cur + 3]] << 5)) & _hashMask;
} }
else else
@@ -334,8 +338,8 @@ internal sealed class BinTree : InWindow
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];
_hash[_kFixHashSize + hashValue] = _pos; hash[_kFixHashSize + hashValue] = _pos;
var ptr0 = (_cyclicBufferPos << 1) + 1; var ptr0 = (_cyclicBufferPos << 1) + 1;
var ptr1 = (_cyclicBufferPos << 1); var ptr1 = (_cyclicBufferPos << 1);
@@ -349,7 +353,7 @@ internal sealed class BinTree : InWindow
{ {
if (curMatch <= matchMinPos || count-- == 0) if (curMatch <= matchMinPos || count-- == 0)
{ {
_son[ptr0] = _son[ptr1] = K_EMPTY_HASH_VALUE; son[ptr0] = son[ptr1] = K_EMPTY_HASH_VALUE;
break; break;
} }
@@ -374,23 +378,23 @@ internal sealed class BinTree : InWindow
} }
if (len == lenLimit) if (len == lenLimit)
{ {
_son[ptr1] = _son[cyclicPos]; son[ptr1] = son[cyclicPos];
_son[ptr0] = _son[cyclicPos + 1]; son[ptr0] = son[cyclicPos + 1];
break; break;
} }
} }
if (_bufferBase[pby1 + len] < _bufferBase[cur + len]) if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
{ {
_son[ptr1] = curMatch; son[ptr1] = curMatch;
ptr1 = cyclicPos + 1; ptr1 = cyclicPos + 1;
curMatch = _son[ptr1]; curMatch = son[ptr1];
len1 = len; len1 = len;
} }
else else
{ {
_son[ptr0] = curMatch; son[ptr0] = curMatch;
ptr0 = cyclicPos; ptr0 = cyclicPos;
curMatch = _son[ptr0]; curMatch = son[ptr0];
len0 = len; len0 = len;
} }
} }
@@ -418,8 +422,8 @@ internal sealed class BinTree : InWindow
private void Normalize() private void Normalize()
{ {
var subValue = _pos - _cyclicBufferSize; var subValue = _pos - _cyclicBufferSize;
NormalizeLinks(_son, _cyclicBufferSize * 2, subValue); NormalizeLinks(_son.NotNull(), _cyclicBufferSize * 2, subValue);
NormalizeLinks(_hash, _hashSizeSum, subValue); NormalizeLinks(_hash.NotNull(), _hashSizeSum, subValue);
ReduceOffsets((int)subValue); ReduceOffsets((int)subValue);
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@@ -25,6 +23,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties
) )
{ {
return await _lowCoder[posState] return await _lowCoder[posState]
.NotNull()
.DecodeAsync(rangeDecoder, cancellationToken) .DecodeAsync(rangeDecoder, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@@ -35,6 +34,7 @@ public partial class Decoder : ICoder, ISetDecoderProperties
) )
{ {
symbol += await _midCoder[posState] symbol += await _midCoder[posState]
.NotNull()
.DecodeAsync(rangeDecoder, cancellationToken) .DecodeAsync(rangeDecoder, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@@ -108,7 +108,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
byte prevByte, byte prevByte,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) => ) =>
await _coders[GetState(pos, prevByte)] await _coders
.NotNull()[GetState(pos, prevByte)]
.DecodeNormalAsync(rangeDecoder, cancellationToken) .DecodeNormalAsync(rangeDecoder, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
@@ -119,7 +120,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties
byte matchByte, byte matchByte,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) => ) =>
await _coders[GetState(pos, prevByte)] await _coders
.NotNull()[GetState(pos, prevByte)]
.DecodeWithMatchByteAsync(rangeDecoder, matchByte, cancellationToken) .DecodeWithMatchByteAsync(rangeDecoder, matchByte, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@@ -137,26 +139,26 @@ public partial class Decoder : ICoder, ISetDecoderProperties
{ {
CreateDictionary(); CreateDictionary();
} }
await _outWindow.InitAsync(outStream); await _outWindow.NotNull().InitAsync(outStream);
if (outSize > 0) if (outSize > 0)
{ {
_outWindow.SetLimit(outSize); _outWindow.NotNull().SetLimit(outSize);
} }
else else
{ {
_outWindow.SetLimit(long.MaxValue - _outWindow.Total); _outWindow.NotNull().SetLimit(long.MaxValue - _outWindow.NotNull().Total);
} }
var rangeDecoder = new RangeCoder.Decoder(); var rangeDecoder = new RangeCoder.Decoder();
await rangeDecoder.InitAsync(inStream, cancellationToken).ConfigureAwait(false); await rangeDecoder.InitAsync(inStream, cancellationToken).ConfigureAwait(false);
await CodeAsync(_dictionarySize, _outWindow, rangeDecoder, cancellationToken) await CodeAsync(_dictionarySize, _outWindow.NotNull(), rangeDecoder, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
await _outWindow.ReleaseStreamAsync(cancellationToken).ConfigureAwait(false); await _outWindow.NotNull().ReleaseStreamAsync(cancellationToken).ConfigureAwait(false);
rangeDecoder.ReleaseStream(); rangeDecoder.ReleaseStream();
await _outWindow.DisposeAsync().ConfigureAwait(false); await _outWindow.NotNull().DisposeAsync().ConfigureAwait(false);
_outWindow = null; _outWindow = null;
} }
@@ -339,6 +341,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties
{ {
CreateDictionary(); CreateDictionary();
} }
await _outWindow.TrainAsync(stream); await _outWindow.NotNull().TrainAsync(stream);
} }
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
@@ -15,8 +13,12 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
{ {
private BitDecoder _choice = new(); private BitDecoder _choice = new();
private BitDecoder _choice2 = new(); private BitDecoder _choice2 = new();
private readonly BitTreeDecoder[] _lowCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX]; private readonly BitTreeDecoder?[] _lowCoder = new BitTreeDecoder?[
private readonly BitTreeDecoder[] _midCoder = new BitTreeDecoder[Base.K_NUM_POS_STATES_MAX]; 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 BitTreeDecoder _highCoder = new(Base.K_NUM_HIGH_LEN_BITS);
private uint _numPosStates; private uint _numPosStates;
@@ -35,8 +37,8 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
_choice.Init(); _choice.Init();
for (uint posState = 0; posState < _numPosStates; posState++) for (uint posState = 0; posState < _numPosStates; posState++)
{ {
_lowCoder[posState].Init(); _lowCoder[posState].NotNull().Init();
_midCoder[posState].Init(); _midCoder[posState].NotNull().Init();
} }
_choice2.Init(); _choice2.Init();
_highCoder.Init(); _highCoder.Init();
@@ -46,12 +48,12 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
{ {
if (_choice.Decode(rangeDecoder) == 0) if (_choice.Decode(rangeDecoder) == 0)
{ {
return _lowCoder[posState].Decode(rangeDecoder); return _lowCoder[posState].NotNull().Decode(rangeDecoder);
} }
var symbol = Base.K_NUM_LOW_LEN_SYMBOLS; var symbol = Base.K_NUM_LOW_LEN_SYMBOLS;
if (_choice2.Decode(rangeDecoder) == 0) if (_choice2.Decode(rangeDecoder) == 0)
{ {
symbol += _midCoder[posState].Decode(rangeDecoder); symbol += _midCoder[posState].NotNull().Decode(rangeDecoder);
} }
else 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 _numPrevBits;
private int _numPosBits; private int _numPosBits;
private uint _posMask; private uint _posMask;
@@ -134,10 +136,11 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
public void Init() public void Init()
{ {
var coders = _coders.NotNull();
var numStates = (uint)1 << (_numPrevBits + _numPosBits); var numStates = (uint)1 << (_numPrevBits + _numPosBits);
for (uint i = 0; i < numStates; i++) 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)); ((pos & _posMask) << _numPrevBits) + (uint)(prevByte >> (8 - _numPrevBits));
public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte) => 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( public byte DecodeWithMatchByte(
RangeCoder.Decoder rangeDecoder, RangeCoder.Decoder rangeDecoder,
uint pos, uint pos,
byte prevByte, byte prevByte,
byte matchByte 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[ private readonly BitDecoder[] _isMatchDecoders = new BitDecoder[
Base.K_NUM_STATES << Base.K_NUM_POS_STATES_BITS_MAX 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, Stream outStream,
long inSize, long inSize,
long outSize, long outSize,
ICodeProgress progress ICodeProgress? progress
) )
{ {
if (_outWindow is null) if (_outWindow is null)
{ {
CreateDictionary(); CreateDictionary();
} }
_outWindow.Init(outStream); _outWindow.NotNull().Init(outStream);
if (outSize > 0) if (outSize > 0)
{ {
_outWindow.SetLimit(outSize); _outWindow.NotNull().SetLimit(outSize);
} }
else else
{ {
_outWindow.SetLimit(long.MaxValue - _outWindow.Total); _outWindow.NotNull().SetLimit(long.MaxValue - _outWindow.NotNull().Total);
} }
var rangeDecoder = new RangeCoder.Decoder(); var rangeDecoder = new RangeCoder.Decoder();
rangeDecoder.Init(inStream); rangeDecoder.Init(inStream);
Code(_dictionarySize, _outWindow, rangeDecoder); Code(_dictionarySize, _outWindow.NotNull(), rangeDecoder);
_outWindow.ReleaseStream(); _outWindow.NotNull().ReleaseStream();
rangeDecoder.ReleaseStream(); rangeDecoder.ReleaseStream();
_outWindow.Dispose(); _outWindow.NotNull().Dispose();
_outWindow = null; _outWindow = null;
} }
@@ -473,6 +477,6 @@ public partial class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Strea
{ {
CreateDictionary(); CreateDictionary();
} }
_outWindow.Train(stream); _outWindow.NotNull().Train(stream);
} }
} }

View File

@@ -147,7 +147,7 @@ public partial class LzmaStream
_decoder.SetDecoderProperties(Properties); _decoder.SetDecoderProperties(Properties);
} }
await _rangeDecoder.InitAsync(_inputStream, cancellationToken); await _rangeDecoder.InitAsync(_inputStream.NotNull(), cancellationToken);
} }
else if (control > 0x02) else if (control > 0x02)
{ {

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -17,7 +15,7 @@ internal partial class Encoder
{ {
var b = (byte)(temp + (_low >> 32)); var b = (byte)(temp + (_low >> 32));
var buffer = new[] { b }; var buffer = new[] { b };
await _stream.WriteAsync(buffer, 0, 1, cancellationToken).ConfigureAwait(false); await Stream.WriteAsync(buffer, 0, 1, cancellationToken).ConfigureAwait(false);
temp = 0xFF; temp = 0xFF;
} while (--_cacheSize != 0); } while (--_cacheSize != 0);
_cache = (byte)(((uint)_low) >> 24); _cache = (byte)(((uint)_low) >> 24);
@@ -72,7 +70,7 @@ internal partial class Encoder
} }
public async ValueTask FlushStreamAsync(CancellationToken cancellationToken = default) => public async ValueTask FlushStreamAsync(CancellationToken cancellationToken = default) =>
await _stream.FlushAsync(cancellationToken).ConfigureAwait(false); await Stream.FlushAsync(cancellationToken).ConfigureAwait(false);
} }
internal partial class Decoder internal partial class Decoder
@@ -103,7 +101,7 @@ internal partial class Decoder
while (_range < K_TOP_VALUE) while (_range < K_TOP_VALUE)
{ {
var buffer = new byte[1]; var buffer = new byte[1];
var read = await _stream var read = await Stream
.ReadAsync(buffer, 0, 1, cancellationToken) .ReadAsync(buffer, 0, 1, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (read == 0) if (read == 0)
@@ -121,7 +119,7 @@ internal partial class Decoder
if (_range < K_TOP_VALUE) if (_range < K_TOP_VALUE)
{ {
var buffer = new byte[1]; var buffer = new byte[1];
var read = await _stream var read = await Stream
.ReadAsync(buffer, 0, 1, cancellationToken) .ReadAsync(buffer, 0, 1, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (read == 0) if (read == 0)
@@ -152,7 +150,7 @@ internal partial class Decoder
if (range < K_TOP_VALUE) if (range < K_TOP_VALUE)
{ {
var read = await _stream var read = await Stream
.ReadAsync(buffer, 0, 1, cancellationToken) .ReadAsync(buffer, 0, 1, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (read == 0) if (read == 0)

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -9,7 +7,7 @@ internal partial class Encoder
{ {
public const uint K_TOP_VALUE = (1 << 24); public const uint K_TOP_VALUE = (1 << 24);
private Stream _stream; private Stream? _stream;
public ulong _low; public ulong _low;
public uint _range; public uint _range;
@@ -22,6 +20,8 @@ internal partial class Encoder
public void ReleaseStream() => _stream = null; public void ReleaseStream() => _stream = null;
private Stream Stream => _stream.NotNull();
public void Init() public void Init()
{ {
//StartPosition = Stream.Position; //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() public void ShiftLow()
{ {
@@ -51,7 +51,7 @@ internal partial class Encoder
var temp = _cache; var temp = _cache;
do do
{ {
_stream.WriteByte((byte)(temp + (_low >> 32))); Stream.WriteByte((byte)(temp + (_low >> 32)));
temp = 0xFF; temp = 0xFF;
} while (--_cacheSize != 0); } while (--_cacheSize != 0);
_cache = (byte)(((uint)_low) >> 24); _cache = (byte)(((uint)_low) >> 24);
@@ -86,7 +86,7 @@ internal partial class Decoder
public uint _range; public uint _range;
public uint _code; public uint _code;
public Stream _stream; public Stream? _stream;
public long _total; public long _total;
public void Init(Stream stream) public void Init(Stream stream)
@@ -97,7 +97,7 @@ internal partial class Decoder
_range = 0xFFFFFFFF; _range = 0xFFFFFFFF;
for (var i = 0; i < 5; i++) for (var i = 0; i < 5; i++)
{ {
_code = (_code << 8) | (byte)_stream.ReadByte(); _code = (_code << 8) | (byte)stream.ReadByte();
} }
_total = 5; _total = 5;
} }
@@ -106,11 +106,13 @@ internal partial class Decoder
// Stream.ReleaseStream(); // Stream.ReleaseStream();
_stream = null; _stream = null;
private Stream Stream => _stream.NotNull();
public void Normalize() public void Normalize()
{ {
while (_range < K_TOP_VALUE) while (_range < K_TOP_VALUE)
{ {
_code = (_code << 8) | (byte)_stream.ReadByte(); _code = (_code << 8) | (byte)Stream.ReadByte();
_range <<= 8; _range <<= 8;
_total++; _total++;
} }
@@ -121,7 +123,7 @@ internal partial class Decoder
{ {
if (_range < K_TOP_VALUE) if (_range < K_TOP_VALUE)
{ {
_code = (_code << 8) | (byte)_stream.ReadByte(); _code = (_code << 8) | (byte)Stream.ReadByte();
_range <<= 8; _range <<= 8;
_total++; _total++;
} }
@@ -150,7 +152,7 @@ internal partial class Decoder
if (range < K_TOP_VALUE) if (range < K_TOP_VALUE)
{ {
code = (code << 8) | (byte)_stream.ReadByte(); code = (code << 8) | (byte)Stream.ReadByte();
range <<= 8; range <<= 8;
_total++; _total++;
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@@ -15,9 +13,9 @@ public class PpmdStream : Stream
private readonly PpmdProperties _properties; private readonly PpmdProperties _properties;
private readonly Stream _stream; private readonly Stream _stream;
private readonly bool _compress; private readonly bool _compress;
private Model _model; private Model? _model;
private ModelPpm _modelH; private ModelPpm? _modelH;
private Decoder _decoder; private Decoder? _decoder;
private long _position; private long _position;
private bool _isDisposed; private bool _isDisposed;
@@ -178,7 +176,7 @@ public class PpmdStream : Stream
{ {
if (_compress) if (_compress)
{ {
_model.EncodeBlock(_stream, new MemoryStream(), true); _model.NotNull().EncodeBlock(_stream, new MemoryStream(), true);
} }
} }
base.Dispose(isDisposing); base.Dispose(isDisposing);
@@ -201,12 +199,12 @@ public class PpmdStream : Stream
var size = 0; var size = 0;
if (_properties.Version == PpmdVersion.I1) 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) if (_properties.Version == PpmdVersion.H)
{ {
int c; int c;
while (size < count && (c = _modelH.DecodeChar()) >= 0) while (size < count && (c = _modelH.NotNull().DecodeChar()) >= 0)
{ {
buffer[offset++] = (byte)c; buffer[offset++] = (byte)c;
size++; size++;
@@ -215,7 +213,7 @@ public class PpmdStream : Stream
if (_properties.Version == PpmdVersion.H7Z) if (_properties.Version == PpmdVersion.H7Z)
{ {
int c; int c;
while (size < count && (c = _modelH.DecodeChar(_decoder)) >= 0) while (size < count && (c = _modelH.NotNull().DecodeChar(_decoder.NotNull())) >= 0)
{ {
buffer[offset++] = (byte)c; buffer[offset++] = (byte)c;
size++; size++;
@@ -247,6 +245,7 @@ public class PpmdStream : Stream
if (_properties.Version == PpmdVersion.I1) if (_properties.Version == PpmdVersion.I1)
{ {
size = await _model size = await _model
.NotNull()
.DecodeBlockAsync(_stream, buffer, offset, count, cancellationToken) .DecodeBlockAsync(_stream, buffer, offset, count, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@@ -255,7 +254,12 @@ public class PpmdStream : Stream
int c; int c;
while ( while (
size < count size < count
&& (c = await _modelH.DecodeCharAsync(cancellationToken).ConfigureAwait(false)) >= 0 && (
c = await _modelH
.NotNull()
.DecodeCharAsync(cancellationToken)
.ConfigureAwait(false)
) >= 0
) )
{ {
buffer[offset++] = (byte)c; buffer[offset++] = (byte)c;
@@ -269,7 +273,8 @@ public class PpmdStream : Stream
size < count size < count
&& ( && (
c = await _modelH c = await _modelH
.DecodeCharAsync(_decoder, cancellationToken) .NotNull()
.DecodeCharAsync(_decoder.NotNull(), cancellationToken)
.ConfigureAwait(false) .ConfigureAwait(false)
) >= 0 ) >= 0
) )
@@ -304,6 +309,7 @@ public class PpmdStream : Stream
// Need to use a temporary buffer since DecodeBlockAsync works with byte[] // Need to use a temporary buffer since DecodeBlockAsync works with byte[]
var tempBuffer = new byte[count]; var tempBuffer = new byte[count];
size = await _model size = await _model
.NotNull()
.DecodeBlockAsync(_stream, tempBuffer, 0, count, cancellationToken) .DecodeBlockAsync(_stream, tempBuffer, 0, count, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
tempBuffer.AsMemory(0, size).CopyTo(buffer); tempBuffer.AsMemory(0, size).CopyTo(buffer);
@@ -313,7 +319,12 @@ public class PpmdStream : Stream
int c; int c;
while ( while (
size < count size < count
&& (c = await _modelH.DecodeCharAsync(cancellationToken).ConfigureAwait(false)) >= 0 && (
c = await _modelH
.NotNull()
.DecodeCharAsync(cancellationToken)
.ConfigureAwait(false)
) >= 0
) )
{ {
buffer.Span[offset++] = (byte)c; buffer.Span[offset++] = (byte)c;
@@ -327,7 +338,8 @@ public class PpmdStream : Stream
size < count size < count
&& ( && (
c = await _modelH c = await _modelH
.DecodeCharAsync(_decoder, cancellationToken) .NotNull()
.DecodeCharAsync(_decoder.NotNull(), cancellationToken)
.ConfigureAwait(false) .ConfigureAwait(false)
) >= 0 ) >= 0
) )
@@ -345,7 +357,7 @@ public class PpmdStream : Stream
{ {
if (_compress) if (_compress)
{ {
_model.EncodeBlock(_stream, new MemoryStream(buffer, offset, count), false); _model.NotNull().EncodeBlock(_stream, new MemoryStream(buffer, offset, count), false);
} }
} }
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
@@ -47,7 +45,7 @@ internal partial class RarStream
if (tmpCount > 0) if (tmpCount > 0)
{ {
var toCopy = tmpCount < count ? tmpCount : count; var toCopy = tmpCount < count ? tmpCount : count;
Buffer.BlockCopy(tmpBuffer, tmpOffset, buffer, offset, toCopy); Buffer.BlockCopy(tmpBuffer.NotNull(), tmpOffset, buffer, offset, toCopy);
tmpOffset += toCopy; tmpOffset += toCopy;
tmpCount -= toCopy; tmpCount -= toCopy;
offset += toCopy; offset += toCopy;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
@@ -15,11 +13,11 @@ internal partial class RarStream : Stream
private bool fetch; private bool fetch;
private byte[] tmpBuffer = ArrayPool<byte>.Shared.Rent(65536); private byte[]? tmpBuffer = ArrayPool<byte>.Shared.Rent(65536);
private int tmpOffset; private int tmpOffset;
private int tmpCount; private int tmpCount;
private byte[] outBuffer; private byte[]? outBuffer;
private int outOffset; private int outOffset;
private int outCount; private int outCount;
private int outTotal; private int outTotal;
@@ -47,8 +45,11 @@ internal partial class RarStream : Stream
{ {
if (disposing) if (disposing)
{ {
ArrayPool<byte>.Shared.Return(this.tmpBuffer); if (this.tmpBuffer is not null)
this.tmpBuffer = null; {
ArrayPool<byte>.Shared.Return(this.tmpBuffer);
this.tmpBuffer = null;
}
readStream.Dispose(); readStream.Dispose();
} }
isDisposed = true; isDisposed = true;
@@ -79,7 +80,7 @@ internal partial class RarStream : Stream
if (tmpCount > 0) if (tmpCount > 0)
{ {
var toCopy = tmpCount < count ? tmpCount : count; var toCopy = tmpCount < count ? tmpCount : count;
Buffer.BlockCopy(tmpBuffer, tmpOffset, buffer, offset, toCopy); Buffer.BlockCopy(tmpBuffer.NotNull(), tmpOffset, buffer, offset, toCopy);
tmpOffset += toCopy; tmpOffset += toCopy;
tmpCount -= toCopy; tmpCount -= toCopy;
offset += toCopy; offset += toCopy;
@@ -119,7 +120,7 @@ internal partial class RarStream : Stream
if (outCount > 0) if (outCount > 0)
{ {
var toCopy = outCount < count ? outCount : count; var toCopy = outCount < count ? outCount : count;
Buffer.BlockCopy(buffer, offset, outBuffer, outOffset, toCopy); Buffer.BlockCopy(buffer, offset, outBuffer.NotNull(), outOffset, toCopy);
outOffset += toCopy; outOffset += toCopy;
outCount -= toCopy; outCount -= toCopy;
offset += toCopy; offset += toCopy;
@@ -129,7 +130,7 @@ internal partial class RarStream : Stream
if (count > 0) if (count > 0)
{ {
EnsureBufferCapacity(count); EnsureBufferCapacity(count);
Buffer.BlockCopy(buffer, offset, tmpBuffer, tmpCount, count); Buffer.BlockCopy(buffer, offset, tmpBuffer.NotNull(), tmpCount, count);
tmpCount += count; tmpCount += count;
tmpOffset = 0; tmpOffset = 0;
unpack.Suspended = true; unpack.Suspended = true;
@@ -142,15 +143,16 @@ internal partial class RarStream : Stream
private void EnsureBufferCapacity(int count) 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 = var newLength =
this.tmpBuffer.Length * 2 > this.tmpCount + count buffer.Length * 2 > this.tmpCount + count
? this.tmpBuffer.Length * 2 ? buffer.Length * 2
: this.tmpCount + count; : this.tmpCount + count;
var newBuffer = ArrayPool<byte>.Shared.Rent(newLength); var newBuffer = ArrayPool<byte>.Shared.Rent(newLength);
Buffer.BlockCopy(this.tmpBuffer, 0, newBuffer, 0, this.tmpCount); Buffer.BlockCopy(buffer, 0, newBuffer, 0, this.tmpCount);
var oldBuffer = this.tmpBuffer; var oldBuffer = buffer;
this.tmpBuffer = newBuffer; this.tmpBuffer = newBuffer;
ArrayPool<byte>.Shared.Return(oldBuffer); ArrayPool<byte>.Shared.Return(oldBuffer);
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
namespace SharpCompress.Compressors.Xz; namespace SharpCompress.Compressors.Xz;
@@ -10,7 +8,7 @@ public static class Crc32
public const uint DefaultPolynomial = 0xedb88320u; public const uint DefaultPolynomial = 0xedb88320u;
public const uint DefaultSeed = 0xffffffffu; public const uint DefaultSeed = 0xffffffffu;
private static uint[] defaultTable; private static uint[]? defaultTable;
public static uint Compute(byte[] buffer) => Compute(DefaultSeed, buffer); public static uint Compute(byte[] buffer) => Compute(DefaultSeed, buffer);

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
namespace SharpCompress.Compressors.Xz; namespace SharpCompress.Compressors.Xz;
@@ -9,7 +7,7 @@ public static class Crc64
{ {
public const ulong DefaultSeed = 0x0; public const ulong DefaultSeed = 0x0;
internal static ulong[] Table; internal static ulong[]? Table;
public const ulong Iso3309Polynomial = 0xD800000000000000; public const ulong Iso3309Polynomial = 0xD800000000000000;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@@ -36,7 +34,7 @@ public sealed partial class XZStream : XZReadOnlyStream
private void AssertBlockCheckTypeIsSupported() private void AssertBlockCheckTypeIsSupported()
{ {
switch (Header.BlockCheckType) switch (Header.NotNull().BlockCheckType)
{ {
case CheckType.NONE: case CheckType.NONE:
case CheckType.CRC32: case CheckType.CRC32:
@@ -49,11 +47,11 @@ public sealed partial class XZStream : XZReadOnlyStream
} }
private readonly Stream _baseStream; private readonly Stream _baseStream;
public XZHeader Header { get; private set; } public XZHeader? Header { get; private set; }
public XZIndex Index { get; private set; } public XZIndex? Index { get; private set; }
public XZFooter Footer { get; private set; } public XZFooter? Footer { get; private set; }
public bool HeaderIsRead { get; private set; } public bool HeaderIsRead { get; private set; }
private XZBlock _currentBlock; private XZBlock? _currentBlock;
private bool _endOfStream; private bool _endOfStream;
@@ -113,7 +111,7 @@ public sealed partial class XZStream : XZReadOnlyStream
var remaining = count - bytesRead; var remaining = count - bytesRead;
var newOffset = offset + bytesRead; var newOffset = offset + bytesRead;
var justRead = _currentBlock.Read(buffer, newOffset, remaining); var justRead = _currentBlock.NotNull().Read(buffer, newOffset, remaining);
if (justRead < remaining) if (justRead < remaining)
{ {
NextBlock(); NextBlock();
@@ -130,5 +128,9 @@ public sealed partial class XZStream : XZReadOnlyStream
} }
private void NextBlock() => private void NextBlock() =>
_currentBlock = new XZBlock(BaseStream, Header.BlockCheckType, Header.BlockCheckSize); _currentBlock = new XZBlock(
BaseStream,
Header.NotNull().BlockCheckType,
Header.NotNull().BlockCheckSize
);
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.IO; using System.IO;
@@ -15,7 +13,7 @@ public sealed class Crc32Stream : Stream
public const uint DEFAULT_POLYNOMIAL = 0xedb88320u; public const uint DEFAULT_POLYNOMIAL = 0xedb88320u;
public const uint DEFAULT_SEED = 0xffffffffu; public const uint DEFAULT_SEED = 0xffffffffu;
private static uint[] _defaultTable; private static uint[]? _defaultTable;
public Crc32Stream(Stream stream) public Crc32Stream(Stream stream)
: this(stream, DEFAULT_POLYNOMIAL, DEFAULT_SEED) { } : this(stream, DEFAULT_POLYNOMIAL, DEFAULT_SEED) { }

View File

@@ -1,4 +1,3 @@
#nullable disable
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@@ -43,7 +41,7 @@ internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
#region IEnumerator Members #region IEnumerator Members
object IEnumerator.Current => Current; object? IEnumerator.Current => Current;
public bool MoveNext() public bool MoveNext()
{ {

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@@ -15,7 +13,7 @@ namespace SharpCompress.Readers.Ace;
internal class MultiVolumeAceReader : AceReader internal class MultiVolumeAceReader : AceReader
{ {
private readonly IEnumerator<Stream> streams; private readonly IEnumerator<Stream> streams;
private Stream tempStream; private Stream? tempStream;
internal MultiVolumeAceReader(IEnumerable<Stream> streams, ReaderOptions options) internal MultiVolumeAceReader(IEnumerable<Stream> streams, ReaderOptions options)
: base(options) => this.streams = streams.GetEnumerator(); : base(options) => this.streams = streams.GetEnumerator();
@@ -54,13 +52,13 @@ internal class MultiVolumeAceReader : AceReader
{ {
private readonly MultiVolumeAceReader reader; private readonly MultiVolumeAceReader reader;
private readonly IEnumerator<Stream> nextReadableStreams; private readonly IEnumerator<Stream> nextReadableStreams;
private Stream tempStream; private Stream? tempStream;
private bool isFirst = true; private bool isFirst = true;
internal MultiVolumeStreamEnumerator( internal MultiVolumeStreamEnumerator(
MultiVolumeAceReader r, MultiVolumeAceReader r,
IEnumerator<Stream> nextReadableStreams, IEnumerator<Stream> nextReadableStreams,
Stream tempStream Stream? tempStream
) )
{ {
reader = r; reader = r;
@@ -72,7 +70,12 @@ internal class MultiVolumeAceReader : AceReader
IEnumerator IEnumerable.GetEnumerator() => this; 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() { } public void Dispose() { }
@@ -82,7 +85,7 @@ internal class MultiVolumeAceReader : AceReader
{ {
if (isFirst) if (isFirst)
{ {
Current = reader.Entry.Parts.First(); _current = reader.Entry.Parts.First();
isFirst = false; //first stream already to go isFirst = false; //first stream already to go
return true; return true;
} }
@@ -93,7 +96,7 @@ internal class MultiVolumeAceReader : AceReader
} }
if (tempStream != null) if (tempStream != null)
{ {
reader.LoadStreamForReading(tempStream); reader.LoadStreamForReading(tempStream.NotNull());
tempStream = null; tempStream = null;
} }
else if (!nextReadableStreams.MoveNext()) else if (!nextReadableStreams.MoveNext())
@@ -107,7 +110,7 @@ internal class MultiVolumeAceReader : AceReader
reader.LoadStreamForReading(nextReadableStreams.Current); reader.LoadStreamForReading(nextReadableStreams.Current);
} }
Current = reader.Entry.Parts.First(); _current = reader.Entry.Parts.First();
return true; return true;
} }

View File

@@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@@ -16,7 +14,7 @@ namespace SharpCompress.Readers.Arj;
internal class MultiVolumeArjReader : ArjReader internal class MultiVolumeArjReader : ArjReader
{ {
private readonly IEnumerator<Stream> streams; private readonly IEnumerator<Stream> streams;
private Stream tempStream; private Stream? tempStream;
internal MultiVolumeArjReader(IEnumerable<Stream> streams, ReaderOptions options) internal MultiVolumeArjReader(IEnumerable<Stream> streams, ReaderOptions options)
: base(options) => this.streams = streams.GetEnumerator(); : base(options) => this.streams = streams.GetEnumerator();
@@ -55,13 +53,13 @@ internal class MultiVolumeArjReader : ArjReader
{ {
private readonly MultiVolumeArjReader reader; private readonly MultiVolumeArjReader reader;
private readonly IEnumerator<Stream> nextReadableStreams; private readonly IEnumerator<Stream> nextReadableStreams;
private Stream tempStream; private Stream? tempStream;
private bool isFirst = true; private bool isFirst = true;
internal MultiVolumeStreamEnumerator( internal MultiVolumeStreamEnumerator(
MultiVolumeArjReader r, MultiVolumeArjReader r,
IEnumerator<Stream> nextReadableStreams, IEnumerator<Stream> nextReadableStreams,
Stream tempStream Stream? tempStream
) )
{ {
reader = r; reader = r;
@@ -73,7 +71,12 @@ internal class MultiVolumeArjReader : ArjReader
IEnumerator IEnumerable.GetEnumerator() => this; 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() { } public void Dispose() { }
@@ -94,7 +97,7 @@ internal class MultiVolumeArjReader : ArjReader
} }
if (tempStream != null) if (tempStream != null)
{ {
reader.LoadStreamForReading(tempStream); reader.LoadStreamForReading(tempStream.NotNull());
tempStream = null; tempStream = null;
} }
else if (!nextReadableStreams.MoveNext()) else if (!nextReadableStreams.MoveNext())

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -26,13 +24,13 @@ internal partial class MultiVolumeRarReader : RarReader
{ {
private readonly MultiVolumeRarReader reader; private readonly MultiVolumeRarReader reader;
private readonly IEnumerator<Stream> nextReadableStreams; private readonly IEnumerator<Stream> nextReadableStreams;
private Stream tempStream; private Stream? tempStream;
private bool isFirst = true; private bool isFirst = true;
internal MultiVolumeStreamAsyncEnumerator( internal MultiVolumeStreamAsyncEnumerator(
MultiVolumeRarReader r, MultiVolumeRarReader r,
IEnumerator<Stream> nextReadableStreams, IEnumerator<Stream> nextReadableStreams,
Stream tempStream Stream? tempStream
) )
{ {
reader = r; reader = r;
@@ -40,7 +38,12 @@ internal partial class MultiVolumeRarReader : RarReader
this.tempStream = tempStream; 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() public async ValueTask<bool> MoveNextAsync()
{ {
@@ -57,7 +60,7 @@ internal partial class MultiVolumeRarReader : RarReader
} }
if (tempStream != null) if (tempStream != null)
{ {
await reader.LoadStreamForReadingAsync(tempStream); await reader.LoadStreamForReadingAsync(tempStream.NotNull());
tempStream = null; tempStream = null;
} }
else if (!nextReadableStreams.MoveNext()) else if (!nextReadableStreams.MoveNext())

View File

@@ -1,5 +1,3 @@
#nullable disable
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -14,7 +12,7 @@ namespace SharpCompress.Readers.Rar;
internal partial class MultiVolumeRarReader : RarReader internal partial class MultiVolumeRarReader : RarReader
{ {
private readonly IEnumerator<Stream> streams; private readonly IEnumerator<Stream> streams;
private Stream tempStream; private Stream? tempStream;
internal MultiVolumeRarReader(IEnumerable<Stream> streams, ReaderOptions options) internal MultiVolumeRarReader(IEnumerable<Stream> streams, ReaderOptions options)
: base(options) => this.streams = streams.GetEnumerator(); : base(options) => this.streams = streams.GetEnumerator();
@@ -55,13 +53,13 @@ internal partial class MultiVolumeRarReader : RarReader
{ {
private readonly MultiVolumeRarReader reader; private readonly MultiVolumeRarReader reader;
private readonly IEnumerator<Stream> nextReadableStreams; private readonly IEnumerator<Stream> nextReadableStreams;
private Stream tempStream; private Stream? tempStream;
private bool isFirst = true; private bool isFirst = true;
internal MultiVolumeStreamEnumerator( internal MultiVolumeStreamEnumerator(
MultiVolumeRarReader r, MultiVolumeRarReader r,
IEnumerator<Stream> nextReadableStreams, IEnumerator<Stream> nextReadableStreams,
Stream tempStream Stream? tempStream
) )
{ {
reader = r; reader = r;
@@ -73,7 +71,12 @@ internal partial class MultiVolumeRarReader : RarReader
IEnumerator IEnumerable.GetEnumerator() => this; 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() { } public void Dispose() { }
@@ -94,7 +97,7 @@ internal partial class MultiVolumeRarReader : RarReader
} }
if (tempStream != null) if (tempStream != null)
{ {
reader.LoadStreamForReading(tempStream); reader.LoadStreamForReading(tempStream.NotNull());
tempStream = null; tempStream = null;
} }
else if (!nextReadableStreams.MoveNext()) else if (!nextReadableStreams.MoveNext())