From 097aaf7b24c239f031eaafcba188bbadf7c49ca0 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 25 Jul 2017 00:35:57 +0300 Subject: [PATCH] Complete 7zip structures implementations Though some questions, problems and opportunities for improvements are remaining. --- Sources/7zCodec.swift | 13 +++--- Sources/7zCoderInfo.swift | 47 +++++++++++++------ Sources/7zFileInfo.swift | 86 +++-------------------------------- Sources/7zFolder.swift | 4 +- Sources/7zPackInfo.swift | 32 +++++++++---- Sources/7zSubstreamInfo.swift | 49 +++++++++++--------- 6 files changed, 98 insertions(+), 133 deletions(-) diff --git a/Sources/7zCodec.swift b/Sources/7zCodec.swift index d986a773..eacc4416 100644 --- a/Sources/7zCodec.swift +++ b/Sources/7zCodec.swift @@ -13,8 +13,8 @@ struct SevenZipCodec { let id: [UInt8] - var numInStreams: Int? - var numOutStreams: Int? + let numInStreams: Int + let numOutStreams: Int var propertiesSize: Int? var properties: [UInt8]? @@ -29,10 +29,11 @@ struct SevenZipCodec { id = pointerData.bytes(count: idSize) - if isComplex { - numInStreams = try pointerData.multiByteDecode(SevenZipError.multiByteIntegerError).multiByteInteger - numOutStreams = try pointerData.multiByteDecode(SevenZipError.multiByteIntegerError).multiByteInteger - } + // TODO: Introduce typealias for SevenZipError.multiByteIntegerError. + numInStreams = isComplex ? try pointerData + .multiByteDecode(SevenZipError.multiByteIntegerError).multiByteInteger : 1 + numOutStreams = isComplex ? try pointerData + .multiByteDecode(SevenZipError.multiByteIntegerError).multiByteInteger : 1 if attributesExist { propertiesSize = try pointerData.multiByteDecode(SevenZipError.multiByteIntegerError).multiByteInteger diff --git a/Sources/7zCoderInfo.swift b/Sources/7zCoderInfo.swift index 8ffbba5d..fccfbd1d 100644 --- a/Sources/7zCoderInfo.swift +++ b/Sources/7zCoderInfo.swift @@ -10,10 +10,10 @@ struct SevenZipCoderInfo { let numFolders: Int let external: UInt8 - var folders: [SevenZipFolder]? + var folders = [SevenZipFolder]() var dataStreamIndex: Int? - let unpackSizes: [Int] + var digests = [UInt32?]() init(_ pointerData: DataWithPointer) throws { guard pointerData.byte() == 0x0B @@ -22,9 +22,8 @@ struct SevenZipCoderInfo { external = pointerData.byte() switch external { case 0: - folders = [] for _ in 0..