[BZip2] Add multiDecompress public function

This should help with inputs consisting of multiple BZip2 archives concatenated together which were brought up in #59.
This commit is contained in:
Timofey Solomko
2026-05-12 16:06:19 +08:00
parent 2620ed67cf
commit 75cc406d47
+10
View File
@@ -25,6 +25,16 @@ public class BZip2: DecompressionAlgorithm {
return try decompress(bitReader)
}
public static func multiDecompress(data: Data) throws -> [Data] {
let reader = MsbBitReader(data: data)
var result = [Data]()
while !reader.isFinished {
result.append(try decompress(reader))
reader.align()
}
return result
}
static func decompress(_ bitReader: MsbBitReader) throws -> Data {
// Valid BZip2 "archive" must contain at least 14 bytes of data: magic number (2 bytes), method (1 byte), and
// block size (1 byte).