@@ -294,11 +294,12 @@ return self; } - (void)dealloc { - [self close]; + if (_stream != nil) + [self close]; [_entry release]; [super dealloc]; } @@ -352,10 +353,13 @@ .fileDescriptorForReading; } - (void)close { + if (_stream == nil) + @throw [OFNotOpenException exceptionWithObject: self]; + [self of_skip]; [_stream release]; _stream = nil; @@ -427,11 +431,12 @@ return self; } - (void)dealloc { - [self close]; + if (_stream != nil) + [self close]; [_entry release]; [super dealloc]; } @@ -474,17 +479,19 @@ .fileDescriptorForWriting; } - (void)close { + uint64_t remainder; + if (_stream == nil) - return; - - uint64_t remainder = 512 - _entry.size % 512; + @throw [OFNotOpenException exceptionWithObject: self]; if (_toWrite > 0) @throw [OFTruncatedDataException exception]; + + remainder = 512 - _entry.size % 512; if (remainder != 512) { bool wasWriteBuffered = _stream.writeBuffered; [_stream setWriteBuffered: true];