@@ -89,42 +89,8 @@ public class Decompressor
89
89
/// <param name="input">Byte array to decompress</param>
90
90
/// <param name="windowBits">Number of bits in the sliding window</param>
91
91
public Decompressor ( byte [ ] ? input , uint windowBits )
92
- {
93
- // If we have an invalid stream
94
- if ( input == null || input . Length == 0 )
95
- throw new ArgumentException ( nameof ( input ) ) ;
96
-
97
- // If we have an invalid value for the window bits
98
- if ( windowBits < 10 || windowBits > 21 )
99
- throw new ArgumentOutOfRangeException ( nameof ( windowBits ) ) ;
100
-
101
- // Create a memory stream to wrap
102
- var ms = new MemoryStream ( input ) ;
103
-
104
- // Wrap the stream in a ReadOnlyBitStream
105
- _bitStream = new ReadOnlyBitStream ( ms ) ;
106
-
107
- // Initialize literal models
108
- _model0 = CreateModel ( 0 , 64 ) ;
109
- _model1 = CreateModel ( 64 , 64 ) ;
110
- _model2 = CreateModel ( 128 , 64 ) ;
111
- _model3 = CreateModel ( 192 , 64 ) ;
112
-
113
- // Initialize LZ models
114
- int maxBitLength = ( int ) ( windowBits * 2 ) ;
115
- _model4 = CreateModel ( 0 , maxBitLength > 24 ? 24 : maxBitLength ) ;
116
- _model5 = CreateModel ( 0 , maxBitLength > 36 ? 36 : maxBitLength ) ;
117
- _model6 = CreateModel ( 0 , maxBitLength ) ;
118
- _model6len = CreateModel ( 0 , 27 ) ;
119
-
120
- // Initialze the selector model
121
- _selector = CreateModel ( 0 , 7 ) ;
122
-
123
- // Initialize coding state
124
- CS_H = 0 ;
125
- CS_L = 0 ;
126
- CS_C = 0 ;
127
- }
92
+ : this ( new MemoryStream ( input ?? [ ] ) , windowBits )
93
+ { }
128
94
129
95
/// <summary>
130
96
/// Create a new Decompressor from a Stream
@@ -264,12 +230,12 @@ private Model CreateModel(ushort start, int length)
264
230
var model = new Model
265
231
{
266
232
Entries = length ,
267
- Symbols = new ModelSymbol [ length ] ,
233
+ Symbols = new ModelSymbol [ length + 1 ] ,
268
234
TimeToReorder = 4 ,
269
235
} ;
270
236
271
237
// Populate the symbol array
272
- for ( int i = 0 ; i < length ; i ++ )
238
+ for ( int i = 0 ; i <= length ; i ++ )
273
239
{
274
240
model . Symbols [ i ] = new ModelSymbol
275
241
{
@@ -415,7 +381,7 @@ private void UpdateModel(Model model, int lastUpdated)
415
381
private ushort GetFrequency ( ushort totalFrequency )
416
382
{
417
383
ulong range = ( ulong ) ( ( ( CS_H - CS_L ) & 0xFFFF ) + 1 ) ;
418
- ulong frequency = ( ulong ) ( ( CS_C - CS_L + 1 ) * totalFrequency - 1 ) / range ;
384
+ ulong frequency = ( ulong ) ( ( ( CS_C - CS_L + 1 ) * totalFrequency ) - 1 ) / range ;
419
385
return ( ushort ) ( frequency & 0xFFFF ) ;
420
386
}
421
387
}
0 commit comments