From 07786773c5a98ee63bf3ee5ed55303973ebb2d41 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 24 Dec 2016 20:37:35 +0300 Subject: [PATCH] Added gzip file members support. --- Sources/GzipArchive.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/GzipArchive.swift b/Sources/GzipArchive.swift index 44fba959..cd273c95 100644 --- a/Sources/GzipArchive.swift +++ b/Sources/GzipArchive.swift @@ -169,17 +169,19 @@ public class GzipArchive: Archive { /// Object with input data which supports convenient work with bit shifts. var pointerData = DataWithPointer(data: data, bitOrder: .reversed) - _ = try self.serviceInfo(pointerData) + var out: [UInt8] = [] - // TODO: Add 'members' support. + while !pointerData.isAtTheEnd { + _ = try self.serviceInfo(pointerData) - let out = try Deflate.decompress(&pointerData) + out.append(contentsOf: try Deflate.decompress(&pointerData)) - let crc32 = pointerData.intFromAlignedBytes(count: 4) - guard CheckSums.crc32(out) == crc32 else { throw GzipError.WrongCRC } + let crc32 = pointerData.intFromAlignedBytes(count: 4) + guard CheckSums.crc32(out) == crc32 else { throw GzipError.WrongCRC } - let isize = pointerData.intFromAlignedBytes(count: 4) - guard out.count % (1 << 32) == isize else { throw GzipError.WrongISize } + let isize = pointerData.intFromAlignedBytes(count: 4) + guard out.count % (1 << 32) == isize else { throw GzipError.WrongISize } + } return Data(bytes: out) }