mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
More LZMA fixes?
This commit is contained in:
@@ -114,6 +114,8 @@ internal partial class Decoder
|
||||
_total = 5;
|
||||
}
|
||||
|
||||
public void ReleaseStream() => _stream = null;
|
||||
|
||||
public async ValueTask NormalizeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
while (_range < K_TOP_VALUE)
|
||||
@@ -132,6 +134,24 @@ internal partial class Decoder
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask Normalize2Async(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_range < K_TOP_VALUE)
|
||||
{
|
||||
var buffer = new byte[1];
|
||||
var read = await _stream
|
||||
.ReadAsync(buffer, 0, 1, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
}
|
||||
_code = (_code << 8) | buffer[0];
|
||||
_range <<= 8;
|
||||
_total++;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<uint> DecodeDirectBitsAsync(
|
||||
int numTotalBits,
|
||||
CancellationToken cancellationToken = default
|
||||
|
||||
@@ -45,13 +45,13 @@ internal partial struct BitDecoder
|
||||
{
|
||||
decoder._range = newBound;
|
||||
_prob += (K_BIT_MODEL_TOTAL - _prob) >> K_NUM_MOVE_BITS;
|
||||
await decoder.NormalizeAsync(cancellationToken).ConfigureAwait(false);
|
||||
await decoder.Normalize2Async(cancellationToken).ConfigureAwait(false);
|
||||
return 0;
|
||||
}
|
||||
decoder._range -= newBound;
|
||||
decoder._code -= newBound;
|
||||
_prob -= (_prob) >> K_NUM_MOVE_BITS;
|
||||
await decoder.NormalizeAsync(cancellationToken).ConfigureAwait(false);
|
||||
await decoder.Normalize2Async(cancellationToken).ConfigureAwait(false);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user