ObjFW
OFInflateStream.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFStream.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 #define OF_INFLATE_STREAM_BUFFER_SIZE 4096
22 
30 {
31 #ifdef OF_INFLATE_STREAM_M
32 @public
33 #endif
34  OFStream *_stream;
35  uint8_t _buffer[OF_INFLATE_STREAM_BUFFER_SIZE];
36  uint16_t _bufferIndex, _bufferLength;
37  uint8_t _byte;
38  uint8_t _bitIndex, _savedBitsLength;
39  uint16_t _savedBits;
40  uint8_t *_Nullable _slidingWindow;
41  uint16_t _slidingWindowIndex, _slidingWindowMask;
42  int _state;
43  union {
44  struct {
45  uint8_t position;
46  uint8_t length[4];
47  } uncompressedHeader;
48  struct {
49  uint16_t position, length;
50  } uncompressed;
51  struct {
52  struct huffman_tree *_Nullable litLenTree;
53  struct huffman_tree *_Nullable distTree;
54  struct huffman_tree *_Nullable codeLenTree;
55  struct huffman_tree *_Nullable treeIter;
56  uint8_t *_Nullable lengths;
57  uint16_t receivedCount;
58  uint8_t value, litLenCodesCount, distCodesCount;
59  uint8_t codeLenCodesCount;
60  } huffmanTree;
61  struct {
62  struct huffman_tree *_Nullable litLenTree;
63  struct huffman_tree *_Nullable distTree;
64  struct huffman_tree *_Nullable treeIter;
65  int state;
66  uint16_t value, length, distance, extraBits;
67  } huffman;
68  } _context;
69  bool _inLastBlock, _atEndOfStream;
70 }
71 
79 + (instancetype)streamWithStream: (OFStream *)stream;
80 
81 - init OF_UNAVAILABLE;
82 
91 - initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
92 @end
93 
94 OF_ASSUME_NONNULL_END
A class that handles Deflate decompression transparently for an underlying stream.
Definition: OFInflateStream.h:29
id init()
Initializes an already allocated object.
Definition: OFObject.m:488
A base class for different types of streams.
Definition: OFStream.h:88