ObjFW  Diff

Differences From Artifact [56fa949e3a]:

To Artifact [6f9fadd6e2]:


25
26
27
28
29
30
31

32
33

34
35
36
37
38
39
40
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+


+







#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#import "OFStream.h"
#import "OFSeekableStream.h"
#import "OFString.h"

#import "crc16.h"
#import "huffman_tree.h"

#import "OFChecksumFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#import "OFTruncatedDataException.h"

#define LHSTREAM_BUFFER_SIZE 4096
67
68
69
70
71
72
73

74
75
76
77
78
79
80
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83







+







		   dictionaryBits: (uint8_t)dictionaryBits;
@end

@interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving>
{
	OF_KINDOF(OFStream *) _stream;
	uint32_t _toRead;
	uint16_t _expectedCRC16, _CRC16;
	bool _atEndOfStream;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFLHAArchiveEntry *)entry;
- (void)of_skip;
@end
724
725
726
727
728
729
730


731
732
733
734
735
736
737
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742







+
+








		if ([method isEqual: @"-lh0-"] || [method isEqual: @"-lhd-"] ||
		    [method isEqual: @"-lz4-"] || [method isEqual: @"-lh5-"] ||
		    [method isEqual: @"-lh6-"] || [method isEqual: @"-lh6-"])
			_toRead = [entry uncompressedSize];
		else
			_toRead = [entry compressedSize];

		_expectedCRC16 = [entry CRC16];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
757
758
759
760
761
762
763

764
765

766




767
768
769
770
771
772
773
762
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
778
779
780
781
782
783







+

-
+

+
+
+
+







	if (length > _toRead)
		length = _toRead;

	ret = [_stream readIntoBuffer: buffer
			       length: length];

	_toRead -= ret;
	_CRC16 = of_crc16(_CRC16, buffer, ret);

	if (_toRead == 0)
	if (_toRead == 0) {
		_atEndOfStream = true;

		if (_CRC16 != _expectedCRC16)
			@throw [OFChecksumFailedException exception];
	}

	return ret;
}

- (bool)lowlevelIsAtEndOfStream
{
	if (_stream == nil)