Index: src/OFLHAArchive.h ================================================================== --- src/OFLHAArchive.h +++ src/OFLHAArchive.h @@ -37,10 +37,12 @@ OFLHAArchiveEntry *_Nullable _currentEntry; #ifdef OF_LHA_ARCHIVE_M @public #endif OFStream *_Nullable _lastReturnedStream; +@protected + bool _hasWritten; } /** * @brief The encoding to use for the archive. Defaults to ISO 8859-1. */ Index: src/OFLHAArchive.m ================================================================== --- src/OFLHAArchive.m +++ src/OFLHAArchive.m @@ -123,11 +123,17 @@ if ((_mode == modeWrite || _mode == modeAppend) && ![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) - [(OFSeekableStream *)_stream seekToOffset: 0 + /* + * Only works with properly zero-terminated files that + * have no trailing garbage. Unfortunately there is no + * good way to check for this other than reading the + * entire archive. + */ + [(OFSeekableStream *)_stream seekToOffset: -1 whence: OFSeekEnd]; _encoding = OFStringEncodingISO8859_1; } @catch (id e) { [self release]; @@ -276,10 +282,11 @@ _lastReturnedStream = [[[OFLHAArchiveFileWriteStream alloc] of_initWithArchive: self stream: (OFSeekableStream *)_stream entry: entry encoding: _encoding] autorelease]; + _hasWritten = true; return _lastReturnedStream; } - (void)close @@ -288,12 +295,17 @@ @throw [OFNotOpenException exceptionWithObject: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { - /* Might have already been closed by the user - that's fine. */ + /* Might have already been closed by the user - that's fine */ } + + /* LHA archives should be terminated with a header of size 0 */ + if (_hasWritten) + [_stream writeBuffer: "" length: 1]; + _lastReturnedStream = nil; [_stream release]; _stream = nil; }