ObjFW  Check-in [7aef43d648]

Overview
Comment:Add OFDeflate64Stream.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7aef43d6484755ae1e6b349b16b52fb07371422cfb56bbedf6fcac1198c3919d
User & Date: js on 2013-11-06 20:29:17
Other Links: manifest | tags
Context
2013-11-06
20:58
OFZIPArchive: Do not sort -[entries]. check-in: be628bbb84 user: js tags: trunk
20:29
Add OFDeflate64Stream. check-in: 7aef43d648 user: js tags: trunk
11:36
OFZIPArchive: Add support for ZIP64. check-in: 7d11e6e4e6 user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [523bffa7ab] to [0527e94856].

266
267
268
269
270
271
272


273
274
275
276
277
278
279
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281







+
+







		4B5C112F17E9AB3E003C917F /* forwarding.S in Sources */ = {isa = PBXBuildFile; fileRef = 4B5C112C17E9AAED003C917F /* forwarding.S */; };
		4B5CF8F914940BD2007AA324 /* OFString+JSONValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B5CF8F614940BD2007AA324 /* OFString+JSONValue.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B5CF8FA14940BD2007AA324 /* OFString+JSONValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B5CF8F714940BD2007AA324 /* OFString+JSONValue.m */; };
		4B64D6EF1425381E007BDFB1 /* OFStreamObserver_poll.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */; };
		4B64D6F01425381E007BDFB1 /* OFStreamObserver_poll.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B64D6EC1425381E007BDFB1 /* OFStreamObserver_poll.m */; };
		4B64D6F11425381E007BDFB1 /* OFStreamObserver_select.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B64D6ED1425381E007BDFB1 /* OFStreamObserver_select.h */; };
		4B64D6F21425381E007BDFB1 /* OFStreamObserver_select.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B64D6EE1425381E007BDFB1 /* OFStreamObserver_select.m */; };
		4B66B636182ADC45000A69E3 /* OFDeflate64Stream.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B66B634182ADC45000A69E3 /* OFDeflate64Stream.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B66B637182ADC45000A69E3 /* OFDeflate64Stream.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B66B635182ADC45000A69E3 /* OFDeflate64Stream.m */; };
		4B6743F1163C384A00EB1E59 /* OFLockFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743EB163C384A00EB1E59 /* OFLockFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B6743F2163C384A00EB1E59 /* OFLockFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743EC163C384A00EB1E59 /* OFLockFailedException.m */; };
		4B6743F3163C384A00EB1E59 /* OFStillLockedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743ED163C384A00EB1E59 /* OFStillLockedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B6743F4163C384A00EB1E59 /* OFStillLockedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743EE163C384A00EB1E59 /* OFStillLockedException.m */; };
		4B6743F5163C384A00EB1E59 /* OFUnlockFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743EF163C384A00EB1E59 /* OFUnlockFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B6743F6163C384A00EB1E59 /* OFUnlockFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B6743F0163C384A00EB1E59 /* OFUnlockFailedException.m */; };
		4B674400163C395900EB1E59 /* OFCondition.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B6743F7163C395900EB1E59 /* OFCondition.h */; settings = {ATTRIBUTES = (Public, ); }; };
634
635
636
637
638
639
640


641
642
643
644
645
646
647
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651







+
+







		4B5C112E17E9AB0C003C917F /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; name = Makefile; path = src/forwarding/Makefile; sourceTree = "<group>"; };
		4B5CF8F614940BD2007AA324 /* OFString+JSONValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFString+JSONValue.h"; path = "src/OFString+JSONValue.h"; sourceTree = "<group>"; };
		4B5CF8F714940BD2007AA324 /* OFString+JSONValue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "OFString+JSONValue.m"; path = "src/OFString+JSONValue.m"; sourceTree = "<group>"; };
		4B64D6EB1425381E007BDFB1 /* OFStreamObserver_poll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_poll.h; path = src/OFStreamObserver_poll.h; sourceTree = "<group>"; };
		4B64D6EC1425381E007BDFB1 /* OFStreamObserver_poll.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_poll.m; path = src/OFStreamObserver_poll.m; sourceTree = "<group>"; };
		4B64D6ED1425381E007BDFB1 /* OFStreamObserver_select.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStreamObserver_select.h; path = src/OFStreamObserver_select.h; sourceTree = "<group>"; };
		4B64D6EE1425381E007BDFB1 /* OFStreamObserver_select.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStreamObserver_select.m; path = src/OFStreamObserver_select.m; sourceTree = "<group>"; };
		4B66B634182ADC45000A69E3 /* OFDeflate64Stream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFDeflate64Stream.h; path = src/OFDeflate64Stream.h; sourceTree = "<group>"; };
		4B66B635182ADC45000A69E3 /* OFDeflate64Stream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFDeflate64Stream.m; path = src/OFDeflate64Stream.m; sourceTree = "<group>"; };
		4B6743EB163C384A00EB1E59 /* OFLockFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFLockFailedException.h; path = src/exceptions/OFLockFailedException.h; sourceTree = "<group>"; };
		4B6743EC163C384A00EB1E59 /* OFLockFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFLockFailedException.m; path = src/exceptions/OFLockFailedException.m; sourceTree = "<group>"; };
		4B6743ED163C384A00EB1E59 /* OFStillLockedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFStillLockedException.h; path = src/exceptions/OFStillLockedException.h; sourceTree = "<group>"; };
		4B6743EE163C384A00EB1E59 /* OFStillLockedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFStillLockedException.m; path = src/exceptions/OFStillLockedException.m; sourceTree = "<group>"; };
		4B6743EF163C384A00EB1E59 /* OFUnlockFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFUnlockFailedException.h; path = src/exceptions/OFUnlockFailedException.h; sourceTree = "<group>"; };
		4B6743F0163C384A00EB1E59 /* OFUnlockFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFUnlockFailedException.m; path = src/exceptions/OFUnlockFailedException.m; sourceTree = "<group>"; };
		4B6743F7163C395900EB1E59 /* OFCondition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFCondition.h; path = src/OFCondition.h; sourceTree = "<group>"; };
1158
1159
1160
1161
1162
1163
1164


1165
1166
1167
1168
1169
1170
1171
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177







+
+







				4BE17ADA12FD746D002CEB0B /* OFDataArray+Hashing.m */,
				4B879A89177231F000EBCEA4 /* OFDataArray+MessagePackValue.h */,
				4B879A8A177231F000EBCEA4 /* OFDataArray+MessagePackValue.m */,
				4BE5F0D912DF4225005C7A0C /* OFDate.h */,
				4BE5F0DA12DF4225005C7A0C /* OFDate.m */,
				4B86E7C917F8B98200ACA680 /* OFDeflateStream.h */,
				4B86E7CA17F8B98200ACA680 /* OFDeflateStream.m */,
				4B66B634182ADC45000A69E3 /* OFDeflate64Stream.h */,
				4B66B635182ADC45000A69E3 /* OFDeflate64Stream.m */,
				4B6799621099E7C50041064A /* OFDictionary.h */,
				4B6799631099E7C50041064A /* OFDictionary.m */,
				4B2B3E75140D430500EC2F7C /* OFDictionary_hashtable.h */,
				4B2B3E76140D430500EC2F7C /* OFDictionary_hashtable.m */,
				4B0108C910EB8C9300631877 /* OFEnumerator.h */,
				4B0108CA10EB8C9300631877 /* OFEnumerator.m */,
				4B6799661099E7C50041064A /* OFFile.h */,
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466
1467
1468
1469
1470
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477







+







				4B45355313DCFE1E0037AB4D /* OFCountedSet.h in Headers */,
				4B3D23C21337FC8300DD29B8 /* OFDataArray.h in Headers */,
				4B3D23C31337FC8300DD29B8 /* OFDataArray+Hashing.h in Headers */,
				4B879A8C177231F000EBCEA4 /* OFDataArray+MessagePackValue.h in Headers */,
				4B3D23C41337FC8300DD29B8 /* OFDate.h in Headers */,
				4B3D23C51337FCB000DD29B8 /* OFDictionary.h in Headers */,
				4B86E7CB17F8B98200ACA680 /* OFDeflateStream.h in Headers */,
				4B66B636182ADC45000A69E3 /* OFDeflate64Stream.h in Headers */,
				4B3D23C61337FCB000DD29B8 /* OFEnumerator.h in Headers */,
				4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */,
				4B3D23C81337FCB000DD29B8 /* OFFile.h in Headers */,
				4B3D23C91337FCB000DD29B8 /* OFHash.h in Headers */,
				4BB4B54416775FF4002A2DCE /* OFHTTPClient.h in Headers */,
				4B3D23CA1337FCB000DD29B8 /* OFHTTPRequest.h in Headers */,
				4B7161AD17A6FC7600B74970 /* OFHTTPResponse.h in Headers */,
1820
1821
1822
1823
1824
1825
1826

1827
1828
1829
1830
1831
1832
1833
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841







+







				4B45355413DCFE1E0037AB4D /* OFCountedSet.m in Sources */,
				4BA85BCB140ECCE800E91D51 /* OFCountedSet_hashtable.m in Sources */,
				4B3D23901337FC0D00DD29B8 /* OFDataArray.m in Sources */,
				4B3D23911337FC0D00DD29B8 /* OFDataArray+Hashing.m in Sources */,
				4B879A8D177231F000EBCEA4 /* OFDataArray+MessagePackValue.m in Sources */,
				4B3D23921337FC0D00DD29B8 /* OFDate.m in Sources */,
				4B86E7CC17F8B98200ACA680 /* OFDeflateStream.m in Sources */,
				4B66B637182ADC45000A69E3 /* OFDeflate64Stream.m in Sources */,
				4B3D23931337FC0D00DD29B8 /* OFDictionary.m in Sources */,
				4B2B3E80140D430500EC2F7C /* OFDictionary_hashtable.m in Sources */,
				4B3D23941337FC0D00DD29B8 /* OFEnumerator.m in Sources */,
				4B3D23961337FC0D00DD29B8 /* OFFile.m in Sources */,
				4BB4B54516775FF4002A2DCE /* OFHTTPClient.m in Sources */,
				4B3D23981337FC0D00DD29B8 /* OFHTTPRequest.m in Sources */,
				4B7161AE17A6FC7600B74970 /* OFHTTPResponse.m in Sources */,

Modified src/Makefile from [55e8b6da7e] to [d4440caf30].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+







       OFConstantString.m		\
       OFCountedSet.m			\
       OFDataArray.m			\
       OFDataArray+Hashing.m		\
       OFDataArray+MessagePackValue.m	\
       OFDate.m				\
       OFDeflateStream.m		\
       OFDeflate64Stream.m		\
       OFDictionary.m			\
       OFEnumerator.m			\
       OFFile.m				\
       OFIntrospection.m		\
       OFList.m				\
       OFMapTable.m			\
       OFMD5Hash.m			\

Added src/OFDeflate64Stream.h version [05007fad3e].

























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFDeflateStream.h"

/*!
 * @brief A class for a stream that handles Deflate64 compression or
 *	  decompression transparently for an underlying stream.
 */
@interface OFDeflate64Stream: OFDeflateStream
@end

Added src/OFDeflate64Stream.m version [4cf3df9c5c].
























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFDeflate64Stream.h"

static const uint_fast8_t numDistanceCodes = 32;
static const uint8_t lengthCodes[29] = {
	/* indices are -257, values -3 */
	0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
	64, 80, 96, 112, 128, 160, 192, 224, 0
};
static const uint8_t lengthExtraBits[29] = {
	0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
	5, 5, 5, 5, 16
};
static const uint16_t distanceCodes[32] = {
	1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385,
	513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577,
	32769, 49153
};
static const uint8_t distanceExtraBits[32] = {
	0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10,
	10, 11, 11, 12, 12, 13, 13, 14, 14
};

@implementation OFDeflate64Stream
- initWithStream: (OFStream*)stream
{
	self = [super initWithStream: stream];

	_slidingWindowMask = 0xFFFF;
	_codes.numDistanceCodes = numDistanceCodes;
	_codes.lengthCodes = lengthCodes;
	_codes.lengthExtraBits = lengthExtraBits;
	_codes.distanceCodes = distanceCodes;
	_codes.distanceExtraBits = distanceExtraBits;

	return self;
}
@end

Modified src/OFDeflateStream.h from [2f21e16d6f] to [ee0596ab39].

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38









39
40
41
42
43
44
45
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52







-
+














-
-
+
+
+
+
+
+
+
+
+







 */

#import "OFStream.h"

#define OF_DEFLATE_STREAM_BUFFER_SIZE 4096

/*!
 * @brief A class for a stream that handles deflate compression or decompression
 * @brief A class for a stream that handles Deflate compression or decompression
 *	  transparently for an underlying stream.
 */
@interface OFDeflateStream: OFStream
{
#ifdef OF_DEFLATE_STREAM_M
@public
#endif
	OFStream *_stream;
	uint8_t _buffer[OF_DEFLATE_STREAM_BUFFER_SIZE];
	uint_fast16_t _bufferIndex, _bufferLength;
	uint8_t _byte;
	uint_fast8_t _bitIndex, _savedBitsLength;
	uint_fast16_t _savedBits;
@protected
	char *_slidingWindow;
	uint_fast16_t _slidingWindowIndex;
	uint8_t *_slidingWindow;
	uint_fast16_t _slidingWindowIndex, _slidingWindowMask;
	struct {
		uint_fast8_t numDistanceCodes;
		const uint8_t *lengthCodes;
		const uint8_t *lengthExtraBits;
		const uint16_t *distanceCodes;
		const uint8_t *distanceExtraBits;
	} _codes;
	enum {
		OF_DEFLATE_STREAM_BLOCK_HEADER,
		OF_DEFLATE_STREAM_UNCOMPRESSED_BLOCK_HEADER,
		OF_DEFLATE_STREAM_UNCOMPRESSED_BLOCK,
		OF_DEFLATE_STREAM_HUFFMAN_TREE,
		OF_DEFLATE_STREAM_HUFFMAN_BLOCK
	} _state;

Modified src/OFDeflateStream.m from [b46dd90f88] to [4e0c067ee9].

53
54
55
56
57
58
59

60
61
62
63
64
65
66
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67







+







#define MAX_BITS    15

struct huffman_tree {
	struct huffman_tree *leafs[2];
	uint16_t value;
};

static const uint_fast8_t numDistanceCodes = 30;
static const uint8_t lengthCodes[29] = {
	/* indices are -257, values -3 */
	0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
	64, 80, 96, 112, 128, 160, 192, 224, 255
};
static const uint8_t lengthExtraBits[29] = {
	0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4,
272
273
274
275
276
277
278






279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311







+
+
+
+
+
+


















-
+








- initWithStream: (OFStream*)stream
{
	self = [super init];

	_stream = [stream retain];
	_bitIndex = 8;	/* 0-7 address the bit, 8 means fetch next byte */
	_slidingWindowMask = 0x7FFF;
	_codes.numDistanceCodes = numDistanceCodes;
	_codes.lengthCodes = lengthCodes;
	_codes.lengthExtraBits = lengthExtraBits;
	_codes.distanceCodes = distanceCodes;
	_codes.distanceExtraBits = distanceExtraBits;

	return self;
}

- (void)dealloc
{
	[_stream release];

	[super dealloc];
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer_
			  length: (size_t)length
{
	uint8_t *buffer = buffer_;
	uint_fast16_t bits;
	uint16_t value;
	size_t i, tmp, bytesWritten = 0;
	char *slidingWindow;
	uint8_t *slidingWindow;
	uint_fast16_t slidingWindowIndex;

	if (_atEndOfStream)
		@throw [OFReadFailedException exceptionWithStream: self
						  requestedLength: length];

start:
384
385
386
387
388
389
390
391


392
393

394
395
396
397
398
399
400
401


402
403
404
405
406
407
408
391
392
393
394
395
396
397

398
399
400

401
402
403
404
405
406
407
408

409
410
411
412
413
414
415
416
417







-
+
+

-
+







-
+
+







		tmp = (length < CTX.length - CTX.position
		    ? length : CTX.length - CTX.position);

		tmp = [_stream readIntoBuffer: buffer + bytesWritten
				       length: tmp];

		if OF_UNLIKELY (_slidingWindow == NULL) {
			_slidingWindow = [self allocMemoryWithSize: 0x8000];
			_slidingWindow =
			    [self allocMemoryWithSize: _slidingWindowMask + 1];
			/* Avoid leaking data */
			memset(_slidingWindow, 0, 0x8000);
			memset(_slidingWindow, 0, _slidingWindowMask + 1);
		}

		slidingWindow = _slidingWindow;
		slidingWindowIndex = _slidingWindowIndex;
		for (i = 0; i < tmp; i++) {
			slidingWindow[slidingWindowIndex] =
			    buffer[bytesWritten + i];
			slidingWindowIndex = (slidingWindowIndex + 1) & 0x7FFF;
			slidingWindowIndex = (slidingWindowIndex + 1) &
			    _slidingWindowMask;
		}
		_slidingWindowIndex = slidingWindowIndex;

		length -= tmp;
		bytesWritten += tmp;

		CTX.position += tmp;
570
571
572
573
574
575
576
577


578
579


580
581
582
583
584


585
586
587
588
589
590
591
579
580
581
582
583
584
585

586
587
588

589
590
591
592
593
594

595
596
597
598
599
600
601
602
603







-
+
+

-
+
+




-
+
+







					return bytesWritten;

				buffer[bytesWritten++] = CTX.value;
				length--;

				if (_slidingWindow == NULL) {
					_slidingWindow = [self
					    allocMemoryWithSize: 0x8000];
					    allocMemoryWithSize:
					    _slidingWindowMask + 1];
					/* Avoid leaking data */
					memset(_slidingWindow, 0, 0x8000);
					memset(_slidingWindow, 0,
					    _slidingWindowMask + 1);
				}

				_slidingWindow[_slidingWindowIndex] = CTX.value;
				_slidingWindowIndex =
				    (_slidingWindowIndex + 1) & 0x7FFF;
				    (_slidingWindowIndex + 1) &
				    _slidingWindowMask;

				CTX.state = AWAIT_CODE;
				CTX.treeIter = CTX.litLenTree;
			}

			if OF_UNLIKELY (CTX.state == AWAIT_LENGTH_EXTRA_BITS) {
				if OF_UNLIKELY (!tryReadBits(self, &bits,
600
601
602
603
604
605
606
607


608
609
610
611
612


613
614
615
616
617
618
619
612
613
614
615
616
617
618

619
620
621
622
623


624
625
626
627
628
629
630
631
632







-
+
+



-
-
+
+








			/* Distance of length distance pair */
			if (CTX.state == AWAIT_DISTANCE) {
				if OF_UNLIKELY (!walkTree(self, &CTX.treeIter,
				    &value))
					return bytesWritten;

				if OF_UNLIKELY (value > 29)
				if OF_UNLIKELY (value >=
				    _codes.numDistanceCodes)
					@throw [OFInvalidFormatException
					    exception];

				CTX.distance = distanceCodes[value];
				extraBits = distanceExtraBits[value];
				CTX.distance = _codes.distanceCodes[value];
				extraBits = _codes.distanceExtraBits[value];

				if (extraBits > 0) {
					if OF_UNLIKELY (!tryReadBits(self,
					    &bits, extraBits)) {
						CTX.state =
						    AWAIT_DISTANCE_EXTRA_BITS;
						CTX.extraBits = extraBits;
647
648
649
650
651
652
653
654

655
656
657
658
659
660
661
662
663


664
665
666
667
668
669
670
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675

676
677
678
679
680
681
682
683
684







-
+








-
+
+








					if OF_UNLIKELY (length == 0) {
						CTX.length -= j;
						return bytesWritten;
					}

					index = (_slidingWindowIndex -
					    CTX.distance) & 0x7FFF;
					    CTX.distance) & _slidingWindowMask;
					value = _slidingWindow[index];

					buffer[bytesWritten++] = value;
					length--;

					_slidingWindow[_slidingWindowIndex] =
					    value;
					_slidingWindowIndex =
					    (_slidingWindowIndex + 1) & 0x7FFF;
					    (_slidingWindowIndex + 1) &
					    _slidingWindowMask;
				}

				CTX.state = AWAIT_CODE;
				CTX.treeIter = CTX.litLenTree;
			}

			if OF_UNLIKELY (!walkTree(self, &CTX.treeIter, &value))
690
691
692
693
694
695
696
697


698
699


700
701
702
703
704


705
706
707
708
709
710
711
712
713
714
715
716


717
718
719
720
721
722
723
704
705
706
707
708
709
710

711
712
713

714
715
716
717
718
719

720
721
722
723
724
725
726
727
728
729
730
731


732
733
734
735
736
737
738
739
740







-
+
+

-
+
+




-
+
+










-
-
+
+







				}

				buffer[bytesWritten++] = value;
				length--;

				if (_slidingWindow == NULL) {
					_slidingWindow = [self
					    allocMemoryWithSize: 0x8000];
					    allocMemoryWithSize:
					    _slidingWindowMask + 1];
					/* Avoid leaking data */
					memset(_slidingWindow, 0, 0x8000);
					memset(_slidingWindow, 0,
					    _slidingWindowMask + 1);
				}

				_slidingWindow[_slidingWindowIndex] = value;
				_slidingWindowIndex =
				    (_slidingWindowIndex + 1) & 0x7FFF;
				    (_slidingWindowIndex + 1) &
				    _slidingWindowMask;

				CTX.treeIter = CTX.litLenTree;
				continue;
			}

			if OF_UNLIKELY (value > 285)
				@throw [OFInvalidFormatException exception];

			/* Length of length distance pair */
			lengthCodeIndex = value - 257;
			CTX.length = lengthCodes[lengthCodeIndex] + 3;
			extraBits = lengthExtraBits[lengthCodeIndex];
			CTX.length = _codes.lengthCodes[lengthCodeIndex] + 3;
			extraBits = _codes.lengthExtraBits[lengthCodeIndex];

			if (extraBits > 0) {
				if OF_UNLIKELY (!tryReadBits(self, &bits,
				    extraBits)) {
					CTX.extraBits = extraBits;
					CTX.state = AWAIT_LENGTH_EXTRA_BITS;
					return bytesWritten;

Modified src/OFZIPArchive.m from [180a7ad71a] to [cf62e89d89].

20
21
22
23
24
25
26

27
28
29
30
31
32
33
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+







#import "OFZIPArchiveEntry.h"
#import "OFZIPArchiveEntry+Private.h"
#import "OFDataArray.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFFile.h"
#import "OFDeflateStream.h"
#import "OFDeflate64Stream.h"

#import "OFChecksumFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenFileFailedException.h"
#import "OFOutOfRangeException.h"
498
499
500
501
502
503
504




505
506
507
508
509
510
511
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516







+
+
+
+







		case 0: /* No compression */
			_stream = [_file retain];
			break;
		case 8: /* Deflate */
			_stream = [[OFDeflateStream alloc]
			    initWithStream: _file];
			break;
		case 9: /* Deflate64 */
			_stream = [[OFDeflate64Stream alloc]
			    initWithStream: _file];
			break;
		default:
			@throw [OFNotImplementedException
			    exceptionWithSelector: _cmd
					   object: self];
		}

		_localFileHeader = [localFileHeader retain];