From 9e1e969541dca3a771658a332a06d459eee2cbbe Mon Sep 17 00:00:00 2001 From: awxkee Date: Sun, 23 Oct 2022 16:19:00 +0400 Subject: [PATCH] fix streaming bug --- Sources/bzip2.swift/BZip2.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Sources/bzip2.swift/BZip2.swift b/Sources/bzip2.swift/BZip2.swift index 5d5e8bc..0ca2a55 100644 --- a/Sources/bzip2.swift/BZip2.swift +++ b/Sources/bzip2.swift/BZip2.swift @@ -111,12 +111,7 @@ public class BZip2 { readData = src.read(srcBuffer.assumingMemoryBound(to: UInt8.self), maxLength: Int(BZipCompressionBufferSize)) compressedSize += Int64(readData) if readData == -1 { - free(srcBuffer) - free(dstBuffer) - src.close() - dst.close() - BZ2_bzDecompressEnd(&stream) - throw BZip2InvalidInputStreamError() + break } stream.avail_in = UInt32(readData) stream.next_in = srcBuffer.bindMemory(to: CChar.self, capacity: Int(BZipCompressionBufferSize)) @@ -187,12 +182,7 @@ public class BZip2 { readData = src.read(srcBuffer, maxLength: Int(BZipCompressionBufferSize)) compressedSize += Int64(readData) if readData == -1 { - free(srcBuffer) - free(dstBuffer) - src.close() - dst.close() - BZ2_bzCompressEnd(&stream) - throw BZip2InvalidInputStreamError() + break } stream.next_in = srcBuffer.assumingMemoryBound(to: CChar.self) stream.avail_in = UInt32(readData)