ObjFW
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 
23 OF_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;
72  uint32_t length;
73  uint16_t distance, extraBits;
74  } huffman;
75  } ctx;
76  bool inLastBlock;
77  } *_Nullable _inflateCtx;
78  bool _atEndOfStream;
79  OF_RESERVE_IVARS(OFDeflateStream, 3)
80 }
81 
88 @property (retain, nonatomic) OFStream *underlyingStream;
89 
99 + (instancetype)streamWithStream: (OFStream *)stream
100  OF_DEPRECATED(ObjFW, 1, 5, "Use +[streamWithStream:mode:] instead");
101 
111 + (instancetype)streamWithStream: (OFStream *)stream mode: (OFString *)mode;
112 
113 - (instancetype)init OF_UNAVAILABLE;
114 
125 - (instancetype)initWithStream: (OFStream *)stream
126  OF_DEPRECATED(ObjFW, 1, 5, "Use -[initWithStream:mode:] instead!");
127 
138 - (instancetype)initWithStream: (OFStream *)stream
139  mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;
140 @end
141 
142 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:278
A class for handling strings.
Definition: OFString.h:142
A class that handles Deflate decompression transparently for an underlying stream.
Definition: OFDeflateStream.h:36