ObjFW
OFInflate64Stream.h
1 /*
2  * Copyright (c) 2008-2021 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 OF_INFLATE64_STREAM_BUFFER_SIZE 4096
22 
32 OF_SUBCLASSING_RESTRICTED
34 {
35  OFStream *_stream;
36  unsigned char _buffer[OF_INFLATE64_STREAM_BUFFER_SIZE];
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 of_huffman_tree *_Nullable litLenTree;
54  struct of_huffman_tree *_Nullable distTree;
55  struct of_huffman_tree *_Nullable codeLenTree;
56  struct of_huffman_tree *_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 of_huffman_tree *_Nullable litLenTree;
64  struct of_huffman_tree *_Nullable distTree;
65  struct of_huffman_tree *_Nullable treeIter;
66  int state;
67  uint16_t value, length, distance, extraBits;
68  } huffman;
69  } _context;
70  bool _inLastBlock, _atEndOfStream;
71 }
72 
80 + (instancetype)streamWithStream: (OFStream *)stream;
81 
82 - (instancetype)init OF_UNAVAILABLE;
83 
92 - (instancetype)initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
93 @end
94 
95 OF_ASSUME_NONNULL_END
A class that handles Deflate decompression transparently for an underlying stream.
Definition: OFInflate64Stream.h:35
A base class for different types of streams.
Definition: OFStream.h:191
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition: OFKernelEventObserver.h:85