ObjFW
 
Loading...
Searching...
No Matches
OFDeflateStream.h
1/*
2 * Copyright (c) 2008-2026 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
37{
38 OFStream *_stream;
39 unsigned char *_Nullable _slidingWindow;
40 uint16_t _slidingWindowIndex;
41 struct OFInflateContext {
42 unsigned char buffer[OFInflateStreamBufferSize];
43 uint16_t bufferIndex, bufferLength;
44 uint8_t byte;
45 uint8_t bitIndex, savedBitsLength;
46 uint16_t savedBits;
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 } ctx;
74 bool inLastBlock;
75 } *_Nullable _inflateCtx;
76 bool _atEndOfStream;
77 OF_RESERVE_IVARS(OFDeflateStream, 4)
78}
79
86@property (retain, nonatomic) OFStream *underlyingStream;
97+ (instancetype)streamWithStream: (OFStream *)stream
98 OF_DEPRECATED(ObjFW, 1, 5, "Use +[streamWithStream:mode:] instead");
99
109+ (instancetype)streamWithStream: (OFStream *)stream mode: (OFString *)mode;
110
111- (instancetype)init OF_UNAVAILABLE;
112
123- (instancetype)initWithStream: (OFStream *)stream
124 OF_DEPRECATED(ObjFW, 1, 5, "Use -[initWithStream:mode:] instead!");
125
136- (instancetype)initWithStream: (OFStream *)stream
137 mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;
138@end
139
140OF_ASSUME_NONNULL_END
A class that handles Deflate decompression transparently for an underlying stream.
Definition OFDeflateStream.h:38
instancetype init()
Initializes an already allocated object.
Definition OFObject.m:671
A base class for different types of streams.
Definition OFStream.h:280
A class for handling strings.
Definition OFString.h:143
This protocol is implemented by classes which can be observed for readiness for reading by OFKernelEv...
Definition OFKernelEventObserver.h:84