ObjFW
Loading...
Searching...
No Matches
OFInflateStream.h
1/*
2 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#import "OFStream.h"
21#import "OFKernelEventObserver.h"
22
23OF_ASSUME_NONNULL_BEGIN
24
25#define OFInflateStreamBufferSize 4096
26
36OF_SUBCLASSING_RESTRICTED
38{
39 OFStream *_stream;
40 unsigned char _buffer[OFInflateStreamBufferSize];
41 uint16_t _bufferIndex, _bufferLength;
42 uint8_t _byte;
43 uint8_t _bitIndex, _savedBitsLength;
44 uint16_t _savedBits;
45 unsigned char *_Nullable _slidingWindow;
46 uint16_t _slidingWindowIndex, _slidingWindowMask;
47 int _state;
48 union {
49 struct {
50 uint8_t position;
51 uint8_t length[4];
52 } uncompressedHeader;
53 struct {
54 uint16_t position, length;
55 } uncompressed;
56 struct {
57 struct _OFHuffmanTree *_Nullable litLenTree;
58 struct _OFHuffmanTree *_Nullable distTree;
59 struct _OFHuffmanTree *_Nullable codeLenTree;
60 struct _OFHuffmanTree *_Nullable treeIter;
61 uint8_t *_Nullable lengths;
62 uint16_t receivedCount;
63 uint8_t value, litLenCodesCount, distCodesCount;
64 uint8_t codeLenCodesCount;
65 } huffmanTree;
66 struct {
67 struct _OFHuffmanTree *_Nullable litLenTree;
68 struct _OFHuffmanTree *_Nullable distTree;
69 struct _OFHuffmanTree *_Nullable treeIter;
70 int state;
71 uint16_t value, length, distance, extraBits;
72 } huffman;
73 } _context;
74 bool _inLastBlock, _atEndOfStream;
75}
76
83@property (retain, nonatomic) OFStream *underlyingStream;
92+ (instancetype)streamWithStream: (OFStream *)stream;
93
94- (instancetype)init OF_UNAVAILABLE;
95
104- (instancetype)initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
105@end
106
107OF_ASSUME_NONNULL_END
A class that handles Deflate decompression transparently for an underlying stream.
Definition OFInflateStream.h:39
A base class for different types of streams.
Definition OFStream.h:192
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition OFKernelEventObserver.h:88