ObjFW
OFInflate64Stream.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFStream.h"
17 #import "OFKernelEventObserver.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 #define OFInflate64StreamBufferSize 4096
22 
32 OF_SUBCLASSING_RESTRICTED
34 {
35  OFStream *_stream;
36  unsigned char _buffer[OFInflate64StreamBufferSize];
37  uint16_t _bufferIndex, _bufferLength;
38  uint8_t _byte;
39  uint8_t _bitIndex, _savedBitsLength;
40  uint16_t _savedBits;
41  unsigned char *_Nullable _slidingWindow;
42  uint16_t _slidingWindowIndex, _slidingWindowMask;
43  int _state;
44  union {
45  struct {
46  uint8_t position;
47  uint8_t length[4];
48  } uncompressedHeader;
49  struct {
50  uint16_t position, length;
51  } uncompressed;
52  struct {
53  struct _OFHuffmanTree *_Nullable litLenTree;
54  struct _OFHuffmanTree *_Nullable distTree;
55  struct _OFHuffmanTree *_Nullable codeLenTree;
56  struct _OFHuffmanTree *_Nullable treeIter;
57  uint8_t *_Nullable lengths;
58  uint16_t receivedCount;
59  uint8_t value, litLenCodesCount, distCodesCount;
60  uint8_t codeLenCodesCount;
61  } huffmanTree;
62  struct {
63  struct _OFHuffmanTree *_Nullable litLenTree;
64  struct _OFHuffmanTree *_Nullable distTree;
65  struct _OFHuffmanTree *_Nullable treeIter;
66  int state;
67  uint16_t value, length, distance, extraBits;
68  } huffman;
69  } _context;
70  bool _inLastBlock, _atEndOfStream;
71 }
72 
79 @property (retain, nonatomic) OFStream *underlyingStream;
80 
88 + (instancetype)streamWithStream: (OFStream *)stream;
89 
90 - (instancetype)init OF_UNAVAILABLE;
91 
100 - (instancetype)initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
101 @end
102 
103 OF_ASSUME_NONNULL_END
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
A base class for different types of streams.
Definition: OFStream.h:186
A class that handles Deflate decompression transparently for an underlying stream.
Definition: OFInflate64Stream.h:33