86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
stream->_savedBitsLength = 0;
*bits = ret;
return true;
}
@implementation OFLHAArchive_LHStream
- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
distanceBits: (uint8_t)distanceBits
dictionaryBits: (uint8_t)dictionaryBits
{
self = [super init];
@try {
_stream = [stream retain];
|
|
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
stream->_savedBitsLength = 0;
*bits = ret;
return true;
}
@implementation OFLHAArchive_LHStream
- (instancetype)of_initWithStream: (OFStream *)stream
distanceBits: (uint8_t)distanceBits
dictionaryBits: (uint8_t)dictionaryBits
{
self = [super init];
@try {
_stream = [stream retain];
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
unsigned char *buffer = buffer_;
uint16_t bits, value;
size_t bytesWritten = 0;
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if ([_stream isAtEndOfStream] && _bufferLength - _bufferIndex == 0 &&
_state == STATE_BLOCK_HEADER)
return 0;
start:
switch ((enum state)_state) {
case STATE_BLOCK_HEADER:
if OF_UNLIKELY (!tryReadBits(self, &bits, 16))
|
|
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
unsigned char *buffer = buffer_;
uint16_t bits, value;
size_t bytesWritten = 0;
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
if (_stream.atEndOfStream && _bufferLength - _bufferIndex == 0 &&
_state == STATE_BLOCK_HEADER)
return 0;
start:
switch ((enum state)_state) {
case STATE_BLOCK_HEADER:
if OF_UNLIKELY (!tryReadBits(self, &bits, 16))
|
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
}
- (bool)lowlevelIsAtEndOfStream
{
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
return ([_stream isAtEndOfStream] &&
_bufferLength - _bufferIndex == 0 && _state == STATE_BLOCK_HEADER);
}
- (int)fileDescriptorForReading
{
return [_stream fileDescriptorForReading];
}
- (bool)hasDataInReadBuffer
{
return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer] ||
_bufferLength - _bufferIndex > 0);
}
- (void)close
{
/* Give back our buffer to the stream, in case it's shared */
[_stream unreadFromBuffer: _buffer + _bufferIndex
|
|
>
|
|
|
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
|
}
- (bool)lowlevelIsAtEndOfStream
{
if (_stream == nil)
@throw [OFNotOpenException exceptionWithObject: self];
return (_stream.atEndOfStream &&
_bufferLength - _bufferIndex == 0 && _state == STATE_BLOCK_HEADER);
}
- (int)fileDescriptorForReading
{
return ((id <OFReadyForReadingObserving>)_stream)
.fileDescriptorForReading;
}
- (bool)hasDataInReadBuffer
{
return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
_bufferLength - _bufferIndex > 0);
}
- (void)close
{
/* Give back our buffer to the stream, in case it's shared */
[_stream unreadFromBuffer: _buffer + _bufferIndex
|