︙ | | | ︙ | |
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
{
if (_stream != nil)
[self close];
OFFreeMemory(_slidingWindow);
if (_codeLenTree != NULL)
OFHuffmanTreeFree(_codeLenTree);
if (_litLenTree != NULL)
OFHuffmanTreeFree(_litLenTree);
if (_distTree != NULL)
OFHuffmanTreeFree(_distTree);
OFFreeMemory(_codesLengths);
[super dealloc];
}
- (size_t)lowlevelReadIntoBuffer: (void *)buffer_
|
|
|
|
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
{
if (_stream != nil)
[self close];
OFFreeMemory(_slidingWindow);
if (_codeLenTree != NULL)
_OFHuffmanTreeFree(_codeLenTree);
if (_litLenTree != NULL)
_OFHuffmanTreeFree(_litLenTree);
if (_distTree != NULL)
_OFHuffmanTreeFree(_distTree);
OFFreeMemory(_codesLengths);
[super dealloc];
}
- (size_t)lowlevelReadIntoBuffer: (void *)buffer_
|
︙ | | | ︙ | |
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
if OF_UNLIKELY (bits == 7) {
_currentIsExtendedLength = true;
continue;
} else
_codesReceived++;
}
_codeLenTree = OFHuffmanTreeNew(_codesLengths, _codesCount);
OFFreeMemory(_codesLengths);
_codesLengths = NULL;
_state = stateLitLenCodesCount;
goto start;
case stateCodeLenTreeSingle:
if OF_UNLIKELY (!tryReadBits(self, &bits, 5))
return bytesWritten;
_codeLenTree = OFHuffmanTreeNewSingle(bits);
_state = stateLitLenCodesCount;
goto start;
case stateLitLenCodesCount:
if OF_UNLIKELY (!tryReadBits(self, &bits, 9))
return bytesWritten;
if OF_UNLIKELY (bits > 510)
@throw [OFInvalidFormatException exception];
if OF_UNLIKELY (bits == 0) {
OFHuffmanTreeFree(_codeLenTree);
_codeLenTree = NULL;
_state = stateLitLenTreeSingle;
goto start;
}
_codesCount = bits;
|
|
|
|
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
if OF_UNLIKELY (bits == 7) {
_currentIsExtendedLength = true;
continue;
} else
_codesReceived++;
}
_codeLenTree = _OFHuffmanTreeNew(_codesLengths, _codesCount);
OFFreeMemory(_codesLengths);
_codesLengths = NULL;
_state = stateLitLenCodesCount;
goto start;
case stateCodeLenTreeSingle:
if OF_UNLIKELY (!tryReadBits(self, &bits, 5))
return bytesWritten;
_codeLenTree = _OFHuffmanTreeNewSingle(bits);
_state = stateLitLenCodesCount;
goto start;
case stateLitLenCodesCount:
if OF_UNLIKELY (!tryReadBits(self, &bits, 9))
return bytesWritten;
if OF_UNLIKELY (bits > 510)
@throw [OFInvalidFormatException exception];
if OF_UNLIKELY (bits == 0) {
_OFHuffmanTreeFree(_codeLenTree);
_codeLenTree = NULL;
_state = stateLitLenTreeSingle;
goto start;
}
_codesCount = bits;
|
︙ | | | ︙ | |
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
for (uint_fast16_t j = 0; j < skipCount; j++)
_codesLengths[_codesReceived++] = 0;
_skip = false;
continue;
}
if (!OFHuffmanTreeWalk(self, tryReadBits, &_treeIter,
&value))
return bytesWritten;
_treeIter = _codeLenTree;
if (value < 3) {
_codesLengths[_codesReceived] = value;
_skip = true;
} else
_codesLengths[_codesReceived++] = value - 2;
}
_litLenTree = OFHuffmanTreeNew(_codesLengths, _codesCount);
OFFreeMemory(_codesLengths);
_codesLengths = NULL;
OFHuffmanTreeFree(_codeLenTree);
_codeLenTree = NULL;
_state = stateDistCodesCount;
goto start;
case stateLitLenTreeSingle:
if OF_UNLIKELY (!tryReadBits(self, &bits, 9))
return bytesWritten;
_litLenTree = OFHuffmanTreeNewSingle(bits);
_state = stateDistCodesCount;
goto start;
case stateDistCodesCount:
if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits))
return bytesWritten;
|
|
|
|
|
|
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
for (uint_fast16_t j = 0; j < skipCount; j++)
_codesLengths[_codesReceived++] = 0;
_skip = false;
continue;
}
if (!_OFHuffmanTreeWalk(self, tryReadBits, &_treeIter,
&value))
return bytesWritten;
_treeIter = _codeLenTree;
if (value < 3) {
_codesLengths[_codesReceived] = value;
_skip = true;
} else
_codesLengths[_codesReceived++] = value - 2;
}
_litLenTree = _OFHuffmanTreeNew(_codesLengths, _codesCount);
OFFreeMemory(_codesLengths);
_codesLengths = NULL;
_OFHuffmanTreeFree(_codeLenTree);
_codeLenTree = NULL;
_state = stateDistCodesCount;
goto start;
case stateLitLenTreeSingle:
if OF_UNLIKELY (!tryReadBits(self, &bits, 9))
return bytesWritten;
_litLenTree = _OFHuffmanTreeNewSingle(bits);
_state = stateDistCodesCount;
goto start;
case stateDistCodesCount:
if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits))
return bytesWritten;
|
︙ | | | ︙ | |
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
if OF_UNLIKELY (bits == 7) {
_currentIsExtendedLength = true;
continue;
} else
_codesReceived++;
}
_distTree = OFHuffmanTreeNew(_codesLengths, _codesCount);
OFFreeMemory(_codesLengths);
_codesLengths = NULL;
_treeIter = _litLenTree;
_state = stateBlockLitLen;
goto start;
case stateDistTreeSingle:
if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits))
return bytesWritten;
_distTree = OFHuffmanTreeNewSingle(bits);
_treeIter = _litLenTree;
_state = stateBlockLitLen;
goto start;
case stateBlockLitLen:
if OF_UNLIKELY (_symbolsLeft == 0) {
OFHuffmanTreeFree(_litLenTree);
OFHuffmanTreeFree(_distTree);
_litLenTree = _distTree = NULL;
_state = stateBlockHeader;
/*
* We must return here, as there is no indication
* whether this was the last block. Whoever called this
|
|
|
|
|
|
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
if OF_UNLIKELY (bits == 7) {
_currentIsExtendedLength = true;
continue;
} else
_codesReceived++;
}
_distTree = _OFHuffmanTreeNew(_codesLengths, _codesCount);
OFFreeMemory(_codesLengths);
_codesLengths = NULL;
_treeIter = _litLenTree;
_state = stateBlockLitLen;
goto start;
case stateDistTreeSingle:
if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits))
return bytesWritten;
_distTree = _OFHuffmanTreeNewSingle(bits);
_treeIter = _litLenTree;
_state = stateBlockLitLen;
goto start;
case stateBlockLitLen:
if OF_UNLIKELY (_symbolsLeft == 0) {
_OFHuffmanTreeFree(_litLenTree);
_OFHuffmanTreeFree(_distTree);
_litLenTree = _distTree = NULL;
_state = stateBlockHeader;
/*
* We must return here, as there is no indication
* whether this was the last block. Whoever called this
|
︙ | | | ︙ | |
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
return bytesWritten;
}
if OF_UNLIKELY (length == 0)
return bytesWritten;
if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits,
&_treeIter, &value))
return bytesWritten;
if OF_LIKELY (value < 256) {
buffer[bytesWritten++] = value;
length--;
|
|
|
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
|
return bytesWritten;
}
if OF_UNLIKELY (length == 0)
return bytesWritten;
if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits,
&_treeIter, &value))
return bytesWritten;
if OF_LIKELY (value < 256) {
buffer[bytesWritten++] = value;
length--;
|
︙ | | | ︙ | |
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
_length = value - 253;
_treeIter = _distTree;
_state = stateBlockDistLength;
}
goto start;
case stateBlockDistLength:
if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits,
&_treeIter, &value))
return bytesWritten;
_distance = value;
_state = (value < 2
? stateBlockLenDistPair : stateBlockDistLengthExtra);
|
|
|
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
_length = value - 253;
_treeIter = _distTree;
_state = stateBlockDistLength;
}
goto start;
case stateBlockDistLength:
if OF_UNLIKELY (!_OFHuffmanTreeWalk(self, tryReadBits,
&_treeIter, &value))
return bytesWritten;
_distance = value;
_state = (value < 2
? stateBlockLenDistPair : stateBlockDistLengthExtra);
|
︙ | | | ︙ | |