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 *_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 *litLenTree, *distTree;
53  struct huffman_tree *codeLenTree, *treeIter;
54  uint8_t *lengths;
55  uint16_t receivedCount;
56  uint8_t value, litLenCodesCount, distCodesCount;
57  uint8_t codeLenCodesCount;
58  } huffmanTree;
59  struct {
60  struct huffman_tree *litLenTree, *distTree;
61  struct huffman_tree *treeIter;
62  int state;
63  uint16_t value, length, distance, extraBits;
64  } huffman;
65  } _context;
66  bool _inLastBlock, _atEndOfStream;
67 }
68 
76 + (instancetype)streamWithStream: (OFStream *)stream;
77 
78 - init OF_UNAVAILABLE;
79 
88 - initWithStream: (OFStream *)stream OF_DESIGNATED_INITIALIZER;
89 @end
90 
91 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