From 3503bcbb89f87e5a3f7270ea2c26795eb0f03e62 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 30 Jul 2017 15:52:28 +0300 Subject: [PATCH] Support unavailable data in SevenZipEntry (when no substreamInfo is found) --- Sources/7zEntry.swift | 16 +++++++++++----- Sources/7zError.swift | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Sources/7zEntry.swift b/Sources/7zEntry.swift index 6436b749..1ea89ba4 100644 --- a/Sources/7zEntry.swift +++ b/Sources/7zEntry.swift @@ -23,17 +23,23 @@ public class SevenZipEntry: ContainerEntry { public var entryAttributes: [FileAttributeKey: Any] - private let dataObject: Data + public let dataIsAvailable: Bool - init(_ entryInfo: SevenZipEntryInfo, _ data: Data) { - // TODO: Make data decoding here? + private let dataObject: Data? + + init(_ entryInfo: SevenZipEntryInfo, _ data: Data?) { self.info = entryInfo self.dataObject = data + self.dataIsAvailable = data != nil self.entryAttributes = [:] } - public func data() -> Data { - return dataObject + public func data() throws -> Data { + if let data = dataObject { + return data + } else { + throw SevenZipError.dataIsUnavailable + } } } diff --git a/Sources/7zError.swift b/Sources/7zError.swift index 129b2480..70bd936e 100644 --- a/Sources/7zError.swift +++ b/Sources/7zError.swift @@ -38,4 +38,5 @@ public enum SevenZipError: Error { case noStreamFound case noPackInfoFound case streamOverread + case dataIsUnavailable }