From 75cc406d475758612689290b89e58064d1005bb0 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 12 May 2026 16:06:19 +0800 Subject: [PATCH] [BZip2] Add multiDecompress public function This should help with inputs consisting of multiple BZip2 archives concatenated together which were brought up in #59. --- Sources/BZip2/BZip2.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/BZip2/BZip2.swift b/Sources/BZip2/BZip2.swift index a8b7e556..7114a2ad 100644 --- a/Sources/BZip2/BZip2.swift +++ b/Sources/BZip2/BZip2.swift @@ -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).