@@ -31,12 +31,12 @@ #endif #import "OFDataArray.h" #import "OFInitializationFailedException.h" #import "OFInvalidFormatException.h" +#import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" -#import "OFReadFailedException.h" #define BUFFER_SIZE OF_INFLATE_STREAM_BUFFER_SIZE #define MAX_BITS 15 @@ -304,11 +304,11 @@ return self; } - (void)dealloc { - [_stream release]; + [self close]; if (_decompression != NULL && _decompression->state == HUFFMAN_TREE) if (_decompression->context.huffmanTree.codeLenTree != NULL) releaseTree( _decompression->context.huffmanTree.codeLenTree); @@ -349,18 +349,20 @@ uint16_t value; size_t bytesWritten = 0; uint8_t *slidingWindow; uint16_t slidingWindowIndex; + if (_stream == nil) + @throw [OFNotOpenException exceptionWithObject: self]; + if (ivars == NULL) { [self of_initDecompression]; ivars = _decompression; } if (ivars->atEndOfStream) - @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + return 0; start: switch ((enum state)ivars->state) { case BLOCK_HEADER: if OF_UNLIKELY (ivars->inLastBlock) { @@ -821,12 +823,12 @@ } #ifndef DEFLATE64 - (bool)lowlevelIsAtEndOfStream { - if (_decompression == NULL) - return false; + if (_stream == nil) + @throw [OFNotOpenException exceptionWithObject: self]; return _decompression->atEndOfStream; } - (int)fileDescriptorForReading @@ -837,6 +839,14 @@ - (bool)hasDataInReadBuffer { return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer]); } #endif + +- (void)close +{ + [_stream release]; + _stream = nil; + + [super close]; +} @end