Skip to content

Commit

Permalink
fix streaming bug
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Oct 23, 2022
1 parent e0a3b71 commit 9e1e969
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions Sources/bzip2.swift/BZip2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9e1e969

Please sign in to comment.