Add 7zEntry class and its first iteration

This commit is contained in:
Timofey Solomko
2017-07-29 00:02:17 +03:00
parent 8c558c5a77
commit 363fe78ead
3 changed files with 61 additions and 11 deletions
+10
View File
@@ -283,6 +283,10 @@
06E234831E06A6C200F18798 /* CheckSums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E234811E06A6C200F18798 /* CheckSums.swift */; };
06E234841E06A6C200F18798 /* CheckSums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E234811E06A6C200F18798 /* CheckSums.swift */; };
06E234851E06A6C200F18798 /* CheckSums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E234811E06A6C200F18798 /* CheckSums.swift */; };
06F276DF1F2BAB4A00E67335 /* 7zEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F276DE1F2BAB4900E67335 /* 7zEntry.swift */; };
06F276E01F2BAB4A00E67335 /* 7zEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F276DE1F2BAB4900E67335 /* 7zEntry.swift */; };
06F276E11F2BAB4A00E67335 /* 7zEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F276DE1F2BAB4900E67335 /* 7zEntry.swift */; };
06F276E21F2BAB4A00E67335 /* 7zEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F276DE1F2BAB4900E67335 /* 7zEntry.swift */; };
06FED40D1DD7717E0013DFB2 /* BZip2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FED40B1DD7717E0013DFB2 /* BZip2.swift */; };
06FED40E1DD7717E0013DFB2 /* BZip2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FED40B1DD7717E0013DFB2 /* BZip2.swift */; };
06FED40F1DD7717E0013DFB2 /* BZip2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FED40B1DD7717E0013DFB2 /* BZip2.swift */; };
@@ -430,6 +434,7 @@
06E2346B1E068E9600F18798 /* XZArchive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XZArchive.swift; sourceTree = "<group>"; };
06E2347F1E069ABD00F18798 /* XzTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XzTests.swift; sourceTree = "<group>"; };
06E234811E06A6C200F18798 /* CheckSums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CheckSums.swift; path = Sources/CheckSums.swift; sourceTree = SOURCE_ROOT; };
06F276DE1F2BAB4900E67335 /* 7zEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = 7zEntry.swift; sourceTree = "<group>"; };
06FED40B1DD7717E0013DFB2 /* BZip2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BZip2.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -551,6 +556,7 @@
06A9605F1F1E7DE20078E6D1 /* 7zFileInfo.swift */,
064F72281F1E638A00017297 /* 7zError.swift */,
065D0ADB1F2B9D9100CE2DA8 /* 7zEntryInfo.swift */,
06F276DE1F2BAB4900E67335 /* 7zEntry.swift */,
);
name = "7-Zip";
sourceTree = "<group>";
@@ -1127,6 +1133,7 @@
06CDFCA41F111D6C00292758 /* BZip2Error.swift in Sources */,
06393DF61F1A7F8E00A647A0 /* ZipCommon.swift in Sources */,
065D0ADD1F2B9D9100CE2DA8 /* 7zEntryInfo.swift in Sources */,
06F276E01F2BAB4A00E67335 /* 7zEntry.swift in Sources */,
06E2346D1E068E9600F18798 /* XZArchive.swift in Sources */,
06CDFC9F1F111D2600292758 /* DeflateCompression.swift in Sources */,
061C06431F0E8AD500832F0C /* ZipEntry.swift in Sources */,
@@ -1184,6 +1191,7 @@
06CDFCA51F111D6C00292758 /* BZip2Error.swift in Sources */,
06393DF71F1A7F8E00A647A0 /* ZipCommon.swift in Sources */,
065D0ADE1F2B9D9100CE2DA8 /* 7zEntryInfo.swift in Sources */,
06F276E11F2BAB4A00E67335 /* 7zEntry.swift in Sources */,
06E2346E1E068E9600F18798 /* XZArchive.swift in Sources */,
06CDFCA01F111D2600292758 /* DeflateCompression.swift in Sources */,
061C06441F0E8AD500832F0C /* ZipEntry.swift in Sources */,
@@ -1241,6 +1249,7 @@
06CDFCA61F111D6C00292758 /* BZip2Error.swift in Sources */,
06393DF81F1A7F8E00A647A0 /* ZipCommon.swift in Sources */,
065D0ADF1F2B9D9100CE2DA8 /* 7zEntryInfo.swift in Sources */,
06F276E21F2BAB4A00E67335 /* 7zEntry.swift in Sources */,
06E2346F1E068E9600F18798 /* XZArchive.swift in Sources */,
06CDFCA11F111D2600292758 /* DeflateCompression.swift in Sources */,
061C06451F0E8AD500832F0C /* ZipEntry.swift in Sources */,
@@ -1298,6 +1307,7 @@
06CDFCA31F111D6C00292758 /* BZip2Error.swift in Sources */,
06393DF51F1A7F8E00A647A0 /* ZipCommon.swift in Sources */,
065D0ADC1F2B9D9100CE2DA8 /* 7zEntryInfo.swift in Sources */,
06F276DF1F2BAB4A00E67335 /* 7zEntry.swift in Sources */,
06E2346C1E068E9600F18798 /* XZArchive.swift in Sources */,
06CDFC9E1F111D2600292758 /* DeflateCompression.swift in Sources */,
061C06421F0E8AD500832F0C /* ZipEntry.swift in Sources */,
+12 -11
View File
@@ -17,17 +17,18 @@ public class SevenZipContainer: Container {
var entryInfos = [SevenZipEntryInfo]()
let header = try readHeader(data)
if let files = header.fileInfo?.files, let substreamInfo = header.mainStreams?.substreamInfo {
var nonEmptyFileIndex = 0
for file in files {
if file.isEmptyStream {
entryInfos.append(SevenZipEntryInfo(file))
} else {
entryInfos.append(SevenZipEntryInfo(file,
substreamInfo.unpackSizes[nonEmptyFileIndex],
substreamInfo.digests[nonEmptyFileIndex]))
nonEmptyFileIndex += 1
}
guard let files = header.fileInfo?.files, let substreamInfo = header.mainStreams?.substreamInfo
else { return [] }
var nonEmptyFileIndex = 0
for file in files {
if file.isEmptyStream {
entryInfos.append(SevenZipEntryInfo(file))
} else {
entryInfos.append(SevenZipEntryInfo(file,
substreamInfo.unpackSizes[nonEmptyFileIndex],
substreamInfo.digests[nonEmptyFileIndex]))
nonEmptyFileIndex += 1
}
}
+39
View File
@@ -0,0 +1,39 @@
// Copyright (c) 2017 Timofey Solomko
// Licensed under MIT License
//
// See LICENSE for license information
import Foundation
public class SevenZipEntry: ContainerEntry {
public let info: SevenZipEntryInfo
public var name: String {
return info.name ?? ""
}
public var size: Int {
return info.size ?? 0
}
public var isDirectory: Bool {
return info.isDirectory
}
public var entryAttributes: [FileAttributeKey: Any]
private let dataObject: Data
init(_ bitReader: BitReader, _ entryInfo: SevenZipEntryInfo) {
self.info = entryInfo
self.dataObject = Data()
self.entryAttributes = [:]
}
public func data() -> Data {
return dataObject
}
}