From 895643b69e5779043dacc519339e9f0acc2005b4 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 18 Mar 2018 00:57:27 +0300 Subject: [PATCH 01/53] [7-Zip] Reduce code nesting in container --- Sources/7-Zip/7zContainer.swift | 184 ++++++++++++++++---------------- 1 file changed, 91 insertions(+), 93 deletions(-) diff --git a/Sources/7-Zip/7zContainer.swift b/Sources/7-Zip/7zContainer.swift index d84b2309..7d53cae9 100644 --- a/Sources/7-Zip/7zContainer.swift +++ b/Sources/7-Zip/7zContainer.swift @@ -55,110 +55,108 @@ public class SevenZipContainer: Container { let byteReader = ByteReader(data: data) for file in files { - let info: SevenZipEntryInfo - let data: Data? + if file.isEmptyStream { + let info = file.isEmptyFile && !file.isAntiFile ? SevenZipEntryInfo(file, 0) : SevenZipEntryInfo(file) + let data = file.isEmptyFile && !file.isAntiFile ? Data() : nil + entries.append(SevenZipEntry(info, data)) + continue + } - if !file.isEmptyStream { - // Without `SevenZipStreamInfo` and `SevenZipPackInfo` we cannot find file data in container. - guard let streamInfo = header.mainStreams, - let packInfo = streamInfo.packInfo - else { throw SevenZipError.internalStructureError } + // Without `SevenZipStreamInfo` and `SevenZipPackInfo` we cannot find file data in container. + guard let streamInfo = header.mainStreams, + let packInfo = streamInfo.packInfo + else { throw SevenZipError.internalStructureError } - // SubstreamInfo is required to get files' data, and without it we can only return files' info. - guard let substreamInfo = streamInfo.substreamInfo else { - entries.append(SevenZipEntry(SevenZipEntryInfo(file), nil)) - continue + // SubstreamInfo is required to get files' data, and without it we can only return files' info. + guard let substreamInfo = streamInfo.substreamInfo else { + entries.append(SevenZipEntry(SevenZipEntryInfo(file), nil)) + continue + } + + // Check if there is enough folders. + guard folderIndex < streamInfo.coderInfo.numFolders + else { throw SevenZipError.internalStructureError } + + /// Folder which contains current file. + let folder = streamInfo.coderInfo.folders[folderIndex] + + // There may be several streams in a single folder, so we have to iterate over them, if necessary. + // If we switched folders or completed reading of a stream we need to move to the next stream. + if folderFileIndex == 0 || unpackedStreamData.isFinished { + streamIndex += 1 + + // First, we move to the stream's offset. We don't have any guarantees that streams will be + // enountered in the same order, as they are placed in the container. Thus, we have to start moving + // to stream's offset from the beginning. + // TODO: Is this correct or the order of streams is guaranteed? + byteReader.offset = signatureHeaderSize + packInfo.packPosition // Pack offset. + if streamIndex != 0 { + for i in 0..= folder.numUnpackSubstreams { // If we read all files in folder... - // Check folder's unpacked size as well as its CRC32 (if it is available). - guard folderUnpackSize == folder.unpackSize() - else { throw SevenZipError.wrongSize } - if let storedFolderCRC = folder.crc { - guard folderCRC == storedFolderCRC - else { throw SevenZipError.wrongCRC } - } - // Reset folder's unpack size and CRC32. - folderCRC = CheckSums.crc32(Data()) - folderUnpackSize = 0 - // Reset file index for the next folder. - folderFileIndex = 0 - // Move to the next folder. - folderIndex += 1 - } - } else { - info = file.isEmptyFile && !file.isAntiFile ? SevenZipEntryInfo(file, 0) : SevenZipEntryInfo(file) - data = file.isEmptyFile && !file.isAntiFile ? Data() : nil + // One stream can contain data for several files, so we need to decode the stream first, then split + // it into files. + unpackedStreamData = ByteReader(data: try folder.unpack(data: streamData)) } + // `SevenZipSubstreamInfo` object must contain information about file's size and may also contain + // information about file's CRC32. + + // File's unpacked size is required to proceed. + guard nonEmptyFileIndex < substreamInfo.unpackSizes.count + else { throw SevenZipError.internalStructureError } + let fileSize = substreamInfo.unpackSizes[nonEmptyFileIndex] + + // Check, if we aren't about to read too much from a stream. + guard unpackedStreamData.offset + fileSize <= unpackedStreamData.data.endIndex + else { throw SevenZipError.internalStructureError } + let fileData = Data(bytes: unpackedStreamData.bytes(count: fileSize)) + + let calculatedFileCRC = CheckSums.crc32(fileData) + if nonEmptyFileIndex < substreamInfo.digests.count { + guard calculatedFileCRC == substreamInfo.digests[nonEmptyFileIndex] + else { throw SevenZipError.wrongCRC } + } + + let info = SevenZipEntryInfo(file, fileSize, calculatedFileCRC) + let data = fileData entries.append(SevenZipEntry(info, data)) + + // Update folder's crc and unpack size. + folderUnpackSize += fileSize + folderCRC = CheckSums.crc32(fileData, prevValue: folderCRC) + + folderFileIndex += 1 + nonEmptyFileIndex += 1 + + if folderFileIndex >= folder.numUnpackSubstreams { // If we read all files in folder... + // Check folder's unpacked size as well as its CRC32 (if it is available). + guard folderUnpackSize == folder.unpackSize() + else { throw SevenZipError.wrongSize } + if let storedFolderCRC = folder.crc { + guard folderCRC == storedFolderCRC + else { throw SevenZipError.wrongCRC } + } + // Reset folder's unpack size and CRC32. + folderCRC = CheckSums.crc32(Data()) + folderUnpackSize = 0 + // Reset file index for the next folder. + folderFileIndex = 0 + // Move to the next folder. + folderIndex += 1 + } } return entries From b123fff4280fae182b5ff76c8099587d11c51890 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 18 Mar 2018 00:58:40 +0300 Subject: [PATCH 02/53] [7-Zip] Replace struct-ends ifs with guards --- Sources/7-Zip/7zCoderInfo.swift | 5 ++--- Sources/7-Zip/7zHeader.swift | 5 ++--- Sources/7-Zip/7zPackInfo.swift | 5 ++--- Sources/7-Zip/7zStreamInfo.swift | 5 ++--- Sources/7-Zip/7zSubstreamInfo.swift | 5 ++--- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Sources/7-Zip/7zCoderInfo.swift b/Sources/7-Zip/7zCoderInfo.swift index 2f2610cf..a2a1da85 100644 --- a/Sources/7-Zip/7zCoderInfo.swift +++ b/Sources/7-Zip/7zCoderInfo.swift @@ -54,8 +54,7 @@ class SevenZipCoderInfo { type = bitReader.byte() } - if type != 0x00 { - throw SevenZipError.internalStructureError - } + guard type == 0x00 + else { throw SevenZipError.internalStructureError } } } diff --git a/Sources/7-Zip/7zHeader.swift b/Sources/7-Zip/7zHeader.swift index 26aed32b..15dbeb57 100644 --- a/Sources/7-Zip/7zHeader.swift +++ b/Sources/7-Zip/7zHeader.swift @@ -35,9 +35,8 @@ class SevenZipHeader { type = bitReader.byte() } - if type != 0x00 { - throw SevenZipError.internalStructureError - } + guard type == 0x00 + else { throw SevenZipError.internalStructureError } } convenience init(_ bitReader: MsbBitReader, using streamInfo: SevenZipStreamInfo) throws { diff --git a/Sources/7-Zip/7zPackInfo.swift b/Sources/7-Zip/7zPackInfo.swift index 18020e96..90bd4500 100644 --- a/Sources/7-Zip/7zPackInfo.swift +++ b/Sources/7-Zip/7zPackInfo.swift @@ -41,9 +41,8 @@ class SevenZipPackInfo { type = bitReader.byte() } - if type != 0x00 { - throw SevenZipError.internalStructureError - } + guard type == 0x00 + else { throw SevenZipError.internalStructureError } } } diff --git a/Sources/7-Zip/7zStreamInfo.swift b/Sources/7-Zip/7zStreamInfo.swift index d656dde9..0680854e 100644 --- a/Sources/7-Zip/7zStreamInfo.swift +++ b/Sources/7-Zip/7zStreamInfo.swift @@ -32,9 +32,8 @@ class SevenZipStreamInfo { type = bitReader.byte() } - if type != 0x00 { - throw SevenZipError.internalStructureError - } + guard type == 0x00 + else { throw SevenZipError.internalStructureError } } } diff --git a/Sources/7-Zip/7zSubstreamInfo.swift b/Sources/7-Zip/7zSubstreamInfo.swift index 3eae6ea8..b90bb031 100644 --- a/Sources/7-Zip/7zSubstreamInfo.swift +++ b/Sources/7-Zip/7zSubstreamInfo.swift @@ -80,9 +80,8 @@ class SevenZipSubstreamInfo { type = bitReader.byte() } - if type != 0x00 { - throw SevenZipError.internalStructureError - } + guard type == 0x00 + else { throw SevenZipError.internalStructureError } } } From 4959ec5fe07a41c1001c37345e186be56a2741cd Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 18 Mar 2018 01:03:14 +0300 Subject: [PATCH 03/53] [TAR] Add compressionMethod property to TarEntryInfo Obviously, it is awlays equal to .copy because TAR format doesn't support any compression. --- Sources/TAR/TarEntryInfo.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index 6e876051..30d1a51e 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -41,6 +41,9 @@ public struct TarEntryInfo: ContainerEntryInfo { // MARK: TAR specific + /// Entry's compression method. Always `.copy` for entries of TAR containers. + public let compressionMethod = CompressionMethod.copy + /// ID of entry's owner. public let ownerID: Int? From 311fe5ae802219620d00a7267d0a3bc15550d80a Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 18 Mar 2018 15:47:43 +0300 Subject: [PATCH 04/53] [7-Zip] Add property to SevenZipFolder orderedCompressionMethods It lazily returns compression methods in the order used by folder. --- Sources/7-Zip/7zFolder.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/7-Zip/7zFolder.swift b/Sources/7-Zip/7zFolder.swift index 2de3d743..79ff0f04 100644 --- a/Sources/7-Zip/7zFolder.swift +++ b/Sources/7-Zip/7zFolder.swift @@ -39,6 +39,10 @@ class SevenZipFolder { // This property is stored in SubstreamInfo. var numUnpackSubstreams = 1 + lazy var orderedCompressionMethods: [CompressionMethod] = { + return self.orderedCoders().map { $0.compressionMethod } + }() + init(_ bitReader: MsbBitReader) throws { numCoders = bitReader.szMbd() for _ in 0.. Date: Sun, 25 Mar 2018 20:02:46 +0300 Subject: [PATCH 05/53] Revert "Disable STRIP_INSTALLED_PRODUCT xcode project setting" Carthage released an update which fixes the problem with unintended stripping of debugging symbols, thus, we no longer need to modify project settings to workaround this problem. --- SWCompression.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 84aed303..c198c336 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1156,7 +1156,6 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; - STRIP_INSTALLED_PRODUCT = NO; SUPPORTED_PLATFORMS = "macosx watchsimulator iphonesimulator appletvsimulator watchos appletvos iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -1197,7 +1196,6 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; SDKROOT = macosx; - STRIP_INSTALLED_PRODUCT = NO; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TVOS_DEPLOYMENT_TARGET = 9.0; From 019bbf06292f72a7b021ee12ce11a5e4a6ceef60 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 25 Mar 2018 23:33:57 +0300 Subject: [PATCH 06/53] [7-Zip] Move conversion from UInt64 to Date from entry to file info --- Sources/7-Zip/7zEntryInfo.swift | 6 +++--- Sources/7-Zip/7zFileInfo.swift | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/7-Zip/7zEntryInfo.swift b/Sources/7-Zip/7zEntryInfo.swift index 36574eb9..b89947f2 100644 --- a/Sources/7-Zip/7zEntryInfo.swift +++ b/Sources/7-Zip/7zEntryInfo.swift @@ -57,9 +57,9 @@ public struct SevenZipEntryInfo: ContainerEntryInfo { self.name = file.name - self.accessTime = Date(file.aTime) - self.creationTime = Date(file.cTime) - self.modificationTime = Date(file.mTime) + self.accessTime = file.aTime + self.creationTime = file.cTime + self.modificationTime = file.mTime self.winAttributes = file.winAttributes diff --git a/Sources/7-Zip/7zFileInfo.swift b/Sources/7-Zip/7zFileInfo.swift index b4f02976..b4c1d375 100644 --- a/Sources/7-Zip/7zFileInfo.swift +++ b/Sources/7-Zip/7zFileInfo.swift @@ -13,9 +13,9 @@ class SevenZipFileInfo { var isEmptyFile = false var isAntiFile = false var name: String = "" - var cTime: UInt64? - var mTime: UInt64? - var aTime: UInt64? + var cTime: Date? + var mTime: Date? + var aTime: Date? var winAttributes: UInt32? } @@ -78,7 +78,7 @@ class SevenZipFileInfo { else { throw SevenZipError.externalNotSupported } for i in 0.. Date: Sun, 25 Mar 2018 23:42:53 +0300 Subject: [PATCH 07/53] Date init from ntfs timestamp is no longer failable The only reason for it to be was to propagate optionality of UInt64 argument. Instead we can if-let ntfs timestamp and call this initializer with non-optional argument. We also now force-unwrap ntfsReferenceDate, since it is likely to be a system problem if we cannot create definetely correct date from its components. --- Sources/Common/Extensions.swift | 10 +++------- Sources/ZIP/ZipEntryInfo.swift | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Sources/Common/Extensions.swift b/Sources/Common/Extensions.swift index 318a9d7e..556d36d4 100644 --- a/Sources/Common/Extensions.swift +++ b/Sources/Common/Extensions.swift @@ -50,14 +50,10 @@ extension Date { private static let ntfsReferenceDate = DateComponents(calendar: Calendar(identifier: .iso8601), timeZone: TimeZone(abbreviation: "UTC"), year: 1601, month: 1, day: 1, - hour: 0, minute: 0, second: 0).date + hour: 0, minute: 0, second: 0).date! - init?(_ ntfsTime: UInt64?) { - if let time = ntfsTime, let ntfsReferenceDate = Date.ntfsReferenceDate { - self.init(timeInterval: TimeInterval(time) / 10_000_000, since: ntfsReferenceDate) - } else { - return nil - } + init(_ ntfsTime: UInt64) { + self.init(timeInterval: TimeInterval(ntfsTime) / 10_000_000, since: .ntfsReferenceDate) } } diff --git a/Sources/ZIP/ZipEntryInfo.swift b/Sources/ZIP/ZipEntryInfo.swift index e7e86dda..ca0c13e4 100644 --- a/Sources/ZIP/ZipEntryInfo.swift +++ b/Sources/ZIP/ZipEntryInfo.swift @@ -114,9 +114,9 @@ public struct ZipEntryInfo: ContainerEntryInfo { if let mtimestamp = cdEntry.modificationTimestamp { // Extended Timestamp extra field. self.modificationTime = Date(timeIntervalSince1970: TimeInterval(mtimestamp)) - } else if let mtime = Date(cdEntry.ntfsMtime) { + } else if let mtime = cdEntry.ntfsMtime { // NTFS extra field. - self.modificationTime = mtime + self.modificationTime = Date(mtime) } else { // Native ZIP modification time. let dosDate = cdEntry.lastModFileDate.toInt() @@ -140,9 +140,9 @@ public struct ZipEntryInfo: ContainerEntryInfo { if let ctimestamp = localHeader.creationTimestamp { // Extended Timestamp extra field. self.creationTime = Date(timeIntervalSince1970: TimeInterval(ctimestamp)) - } else if let ctime = Date(cdEntry.ntfsCtime) { + } else if let ctime = cdEntry.ntfsCtime { // NTFS extra field. - self.creationTime = ctime + self.creationTime = Date(ctime) } else { self.creationTime = nil } @@ -151,9 +151,9 @@ public struct ZipEntryInfo: ContainerEntryInfo { if let atimestamp = localHeader.accessTimestamp { // Extended Timestamp extra field. self.accessTime = Date(timeIntervalSince1970: TimeInterval(atimestamp)) - } else if let atime = Date(cdEntry.ntfsAtime) { + } else if let atime = cdEntry.ntfsAtime { // NTFS extra field. - self.accessTime = atime + self.accessTime = Date(atime) } else { self.accessTime = nil } From 67f5ebba0fcb5115f315fb177327d2a89fe03668 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 31 Mar 2018 12:08:46 +0300 Subject: [PATCH 08/53] [TAR] Add nested SpecialEntryType enum into TarEntryInfo --- Sources/TAR/TarEntryInfo.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index 30d1a51e..ef802dd7 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -9,6 +9,13 @@ import BitByteData /// Provides access to information about an entry from the TAR container. public struct TarEntryInfo: ContainerEntryInfo { + enum SpecialEntryType: UInt8 { + case longName = 76 + case longLinkName = 75 + case globalExtendedHeader = 103 + case localExtendedHeader = 120 + } + // MARK: ContainerEntryInfo /** From c9ea4f33fc33de3dedb027b7d22766d3b40cf25d Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Mon, 26 Mar 2018 08:51:29 +0300 Subject: [PATCH 09/53] [TAR] Use special entry type internal property of TarEntryInfo instead of several isSomething properties --- Sources/TAR/TarContainer.swift | 46 ++++++++++++++++------------------ Sources/TAR/TarEntryInfo.swift | 12 +++------ 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index ebf3ad8b..c8e57fd9 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -72,34 +72,30 @@ public class TarContainer: Container { while byteReader.data[byteReader.offset.. Date: Fri, 30 Mar 2018 23:02:12 +0300 Subject: [PATCH 10/53] Various changes related to upgrading to Xcode 9.3 and Swift 4.1 Changed xcode version used in CI; changed swift version .swift-version file; changed swift version in podspec; changed swift badge in readme; consistently use double-quotes for strings in podspec; upgrade project to Xcode 9.3 and new project format; use Xcode's "new build system". --- .swift-version | 2 +- .travis.yml | 4 +- README.md | 2 +- SWCompression.podspec | 66 +++++++++---------- SWCompression.xcodeproj/project.pbxproj | 46 ++++++++++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 +++ .../xcshareddata/WorkspaceSettings.xcsettings | 8 +++ .../xcschemes/SWCompression.xcscheme | 4 +- 8 files changed, 92 insertions(+), 48 deletions(-) create mode 100644 SWCompression.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 SWCompression.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/.swift-version b/.swift-version index 5186d070..7d5c902e 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0 +4.1 diff --git a/.travis.yml b/.travis.yml index 4c275405..58b6f94a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ jobs: - stage: test language: objective-c os: osx - osx_image: xcode9.2 + osx_image: xcode9.3 before_install: - brew update install: @@ -26,7 +26,7 @@ jobs: if: tag IS present language: objective-c os: osx - osx_image: xcode9.2 + osx_image: xcode9.3 env: secure: iavIkrus2Xd3b086nz2srMGl52yqzLuCdhyEAhMODVqkzqMQ17s10y1TNb+vkepd0HgxI9j57d5X7tfChjWuWDwE2hZKjr/Kx2DfiUr1AKQD6ymuGrq/0Vv6yL9dfPU8goFArcrsBcyVKczLtTuLCKL498ZqokkQc/3kGvzW74lv+z410MfHS9/tvToO/yXJckL6qJ2XBAiElfOO0rEkllTeCo6N3bjcHZ2o7PE0K+CHYxwNKj0TmPmuNWZ3U4fzoWzkk01re1C1l5cpSb20g+2aGyi0yYX+PomX7fIIqNq9vmmyoeNdr35yqoQv/0zFeFnps83NKmZLAjSUhiUdhlbuBLBE+w8544LOaZnMDlFmpDjgyaVnRrOh0NrBB1FwU48aGfX5ljRQmk/07FTEUjvwvGGoOpz8lrLZi148FMHEospL3Sf7d8K+Q9WdtLTGk7HCnbOVcxS6oB/SWF/Cj6n5wu+EI1floBaZEsNPR40Gd4eM/Ik/E3lDrZThGDCWQsao981wm7IfEDBR1nuMME8gpZINFANNS1+5miFaGdTnDTp4Yd5MGEFZm+K8x+TG1891NwNH1ZmKXlypJXiUzvSjbh2ViNJGekdQj9q2gj2ZFlCfHJ05adwJ4w9qRuF00HpAOD6At6EnsjDXFJeTZS5dj8fi2YsU9or8KfTFoNY= before_install: diff --git a/README.md b/README.md index 23455135..17d230e5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SWCompression -[![Swift 4](https://img.shields.io/badge/Swift-4.0-blue.svg)](https://developer.apple.com/swift/) +[![Swift 4.1](https://img.shields.io/badge/Swift-4.1-blue.svg)](https://developer.apple.com/swift/) [![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/tsolomko/SWCompression/master/LICENSE) [![Build Status](https://travis-ci.org/tsolomko/SWCompression.svg?branch=develop)](https://travis-ci.org/tsolomko/SWCompression) diff --git a/SWCompression.podspec b/SWCompression.podspec index d089ab03..0a68532f 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -20,59 +20,59 @@ Pod::Spec.new do |s| s.tvos.deployment_target = "9.0" s.watchos.deployment_target = "2.0" - s.swift_version = '4.0' + s.swift_version = "4.1" - s.dependency 'BitByteData', '~> 1.1' + s.dependency "BitByteData", "~> 1.1" - s.subspec 'Deflate' do |sp| - sp.source_files = 'Sources/{Deflate/*,Common/*}.swift' - sp.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DSWCOMPRESSION_POD_DEFLATE' } + s.subspec "Deflate" do |sp| + sp.source_files = "Sources/{Deflate/*,Common/*}.swift" + sp.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "-DSWCOMPRESSION_POD_DEFLATE" } end - s.subspec 'GZip' do |sp| - sp.dependency 'SWCompression/Deflate' - sp.source_files = 'Sources/{GZip/*,Common/*}.swift' + s.subspec "GZip" do |sp| + sp.dependency "SWCompression/Deflate" + sp.source_files = "Sources/{GZip/*,Common/*}.swift" end - s.subspec 'Zlib' do |sp| - sp.dependency 'SWCompression/Deflate' - sp.source_files = 'Sources/{Zlib/*,Common/*}.swift' + s.subspec "Zlib" do |sp| + sp.dependency "SWCompression/Deflate" + sp.source_files = "Sources/{Zlib/*,Common/*}.swift" end - s.subspec 'BZip2' do |sp| - sp.source_files = 'Sources/{BZip2/*,Common/*}.swift' - sp.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DSWCOMPRESSION_POD_BZ2' } + s.subspec "BZip2" do |sp| + sp.source_files = "Sources/{BZip2/*,Common/*}.swift" + sp.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "-DSWCOMPRESSION_POD_BZ2" } end - s.subspec 'LZMA' do |sp| - sp.source_files = 'Sources/{LZMA/*,Common/*}.swift' - sp.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DSWCOMPRESSION_POD_LZMA' } + s.subspec "LZMA" do |sp| + sp.source_files = "Sources/{LZMA/*,Common/*}.swift" + sp.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "-DSWCOMPRESSION_POD_LZMA" } end - s.subspec 'LZMA2' do |sp| - sp.dependency 'SWCompression/LZMA' - sp.source_files = 'Sources/{LZMA2/*,Common/*}.swift' + s.subspec "LZMA2" do |sp| + sp.dependency "SWCompression/LZMA" + sp.source_files = "Sources/{LZMA2/*,Common/*}.swift" end - s.subspec 'XZ' do |sp| - sp.dependency 'SWCompression/LZMA2' - sp.source_files = 'Sources/{XZ/*,Common/*}.swift' + s.subspec "XZ" do |sp| + sp.dependency "SWCompression/LZMA2" + sp.source_files = "Sources/{XZ/*,Common/*}.swift" end - s.subspec 'ZIP' do |sp| - sp.dependency 'SWCompression/Deflate' - sp.source_files = 'Sources/{Zip/*,Common/*,Common/Container/*}.swift' - sp.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DSWCOMPRESSION_POD_ZIP' } + s.subspec "ZIP" do |sp| + sp.dependency "SWCompression/Deflate" + sp.source_files = "Sources/{Zip/*,Common/*,Common/Container/*}.swift" + sp.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "-DSWCOMPRESSION_POD_ZIP" } end - s.subspec 'TAR' do |sp| - sp.source_files = 'Sources/{TAR/*,Common/*,Common/Container/*}.swift' + s.subspec "TAR" do |sp| + sp.source_files = "Sources/{TAR/*,Common/*,Common/Container/*}.swift" end - s.subspec 'SevenZip' do |sp| - sp.dependency 'SWCompression/LZMA2' - sp.source_files = 'Sources/{7-Zip/*,Common/*,Common/Container/*}.swift' - sp.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS' => '-DSWCOMPRESSION_POD_SEVENZIP' } + s.subspec "SevenZip" do |sp| + sp.dependency "SWCompression/LZMA2" + sp.source_files = "Sources/{7-Zip/*,Common/*,Common/Container/*}.swift" + sp.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "-DSWCOMPRESSION_POD_SEVENZIP" } end end diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index c198c336..3af695e0 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 48; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -854,7 +854,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Timofey Solomko"; TargetAttributes = { 06BE1AC71DB410F100EE0F59 = { @@ -867,7 +867,7 @@ }; }; buildConfigurationList = 06BE1AC21DB410F100EE0F59 /* Build configuration list for PBXProject "SWCompression" */; - compatibilityVersion = "Xcode 8.0"; + compatibilityVersion = "Xcode 9.3"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -1125,15 +1125,18 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; @@ -1168,15 +1171,18 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; @@ -1197,7 +1203,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; SDKROOT = macosx; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; WATCHOS_DEPLOYMENT_TARGET = 2.0; @@ -1221,7 +1227,13 @@ "FRAMEWORK_SEARCH_PATHS[sdk=watchsimulator*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks @executable_path/Frameworks @loader_path/../Frameworks @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/Frameworks", + "@executable_path/Frameworks", + "@loader_path/../Frameworks", + "@executable_path/../Frameworks", + ); OTHER_LDFLAGS = ( "-framework", BitByteData, @@ -1250,7 +1262,13 @@ "FRAMEWORK_SEARCH_PATHS[sdk=watchsimulator*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks @executable_path/Frameworks @loader_path/../Frameworks @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/Frameworks", + "@executable_path/Frameworks", + "@loader_path/../Frameworks", + "@executable_path/../Frameworks", + ); OTHER_LDFLAGS = ( "-framework", BitByteData, @@ -1267,7 +1285,13 @@ buildSettings = { COPY_PHASE_STRIP = NO; INFOPLIST_FILE = SWCompression.xcodeproj/TestSWCompression.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks @executable_path/Frameworks @loader_path/../Frameworks @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/Frameworks", + "@executable_path/Frameworks", + "@loader_path/../Frameworks", + "@executable_path/../Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = me.tsolomko.TestSWCompression; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; @@ -1279,7 +1303,13 @@ buildSettings = { COPY_PHASE_STRIP = NO; INFOPLIST_FILE = SWCompression.xcodeproj/TestSWCompression.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks @executable_path/Frameworks @loader_path/../Frameworks @executable_path/../Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@loader_path/Frameworks", + "@executable_path/Frameworks", + "@loader_path/../Frameworks", + "@executable_path/../Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = me.tsolomko.TestSWCompression; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; diff --git a/SWCompression.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SWCompression.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SWCompression.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SWCompression.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/SWCompression.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 00000000..3ddf867a --- /dev/null +++ b/SWCompression.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + BuildSystemType + Latest + + diff --git a/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme b/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme index c481b3e4..a7095ec1 100644 --- a/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme +++ b/SWCompression.xcodeproj/xcshareddata/xcschemes/SWCompression.xcscheme @@ -1,6 +1,6 @@ Date: Sat, 24 Mar 2018 19:31:12 +0300 Subject: [PATCH 11/53] [ZIP] Add ZipExtraField protocol and ZipExtraFieldLocation enum --- SWCompression.xcodeproj/project.pbxproj | 4 ++++ Sources/ZIP/ZipExtraField.swift | 32 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Sources/ZIP/ZipExtraField.swift diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 3af695e0..9902262a 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 06393DF51F1A7F8E00A647A0 /* ZipString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06393DF41F1A7F8E00A647A0 /* ZipString.swift */; }; 063DF10D1DE1F07800F38082 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063DF1061DE1F07800F38082 /* Extensions.swift */; }; 063DF1131DE1F07800F38082 /* DecodingHuffmanTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 063DF1081DE1F07800F38082 /* DecodingHuffmanTree.swift */; }; + 0642998B206017590044BA0C /* ZipExtraField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0642998A206017590044BA0C /* ZipExtraField.swift */; }; 064512871F82CE63006490BA /* 7zCoder+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064512861F82CE63006490BA /* 7zCoder+Equatable.swift */; }; 064F72241F1E5D4400017297 /* 7zContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064F72231F1E5D4400017297 /* 7zContainer.swift */; }; 064F72291F1E638A00017297 /* 7zError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 064F72281F1E638A00017297 /* 7zError.swift */; }; @@ -236,6 +237,7 @@ 06393DF41F1A7F8E00A647A0 /* ZipString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZipString.swift; sourceTree = ""; }; 063DF1061DE1F07800F38082 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Extensions.swift; path = Sources/Common/Extensions.swift; sourceTree = SOURCE_ROOT; }; 063DF1081DE1F07800F38082 /* DecodingHuffmanTree.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DecodingHuffmanTree.swift; path = Sources/Common/DecodingHuffmanTree.swift; sourceTree = SOURCE_ROOT; }; + 0642998A206017590044BA0C /* ZipExtraField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZipExtraField.swift; sourceTree = ""; }; 064492581DC606D400F10981 /* ZlibArchive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZlibArchive.swift; sourceTree = ""; }; 064512861F82CE63006490BA /* 7zCoder+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "7zCoder+Equatable.swift"; sourceTree = ""; }; 064F72231F1E5D4400017297 /* 7zContainer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = 7zContainer.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; @@ -560,6 +562,7 @@ 067518351E2A86F700D16354 /* ZipContainer.swift */, 061C06411F0E8AD500832F0C /* ZipEntry.swift */, 06BAC5931F8CFF28002443F4 /* ZipEntryInfo.swift */, + 0642998A206017590044BA0C /* ZipExtraField.swift */, 061C063C1F0E8AB700832F0C /* ZipError.swift */, 06393DF41F1A7F8E00A647A0 /* ZipString.swift */, 061C064C1F0E901C00832F0C /* ZipLocalHeader.swift */, @@ -1083,6 +1086,7 @@ 064F72291F1E638A00017297 /* 7zError.swift in Sources */, 06CDFCAD1F111DBE00292758 /* LZMAError.swift in Sources */, 06E6A6391F5C0FBB00D04856 /* HuffmanLength.swift in Sources */, + 0642998B206017590044BA0C /* ZipExtraField.swift in Sources */, 0656B82B1F8A979A00111605 /* ByteReader+Tar.swift in Sources */, 06B689581F278815007C9316 /* 7zProperty.swift in Sources */, 0686A63B1FA4C07D00E89C9E /* FileSystemType.swift in Sources */, diff --git a/Sources/ZIP/ZipExtraField.swift b/Sources/ZIP/ZipExtraField.swift new file mode 100644 index 00000000..95686bd2 --- /dev/null +++ b/Sources/ZIP/ZipExtraField.swift @@ -0,0 +1,32 @@ +// Copyright (c) 2018 Timofey Solomko +// Licensed under MIT License +// +// See LICENSE for license information + +import BitByteData + +public protocol ZipExtraField { + + static var id: UInt16 { get } + + var location: ZipExtraFieldLocation { get } + var size: Int { get } + + init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) + +} + +extension ZipExtraField { + + public var id: UInt16 { + return Self.id + } + +} + +public enum ZipExtraFieldLocation { + + case centralDirectory + case localHeader + +} From de0fcec3cc494b76098db51eccd26c51de0eaec9 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 24 Mar 2018 19:33:34 +0300 Subject: [PATCH 12/53] [ZIP] Add structs for all "standard" extra fields These "standard" extra fields are already implemented in LocalHeader/CDEntry. --- SWCompression.xcodeproj/project.pbxproj | 4 + Sources/ZIP/StandardExtraFields.swift | 135 ++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 Sources/ZIP/StandardExtraFields.swift diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 9902262a..b7e62172 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0606CF8120641209002B6EE9 /* StandardExtraFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0606CF8020641209002B6EE9 /* StandardExtraFields.swift */; }; 06092A1A1FA4CB0300DE9FD5 /* CompressionMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06092A191FA4CB0300DE9FD5 /* CompressionMethod.swift */; }; 06092A241FA4CC3D00DE9FD5 /* CompressionMethod+Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06092A231FA4CC3D00DE9FD5 /* CompressionMethod+Zip.swift */; }; 061C06211F0E89D900832F0C /* XZError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061C06201F0E89D900832F0C /* XZError.swift */; }; @@ -205,6 +206,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0606CF8020641209002B6EE9 /* StandardExtraFields.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardExtraFields.swift; sourceTree = ""; }; 06092A191FA4CB0300DE9FD5 /* CompressionMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompressionMethod.swift; sourceTree = ""; }; 06092A231FA4CC3D00DE9FD5 /* CompressionMethod+Zip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CompressionMethod+Zip.swift"; sourceTree = ""; }; 061C06201F0E89D900832F0C /* XZError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XZError.swift; sourceTree = ""; }; @@ -563,6 +565,7 @@ 061C06411F0E8AD500832F0C /* ZipEntry.swift */, 06BAC5931F8CFF28002443F4 /* ZipEntryInfo.swift */, 0642998A206017590044BA0C /* ZipExtraField.swift */, + 0606CF8020641209002B6EE9 /* StandardExtraFields.swift */, 061C063C1F0E8AB700832F0C /* ZipError.swift */, 06393DF41F1A7F8E00A647A0 /* ZipString.swift */, 061C064C1F0E901C00832F0C /* ZipLocalHeader.swift */, @@ -1047,6 +1050,7 @@ 06A3933A1DE0709300182E12 /* ZlibArchive.swift in Sources */, 06E30F391F82D2DD00F80167 /* HuffmanLength+Comparable.swift in Sources */, 061C063D1F0E8AB700832F0C /* ZipError.swift in Sources */, + 0606CF8120641209002B6EE9 /* StandardExtraFields.swift in Sources */, 0631CB061F81109E00A2E0AB /* Deflate+Constants.swift in Sources */, 06D95AC11F4C54E0006B46AC /* BZip2+Compress.swift in Sources */, 06912BD21F5C8F3D0070BB60 /* Deflate+Lengths.swift in Sources */, diff --git a/Sources/ZIP/StandardExtraFields.swift b/Sources/ZIP/StandardExtraFields.swift new file mode 100644 index 00000000..8a5ec1ef --- /dev/null +++ b/Sources/ZIP/StandardExtraFields.swift @@ -0,0 +1,135 @@ +// Copyright (c) 2018 Timofey Solomko +// Licensed under MIT License +// +// See LICENSE for license information + +import BitByteData + +struct ExtendedTimestampExtraField: ZipExtraField { + + static let id: UInt16 = 0x5455 + + let size: Int + let location: ZipExtraFieldLocation + + var accessTimestamp: UInt32? + var creationTimestamp: UInt32? + var modificationTimestamp: UInt32? + + init(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { + self.size = size + self.location = location + switch location { + case .centralDirectory: + let flags = byteReader.byte() + if flags & 0x01 != 0 { + self.modificationTimestamp = byteReader.uint32() + } + case .localHeader: + let flags = byteReader.byte() + if flags & 0x01 != 0 { + self.modificationTimestamp = byteReader.uint32() + } + if flags & 0x02 != 0 { + self.accessTimestamp = byteReader.uint32() + } + if flags & 0x04 != 0 { + self.creationTimestamp = byteReader.uint32() + } + } + } + +} + +struct NtfsExtraField: ZipExtraField { + + static let id: UInt16 = 0x000A + + let size: Int + let location: ZipExtraFieldLocation + + let ntfsAtime: UInt64 + let ntfsCtime: UInt64 + let ntfsMtime: UInt64 + + init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { + self.size = size + self.location = location + byteReader.offset += 4 // Skip reserved bytes + let tag = byteReader.uint16() // This attribute's tag + byteReader.offset += 2 // Skip size of this attribute + guard tag == 0x0001 + else { return nil } + self.ntfsMtime = byteReader.uint64() + self.ntfsAtime = byteReader.uint64() + self.ntfsCtime = byteReader.uint64() + } + +} + +struct InfoZipUnixExtraField: ZipExtraField { + + static let id: UInt16 = 0x7855 + + let size: Int + let location: ZipExtraFieldLocation + + let infoZipUid: UInt16 + let infoZipGid: UInt16 + + init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { + self.size = size + self.location = location + switch location { + case .centralDirectory: + return nil + case .localHeader: + self.infoZipUid = byteReader.uint16() + self.infoZipGid = byteReader.uint16() + } + } + +} + +struct InfoZipNewUnixExtraField: ZipExtraField { + + static let id: UInt16 = 0x7875 + + let size: Int + let location: ZipExtraFieldLocation + + var infoZipNewUid: Int? + var infoZipNewGid: Int? + + init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { + self.size = size + self.location = location + guard byteReader.byte() == 1 // Version must be 1 + else { return nil } + + let uidSize = byteReader.byte().toInt() + if uidSize > 8 { + byteReader.offset += uidSize + } else { + var uid = 0 + for i in 0.. 8 { + byteReader.offset += gidSize + } else { + var gid = 0 + for i in 0.. Date: Sun, 25 Mar 2018 13:36:36 +0300 Subject: [PATCH 13/53] [ZIP] Use new Standard Extra Field structs in central directory, local header and entry info --- Sources/ZIP/ZipCentralDirectoryEntry.swift | 60 +++------------- Sources/ZIP/ZipEntryInfo.swift | 18 ++--- Sources/ZIP/ZipLocalHeader.swift | 80 ++++------------------ 3 files changed, 35 insertions(+), 123 deletions(-) diff --git a/Sources/ZIP/ZipCentralDirectoryEntry.swift b/Sources/ZIP/ZipCentralDirectoryEntry.swift index 79d80177..355658f5 100644 --- a/Sources/ZIP/ZipCentralDirectoryEntry.swift +++ b/Sources/ZIP/ZipCentralDirectoryEntry.swift @@ -29,18 +29,15 @@ struct ZipCentralDirectoryEntry { private(set) var localHeaderOffset: UInt64 // 0x5455 extra field. - private(set) var modificationTimestamp: UInt32? + private(set) var extendedTimestampExtraField: ExtendedTimestampExtraField? - // 0x000a extra field. - private(set) var ntfsMtime: UInt64? - private(set) var ntfsAtime: UInt64? - private(set) var ntfsCtime: UInt64? + /// 0x000a extra field. + private(set) var ntfsExtraField: NtfsExtraField? // 0x7855 extra field doesn't have any information in Central Directory. - // 0x7875 extra field. - private(set) var infoZipNewUid: Int? - private(set) var infoZipNewGid: Int? + /// 0x7875 extra field. + private(set) var infoZipNewUnixExtraField: InfoZipNewUnixExtraField? let nextEntryOffset: Int @@ -87,6 +84,7 @@ struct ZipCentralDirectoryEntry { let size = byteReader.uint16().toInt() switch headerID { case 0x0001: // Zip64 + // Zip64 extra field is a special case, because it requires knowledge about central directory fields. if self.uncompSize == 0xFFFFFFFF { self.uncompSize = byteReader.uint64() } @@ -100,52 +98,14 @@ struct ZipCentralDirectoryEntry { self.diskNumberStart = byteReader.uint32() } case 0x5455: // Extended Timestamp - let flags = byteReader.byte() - guard flags & 0xF8 == 0 - else { break } - if flags & 0x01 != 0 { - self.modificationTimestamp = byteReader.uint32() - } + self.extendedTimestampExtraField = ExtendedTimestampExtraField(byteReader, size, + location: .centralDirectory) case 0x000a: // NTFS Extra Fields - let ntfsExtraFieldsStartIndex = byteReader.offset - byteReader.offset += 4 // Skipping reserved bytes. - while byteReader.offset - ntfsExtraFieldsStartIndex < size { - let tag = byteReader.uint16() - byteReader.offset += 2 // Skipping size of attributes for this tag. - if tag == 0x0001 { - self.ntfsMtime = byteReader.uint64() - self.ntfsAtime = byteReader.uint64() - self.ntfsCtime = byteReader.uint64() - } - } + self.ntfsExtraField = NtfsExtraField(byteReader, size, location: .centralDirectory) case 0x7855: // Info-ZIP Unix Extra Field break // It doesn't contain any information in Central Directory. case 0x7875: // Info-ZIP New Unix Extra Field - guard byteReader.byte() == 1 // Version must be 1. - else { break } - let uidSize = byteReader.byte().toInt() - if uidSize > 8 { - byteReader.offset += uidSize - } else { - var uid = 0 - for i in 0.. 8 { - byteReader.offset += gidSize - } else { - var gid = 0 - for i in 0.. 8 { - byteReader.offset += uidSize - } else { - var uid = 0 - for i in 0.. 8 { - byteReader.offset += gidSize - } else { - var gid = 0 - for i in 0.. Date: Sun, 25 Mar 2018 13:39:21 +0300 Subject: [PATCH 14/53] [ZIP] Add support for custom extra fields --- Sources/ZIP/ZipCentralDirectoryEntry.swift | 17 ++++++++++++++++- Sources/ZIP/ZipContainer.swift | 2 ++ Sources/ZIP/ZipEntryInfo.swift | 7 +++++++ Sources/ZIP/ZipLocalHeader.swift | 17 ++++++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Sources/ZIP/ZipCentralDirectoryEntry.swift b/Sources/ZIP/ZipCentralDirectoryEntry.swift index 355658f5..f449f4b9 100644 --- a/Sources/ZIP/ZipCentralDirectoryEntry.swift +++ b/Sources/ZIP/ZipCentralDirectoryEntry.swift @@ -39,6 +39,8 @@ struct ZipCentralDirectoryEntry { /// 0x7875 extra field. private(set) var infoZipNewUnixExtraField: InfoZipNewUnixExtraField? + let customExtraFields: [ZipExtraField] + let nextEntryOffset: Int init(_ byteReader: ByteReader) throws { @@ -78,6 +80,7 @@ struct ZipCentralDirectoryEntry { self.fileName = fileName let extraFieldStart = byteReader.offset + var customExtraFields = [ZipExtraField]() while byteReader.offset - extraFieldStart < extraFieldLength { // There are a lot of possible extra fields. let headerID = byteReader.uint16() @@ -107,9 +110,21 @@ struct ZipCentralDirectoryEntry { case 0x7875: // Info-ZIP New Unix Extra Field self.infoZipNewUnixExtraField = InfoZipNewUnixExtraField(byteReader, size, location: .centralDirectory) default: - byteReader.offset += size + let customFieldOffset = byteReader.offset + if let customExtraFieldType = ZipContainer.customExtraFields[headerID], + customExtraFieldType.id == headerID, + let customExtraField = customExtraFieldType.init(byteReader, size, location: .centralDirectory), + customExtraField.id == headerID { + customExtraFields.append(customExtraField) + guard byteReader.offset == customFieldOffset + size + else { fatalError("Custom field in Central Directory with ID=\(headerID) of" + + "type=\(customExtraFieldType) failed to read exactly \(size) bytes.") } + } else { + byteReader.offset = customFieldOffset + size + } } } + self.customExtraFields = customExtraFields guard let fileComment = byteReader.getZipStringField(fileCommentLength, useUtf8) else { throw ZipError.wrongTextField } diff --git a/Sources/ZIP/ZipContainer.swift b/Sources/ZIP/ZipContainer.swift index d2b2ed33..64072f7b 100644 --- a/Sources/ZIP/ZipContainer.swift +++ b/Sources/ZIP/ZipContainer.swift @@ -9,6 +9,8 @@ import BitByteData /// Provides functions for work with ZIP containers. public class ZipContainer: Container { + public static var customExtraFields = [UInt16: ZipExtraField.Type]() + /** Processes ZIP container and returns an array of `ZipEntry` with information and data for all entries. diff --git a/Sources/ZIP/ZipEntryInfo.swift b/Sources/ZIP/ZipEntryInfo.swift index 908ad1b3..5ebc266d 100644 --- a/Sources/ZIP/ZipEntryInfo.swift +++ b/Sources/ZIP/ZipEntryInfo.swift @@ -92,6 +92,8 @@ public struct ZipEntryInfo: ContainerEntryInfo { */ public let groupID: Int? + public let customExtraFields: [ZipExtraField] + let cdEntry: ZipCentralDirectoryEntry let localHeader: ZipLocalHeader @@ -200,6 +202,11 @@ public struct ZipEntryInfo: ContainerEntryInfo { // Owner's group ID. self.groupID = localHeader.infoZipNewUnixExtraField?.infoZipNewGid ?? localHeader.infoZipUnixExtraField?.infoZipGid.toInt() + + // Custom extra fields. + var customExtraFields = cdEntry.customExtraFields + customExtraFields.append(contentsOf: localHeader.customExtraFields) + self.customExtraFields = customExtraFields } } diff --git a/Sources/ZIP/ZipLocalHeader.swift b/Sources/ZIP/ZipLocalHeader.swift index 88a31904..a0433636 100644 --- a/Sources/ZIP/ZipLocalHeader.swift +++ b/Sources/ZIP/ZipLocalHeader.swift @@ -34,6 +34,8 @@ struct ZipLocalHeader { /// 0x7875 extra field. private(set) var infoZipNewUnixExtraField: InfoZipNewUnixExtraField? + let customExtraFields: [ZipExtraField] + let dataOffset: Int init(_ byteReader: ByteReader) throws { @@ -64,6 +66,7 @@ struct ZipLocalHeader { self.fileName = fileName let extraFieldStart = byteReader.offset + var customExtraFields = [ZipExtraField]() while byteReader.offset - extraFieldStart < extraFieldLength { // There are a lot of possible extra fields. let headerID = byteReader.uint16() @@ -85,9 +88,21 @@ struct ZipLocalHeader { case 0x7875: // Info-ZIP New Unix Extra Field self.infoZipNewUnixExtraField = InfoZipNewUnixExtraField(byteReader, size, location: .localHeader) default: - byteReader.offset += size + let customFieldOffset = byteReader.offset + if let customExtraFieldType = ZipContainer.customExtraFields[headerID], + customExtraFieldType.id == headerID, + let customExtraField = customExtraFieldType.init(byteReader, size, location: .localHeader), + customExtraField.id == headerID { + customExtraFields.append(customExtraField) + guard byteReader.offset == customFieldOffset + size + else { fatalError("Custom field in Local Header with ID=\(headerID) of" + + "type=\(customExtraFieldType) failed to read exactly \(size) bytes.") } + } else { + byteReader.offset = customFieldOffset + size + } } } + self.customExtraFields = customExtraFields self.dataOffset = byteReader.offset } From 6e8efe2b3944e428995a07781d2e0991010ac143 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 25 Mar 2018 15:08:27 +0300 Subject: [PATCH 15/53] Make BitByteData linking settings project-wide We now use BitByteData directly in TestSWCompression, so we need to link test target against BitByteData properly, the same way we do it for SWCompression. Since we don't want to unnecessary duplicate equal target settings, it was decided to make them project-wide. --- SWCompression.xcodeproj/project.pbxproj | 36 +++++++++++++++---------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index b7e62172..83c479a5 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1155,6 +1155,13 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=macosx*]" = "\"$(SRCROOT)/Carthage/Build/Mac\""; + "FRAMEWORK_SEARCH_PATHS[sdk=watchos*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=watchsimulator*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -1166,6 +1173,10 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-framework", + BitByteData, + ); SDKROOT = macosx; SUPPORTED_PLATFORMS = "macosx watchsimulator iphonesimulator appletvsimulator watchos appletvos iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -1200,6 +1211,13 @@ CURRENT_PROJECT_VERSION = 59; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; + "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=macosx*]" = "\"$(SRCROOT)/Carthage/Build/Mac\""; + "FRAMEWORK_SEARCH_PATHS[sdk=watchos*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; + "FRAMEWORK_SEARCH_PATHS[sdk=watchsimulator*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -1209,6 +1227,10 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; + OTHER_LDFLAGS = ( + "-framework", + BitByteData, + ); SDKROOT = macosx; SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator"; SWIFT_COMPILATION_MODE = wholemodule; @@ -1226,13 +1248,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 59; DYLIB_INSTALL_NAME_BASE = "@rpath"; - "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=macosx*]" = "\"$(SRCROOT)/Carthage/Build/Mac\""; - "FRAMEWORK_SEARCH_PATHS[sdk=watchos*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=watchsimulator*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = ( @@ -1261,13 +1276,6 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 59; DYLIB_INSTALL_NAME_BASE = "@rpath"; - "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=appletvsimulator*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "\"$(SRCROOT)/Carthage/Build/iOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=macosx*]" = "\"$(SRCROOT)/Carthage/Build/Mac\""; - "FRAMEWORK_SEARCH_PATHS[sdk=watchos*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; - "FRAMEWORK_SEARCH_PATHS[sdk=watchsimulator*]" = "\"$(SRCROOT)/Carthage/Build/watchOS\""; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = ( From 4d72a0325b9320013b8d3d2c70e9f5345d6860d6 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 25 Mar 2018 15:03:34 +0300 Subject: [PATCH 16/53] [Tests] Add test for ZIP custom extra field --- SWCompression.xcodeproj/project.pbxproj | 8 ++++++ Tests/Test Files | 2 +- Tests/TestZipExtraField.swift | 25 ++++++++++++++++++ Tests/ZipTests.swift | 35 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Tests/TestZipExtraField.swift diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 83c479a5..63e79828 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -85,6 +85,8 @@ 06CDFCA81F111D9700292758 /* DeflateError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CDFCA71F111D9700292758 /* DeflateError.swift */; }; 06CDFCAD1F111DBE00292758 /* LZMAError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CDFCAC1F111DBE00292758 /* LZMAError.swift */; }; 06CDFCB21F111DEC00292758 /* LZMA2Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CDFCB11F111DEC00292758 /* LZMA2Error.swift */; }; + 06D42DA52067B46800C1A98B /* test_custom_extra_field.zip in Resources */ = {isa = PBXBuildFile; fileRef = 06D42DA42067B46800C1A98B /* test_custom_extra_field.zip */; }; + 06D42DA72067B71000C1A98B /* TestZipExtraField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06D42DA62067B71000C1A98B /* TestZipExtraField.swift */; }; 06D95AC11F4C54E0006B46AC /* BZip2+Compress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06D95AC01F4C54E0006B46AC /* BZip2+Compress.swift */; }; 06DDB1711F8190D400035BEF /* BZip2+BlockSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06DDB1701F8190D400035BEF /* BZip2+BlockSize.swift */; }; 06DE29B81FB7024C0098A761 /* ByteReader+ZipString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06DE29B71FB7024C0098A761 /* ByteReader+ZipString.swift */; }; @@ -284,6 +286,8 @@ 06CDFCA71F111D9700292758 /* DeflateError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeflateError.swift; sourceTree = ""; }; 06CDFCAC1F111DBE00292758 /* LZMAError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LZMAError.swift; sourceTree = ""; }; 06CDFCB11F111DEC00292758 /* LZMA2Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LZMA2Error.swift; sourceTree = ""; }; + 06D42DA42067B46800C1A98B /* test_custom_extra_field.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = test_custom_extra_field.zip; sourceTree = ""; }; + 06D42DA62067B71000C1A98B /* TestZipExtraField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestZipExtraField.swift; sourceTree = ""; }; 06D95AC01F4C54E0006B46AC /* BZip2+Compress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BZip2+Compress.swift"; sourceTree = ""; }; 06DDB1701F8190D400035BEF /* BZip2+BlockSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BZip2+BlockSize.swift"; sourceTree = ""; }; 06DE29B71FB7024C0098A761 /* ByteReader+ZipString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ByteReader+ZipString.swift"; sourceTree = ""; }; @@ -629,6 +633,7 @@ 06F065A61FFB763300312A82 /* TarTests.swift */, 06F065A91FFB763300312A82 /* XzTests.swift */, 06F065A41FFB763300312A82 /* ZipTests.swift */, + 06D42DA62067B71000C1A98B /* TestZipExtraField.swift */, 06F065A31FFB763300312A82 /* ZlibTests.swift */, ); path = Tests; @@ -723,6 +728,7 @@ 06F065DB1FFB763300312A82 /* test_empty_cont.zip */, 06F065DC1FFB763300312A82 /* SWCompressionSourceCode.zip */, 06F065DD1FFB763300312A82 /* test_zip64.zip */, + 06D42DA42067B46800C1A98B /* test_custom_extra_field.zip */, ); path = ZIP; sourceTree = ""; @@ -971,6 +977,7 @@ 06F0665E1FFB763400312A82 /* test_empty_cont.7z in Resources */, 06F066731FFB763400312A82 /* test3.bz2 in Resources */, 06F066471FFB763400312A82 /* test_empty_cont.zip in Resources */, + 06D42DA52067B46800C1A98B /* test_custom_extra_field.zip in Resources */, 06F0663E1FFB763400312A82 /* test6.xz in Resources */, 06F0666D1FFB763400312A82 /* test_win.7z in Resources */, 06F066571FFB763400312A82 /* test_empty_file.tar in Resources */, @@ -1109,6 +1116,7 @@ 06F066171FFB763300312A82 /* BZip2Tests.swift in Sources */, 06F066181FFB763300312A82 /* TarTests.swift in Sources */, 06F066191FFB763300312A82 /* GzipTests.swift in Sources */, + 06D42DA72067B71000C1A98B /* TestZipExtraField.swift in Sources */, 06F0661D1FFB763300312A82 /* LzmaTests.swift in Sources */, 06F0661B1FFB763300312A82 /* XzTests.swift in Sources */, 06F0661E1FFB763300312A82 /* BZip2CompressionTests.swift in Sources */, diff --git a/Tests/Test Files b/Tests/Test Files index 61fd5086..3c2f7716 160000 --- a/Tests/Test Files +++ b/Tests/Test Files @@ -1 +1 @@ -Subproject commit 61fd50861a9f063cc9b4c4701924945e28482066 +Subproject commit 3c2f77164529122aeb5f57458280f081c43c12ce diff --git a/Tests/TestZipExtraField.swift b/Tests/TestZipExtraField.swift new file mode 100644 index 00000000..390bcd0d --- /dev/null +++ b/Tests/TestZipExtraField.swift @@ -0,0 +1,25 @@ +// Copyright (c) 2018 Timofey Solomko +// Licensed under MIT License +// +// See LICENSE for license information + +import Foundation +import BitByteData +import SWCompression + +struct TestZipExtraField: ZipExtraField { + + static let id: UInt16 = 0x0646 + + let size: Int + let location: ZipExtraFieldLocation + + var helloString: String? + + init(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { + self.size = size + self.location = location + self.helloString = String(data: Data(bytes: byteReader.bytes(count: size)), encoding: .utf8) + } + +} diff --git a/Tests/ZipTests.swift b/Tests/ZipTests.swift index 962f4daf..04b61351 100644 --- a/Tests/ZipTests.swift +++ b/Tests/ZipTests.swift @@ -19,6 +19,41 @@ class ZipTests: XCTestCase { _ = try ZipContainer.open(container: testData) } + func testZipCustomExtraField() throws { + guard let testData = Constants.data(forTest: "test_custom_extra_field", withType: ZipTests.testType) else { + XCTFail("Unable to get test data.") + return + } + + // First, we check that without enabling support for our custom extra field, ZipContainer doesn't recognize it. + var result = try ZipContainer.open(container: testData) + XCTAssertEqual(result.count, 1) + XCTAssertEqual(result[0].info.customExtraFields.count, 0) + + // Enable support for custom extra field. + ZipContainer.customExtraFields[0x0646] = TestZipExtraField.self + + result = try ZipContainer.open(container: testData) + XCTAssertEqual(result.count, 1) + + let entry = result[0] + XCTAssertEqual(entry.info.customExtraFields.count, 2) + + for customExtraField in entry.info.customExtraFields { + XCTAssertTrue(customExtraField is TestZipExtraField) + XCTAssertEqual(customExtraField.id, TestZipExtraField.id) + if customExtraField.size == 13 { + XCTAssertEqual(customExtraField.location, .centralDirectory) + XCTAssertEqual((customExtraField as? TestZipExtraField)?.helloString, "Hello, Extra!") + } else if customExtraField.size == 20 { + XCTAssertEqual(customExtraField.location, .localHeader) + XCTAssertEqual((customExtraField as? TestZipExtraField)?.helloString, "Hello, Local Header!") + } else { + XCTFail("Wrong size for custom extra field.") + } + } + } + func testZip64() throws { guard let testData = Constants.data(forTest: "test_zip64", withType: ZipTests.testType) else { XCTFail("Unable to get test data.") From 0dc93bb077b41c23c0e6aaa1cfc0af299a326759 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 25 Mar 2018 15:57:38 +0300 Subject: [PATCH 17/53] [ZIP] Make names of properties of Standard extra fields shorter --- Sources/ZIP/StandardExtraFields.swift | 42 +++++++++++++-------------- Sources/ZIP/ZipEntryInfo.swift | 24 +++++++-------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/Sources/ZIP/StandardExtraFields.swift b/Sources/ZIP/StandardExtraFields.swift index 8a5ec1ef..037384ef 100644 --- a/Sources/ZIP/StandardExtraFields.swift +++ b/Sources/ZIP/StandardExtraFields.swift @@ -12,9 +12,9 @@ struct ExtendedTimestampExtraField: ZipExtraField { let size: Int let location: ZipExtraFieldLocation - var accessTimestamp: UInt32? - var creationTimestamp: UInt32? - var modificationTimestamp: UInt32? + var atime: UInt32? + var ctime: UInt32? + var mtime: UInt32? init(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { self.size = size @@ -23,18 +23,18 @@ struct ExtendedTimestampExtraField: ZipExtraField { case .centralDirectory: let flags = byteReader.byte() if flags & 0x01 != 0 { - self.modificationTimestamp = byteReader.uint32() + self.mtime = byteReader.uint32() } case .localHeader: let flags = byteReader.byte() if flags & 0x01 != 0 { - self.modificationTimestamp = byteReader.uint32() + self.mtime = byteReader.uint32() } if flags & 0x02 != 0 { - self.accessTimestamp = byteReader.uint32() + self.atime = byteReader.uint32() } if flags & 0x04 != 0 { - self.creationTimestamp = byteReader.uint32() + self.ctime = byteReader.uint32() } } } @@ -48,9 +48,9 @@ struct NtfsExtraField: ZipExtraField { let size: Int let location: ZipExtraFieldLocation - let ntfsAtime: UInt64 - let ntfsCtime: UInt64 - let ntfsMtime: UInt64 + let atime: UInt64 + let ctime: UInt64 + let mtime: UInt64 init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { self.size = size @@ -60,9 +60,9 @@ struct NtfsExtraField: ZipExtraField { byteReader.offset += 2 // Skip size of this attribute guard tag == 0x0001 else { return nil } - self.ntfsMtime = byteReader.uint64() - self.ntfsAtime = byteReader.uint64() - self.ntfsCtime = byteReader.uint64() + self.mtime = byteReader.uint64() + self.atime = byteReader.uint64() + self.ctime = byteReader.uint64() } } @@ -74,8 +74,8 @@ struct InfoZipUnixExtraField: ZipExtraField { let size: Int let location: ZipExtraFieldLocation - let infoZipUid: UInt16 - let infoZipGid: UInt16 + let uid: Int + let gid: Int init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { self.size = size @@ -84,8 +84,8 @@ struct InfoZipUnixExtraField: ZipExtraField { case .centralDirectory: return nil case .localHeader: - self.infoZipUid = byteReader.uint16() - self.infoZipGid = byteReader.uint16() + self.uid = byteReader.uint16().toInt() + self.gid = byteReader.uint16().toInt() } } @@ -98,8 +98,8 @@ struct InfoZipNewUnixExtraField: ZipExtraField { let size: Int let location: ZipExtraFieldLocation - var infoZipNewUid: Int? - var infoZipNewGid: Int? + var uid: Int? + var gid: Int? init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) { self.size = size @@ -116,7 +116,7 @@ struct InfoZipNewUnixExtraField: ZipExtraField { let byte = byteReader.byte() uid |= byte.toInt() << (8 * i) } - self.infoZipNewUid = uid + self.uid = uid } let gidSize = byteReader.byte().toInt() @@ -128,7 +128,7 @@ struct InfoZipNewUnixExtraField: ZipExtraField { let byte = byteReader.byte() gid |= byte.toInt() << (8 * i) } - self.infoZipNewGid = gid + self.gid = gid } } diff --git a/Sources/ZIP/ZipEntryInfo.swift b/Sources/ZIP/ZipEntryInfo.swift index 5ebc266d..dceab0b5 100644 --- a/Sources/ZIP/ZipEntryInfo.swift +++ b/Sources/ZIP/ZipEntryInfo.swift @@ -113,10 +113,10 @@ public struct ZipEntryInfo: ContainerEntryInfo { self.name = cdEntry.fileName // Set Modification Time. - if let mtimestamp = cdEntry.extendedTimestampExtraField?.modificationTimestamp { + if let mtime = cdEntry.extendedTimestampExtraField?.mtime { // Extended Timestamp extra field. - self.modificationTime = Date(timeIntervalSince1970: TimeInterval(mtimestamp)) - } else if let mtime = cdEntry.ntfsExtraField?.ntfsMtime { + self.modificationTime = Date(timeIntervalSince1970: TimeInterval(mtime)) + } else if let mtime = cdEntry.ntfsExtraField?.mtime { // NTFS extra field. self.modificationTime = Date(mtime) } else { @@ -139,10 +139,10 @@ public struct ZipEntryInfo: ContainerEntryInfo { } // Set Creation Time. - if let ctimestamp = localHeader.extendedTimestampExtraField?.creationTimestamp { + if let ctime = localHeader.extendedTimestampExtraField?.ctime { // Extended Timestamp extra field. - self.creationTime = Date(timeIntervalSince1970: TimeInterval(ctimestamp)) - } else if let ctime = cdEntry.ntfsExtraField?.ntfsCtime { + self.creationTime = Date(timeIntervalSince1970: TimeInterval(ctime)) + } else if let ctime = cdEntry.ntfsExtraField?.ctime { // NTFS extra field. self.creationTime = Date(ctime) } else { @@ -150,10 +150,10 @@ public struct ZipEntryInfo: ContainerEntryInfo { } // Set Creation Time. - if let atimestamp = localHeader.extendedTimestampExtraField?.accessTimestamp { + if let atime = localHeader.extendedTimestampExtraField?.atime { // Extended Timestamp extra field. - self.accessTime = Date(timeIntervalSince1970: TimeInterval(atimestamp)) - } else if let atime = cdEntry.ntfsExtraField?.ntfsAtime { + self.accessTime = Date(timeIntervalSince1970: TimeInterval(atime)) + } else if let atime = cdEntry.ntfsExtraField?.atime { // NTFS extra field. self.accessTime = Date(atime) } else { @@ -196,12 +196,10 @@ public struct ZipEntryInfo: ContainerEntryInfo { self.compressionMethod = CompressionMethod(localHeader.compressionMethod) // Owner's ID. - self.ownerID = localHeader.infoZipNewUnixExtraField?.infoZipNewUid ?? - localHeader.infoZipUnixExtraField?.infoZipUid.toInt() + self.ownerID = localHeader.infoZipNewUnixExtraField?.uid ?? localHeader.infoZipUnixExtraField?.uid // Owner's group ID. - self.groupID = localHeader.infoZipNewUnixExtraField?.infoZipNewGid ?? - localHeader.infoZipUnixExtraField?.infoZipGid.toInt() + self.groupID = localHeader.infoZipNewUnixExtraField?.gid ?? localHeader.infoZipUnixExtraField?.gid // Custom extra fields. var customExtraFields = cdEntry.customExtraFields From f5924af1c4089f661a691623daee7e7e61fbfbfa Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 30 Mar 2018 08:36:47 +0300 Subject: [PATCH 18/53] [ZIP] Correctly skip Info-ZIP Unix extra field in Central Directory --- Sources/ZIP/ZipCentralDirectoryEntry.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/ZIP/ZipCentralDirectoryEntry.swift b/Sources/ZIP/ZipCentralDirectoryEntry.swift index f449f4b9..3c6eb221 100644 --- a/Sources/ZIP/ZipCentralDirectoryEntry.swift +++ b/Sources/ZIP/ZipCentralDirectoryEntry.swift @@ -106,7 +106,9 @@ struct ZipCentralDirectoryEntry { case 0x000a: // NTFS Extra Fields self.ntfsExtraField = NtfsExtraField(byteReader, size, location: .centralDirectory) case 0x7855: // Info-ZIP Unix Extra Field - break // It doesn't contain any information in Central Directory. + // If there is any data for Info-ZIP Unix extra field in central directory (`size != 0`), skip it. + // However, according to definition of this extra field it shouldn't have any data in CD. + byteReader.offset += size case 0x7875: // Info-ZIP New Unix Extra Field self.infoZipNewUnixExtraField = InfoZipNewUnixExtraField(byteReader, size, location: .centralDirectory) default: From 756cf236593731481a8c77b836fa4ad486c889bc Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 30 Mar 2018 08:37:24 +0300 Subject: [PATCH 19/53] [ZIP] Add preconditions which check custom extra fields properties --- Sources/ZIP/ZipCentralDirectoryEntry.swift | 8 +++++++- Sources/ZIP/ZipLocalHeader.swift | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/ZIP/ZipCentralDirectoryEntry.swift b/Sources/ZIP/ZipCentralDirectoryEntry.swift index 3c6eb221..66753808 100644 --- a/Sources/ZIP/ZipCentralDirectoryEntry.swift +++ b/Sources/ZIP/ZipCentralDirectoryEntry.swift @@ -117,10 +117,16 @@ struct ZipCentralDirectoryEntry { customExtraFieldType.id == headerID, let customExtraField = customExtraFieldType.init(byteReader, size, location: .centralDirectory), customExtraField.id == headerID { - customExtraFields.append(customExtraField) + precondition(customExtraField.location == .centralDirectory, + "Custom field in Central Directory with ID=\(headerID) of type=\(customExtraFieldType)" + + " changed location.") + precondition(customExtraField.size == size, + "Custom field in Central Directory with ID=\(headerID) of type=\(customExtraFieldType)" + + " changed size.") guard byteReader.offset == customFieldOffset + size else { fatalError("Custom field in Central Directory with ID=\(headerID) of" + "type=\(customExtraFieldType) failed to read exactly \(size) bytes.") } + customExtraFields.append(customExtraField) } else { byteReader.offset = customFieldOffset + size } diff --git a/Sources/ZIP/ZipLocalHeader.swift b/Sources/ZIP/ZipLocalHeader.swift index a0433636..5fa0aa4f 100644 --- a/Sources/ZIP/ZipLocalHeader.swift +++ b/Sources/ZIP/ZipLocalHeader.swift @@ -93,10 +93,16 @@ struct ZipLocalHeader { customExtraFieldType.id == headerID, let customExtraField = customExtraFieldType.init(byteReader, size, location: .localHeader), customExtraField.id == headerID { - customExtraFields.append(customExtraField) + precondition(customExtraField.location == .localHeader, + "Custom field in Local Header with ID=\(headerID) of type=\(customExtraFieldType)" + + " changed location.") + precondition(customExtraField.size == size, + "Custom field in Local Header with ID=\(headerID) of type=\(customExtraFieldType)" + + " changed size.") guard byteReader.offset == customFieldOffset + size else { fatalError("Custom field in Local Header with ID=\(headerID) of" + "type=\(customExtraFieldType) failed to read exactly \(size) bytes.") } + customExtraFields.append(customExtraField) } else { byteReader.offset = customFieldOffset + size } From d4b728125b2cb9496a0dc745cd4d6edef09c50d3 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 30 Mar 2018 22:52:55 +0300 Subject: [PATCH 20/53] [docs] Add documentation for ZIP custom extra fields related APIs --- Sources/ZIP/ZipContainer.swift | 13 +++++++++++++ Sources/ZIP/ZipEntryInfo.swift | 5 +++++ Sources/ZIP/ZipExtraField.swift | 30 ++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Sources/ZIP/ZipContainer.swift b/Sources/ZIP/ZipContainer.swift index 64072f7b..13141913 100644 --- a/Sources/ZIP/ZipContainer.swift +++ b/Sources/ZIP/ZipContainer.swift @@ -9,6 +9,19 @@ import BitByteData /// Provides functions for work with ZIP containers. public class ZipContainer: Container { + /** + Contains user-defined extra fields. When either `ZipContainer.info(container:)` or `ZipContainer.open(container:)` + function encounters non-standard extra field, it uses this dictionary and tries to find a corresponding + user-defined extra field. If an approriate custom extra field is found and successfully processed, then the result + is stored in `ZipEntryInfo.customExtraFields`. + + To enable support of custom extra field one must add a new entry to this dictionary. The value of this entry must + be a user-defined type which conforms to `ZipExtraField` protocol. The key must be equal to the ID of user-defined + extra field and type's `id` property. + + - Warning: Modifying this dictionary while either `info(container:)` or `open(container:)` function is being + executed may cause undefined behavior. + */ public static var customExtraFields = [UInt16: ZipExtraField.Type]() /** diff --git a/Sources/ZIP/ZipEntryInfo.swift b/Sources/ZIP/ZipEntryInfo.swift index dceab0b5..5ade889e 100644 --- a/Sources/ZIP/ZipEntryInfo.swift +++ b/Sources/ZIP/ZipEntryInfo.swift @@ -92,6 +92,11 @@ public struct ZipEntryInfo: ContainerEntryInfo { */ public let groupID: Int? + /** + Entry's custom extra fields from both Central Directory and Local Header. + + - Note: No particular order of extra fields is guaranteed. + */ public let customExtraFields: [ZipExtraField] let cdEntry: ZipCentralDirectoryEntry diff --git a/Sources/ZIP/ZipExtraField.swift b/Sources/ZIP/ZipExtraField.swift index 95686bd2..ac171be6 100644 --- a/Sources/ZIP/ZipExtraField.swift +++ b/Sources/ZIP/ZipExtraField.swift @@ -5,28 +5,54 @@ import BitByteData +/// A type that represents an extra field from ZIP container. public protocol ZipExtraField { + /** + ID of extra field. Must be equal to the key of extra field in `ZipContainer.customExtraFields` dictionary and + instance `id` property + */ static var id: UInt16 { get } + /// Location of extra field. Must be equal to the value of `location` argument of `init?(_:_:location:)`. var location: ZipExtraFieldLocation { get } + + /// Size of extra field's data. Must be equal to the value of the second argument of `init?(_:_:location:)`. var size: Int { get } + /** + Creates an extra field instance reading `size` amount of data from `byteReader`. + + It is guaranteed that the offset of `byteReader` is equal to the position right after extra field header ID and + length of extra field data. It is also guaranteed that header ID matches conforming type's static `id` property. + + Following conditions are checked after execution of this initializer. Failure to satisfy them in conforming type + will result in runtime error. + + - Postcondition: `location` property of a created instance must be equal to the `location` argument. + - Postcondition: `size` property of a created instance must be equal to the second argument. + - Postcondition: exactly `size` amount of bytes must be read by initializer from `byteReader`. + */ init?(_ byteReader: ByteReader, _ size: Int, location: ZipExtraFieldLocation) } extension ZipExtraField { + /** + ID of extra field. Must be equal to the key of extra field in `ZipContainer.customExtraFields` dictionary and + static `id` property + */ public var id: UInt16 { return Self.id } } +/// Location of ZIP extra field inside a container. public enum ZipExtraFieldLocation { - + /// ZIP extra field is located in container's Central Directory. case centralDirectory + /// ZIP extra field is located in one of container's Local Headers. case localHeader - } From 9293210d3519433ca0d86142d35e8c9727e4e86d Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 31 Mar 2018 13:49:46 +0300 Subject: [PATCH 21/53] All properties in huffman trees are now constant --- Sources/Common/DecodingHuffmanTree.swift | 9 +++++---- Sources/Common/EncodingHuffmanTree.swift | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Sources/Common/DecodingHuffmanTree.swift b/Sources/Common/DecodingHuffmanTree.swift index 2a9ff316..c5052f2d 100644 --- a/Sources/Common/DecodingHuffmanTree.swift +++ b/Sources/Common/DecodingHuffmanTree.swift @@ -8,9 +8,9 @@ import BitByteData class DecodingHuffmanTree { - private var bitReader: BitReader + private let bitReader: BitReader - private var tree: [Int] + private let tree: [Int] private let leafCount: Int /// `lengths` don't have to be properly sorted, but there must not be any 0 code lengths. @@ -22,7 +22,7 @@ class DecodingHuffmanTree { // Calculate maximum amount of leaves possible in a tree. self.leafCount = 1 << (sortedLengths.last!.codeLength + 1) - self.tree = Array(repeating: -1, count: leafCount) + var tree = Array(repeating: -1, count: leafCount) // Calculates symbols for each length in 'sortedLengths' array and put them in the tree. var loopBits = -1 @@ -46,8 +46,9 @@ class DecodingHuffmanTree { index = bit == 0 ? 2 * index + 1 : 2 * index + 2 treeCode >>= 1 } - self.tree[index] = length.symbol + tree[index] = length.symbol } + self.tree = tree } func findNextSymbol() -> Int { diff --git a/Sources/Common/EncodingHuffmanTree.swift b/Sources/Common/EncodingHuffmanTree.swift index 3ad5f1ca..f7bd5627 100644 --- a/Sources/Common/EncodingHuffmanTree.swift +++ b/Sources/Common/EncodingHuffmanTree.swift @@ -8,9 +8,9 @@ import BitByteData class EncodingHuffmanTree { - private var bitWriter: BitWriter + private let bitWriter: BitWriter - private var codingIndices: [[Int]] + private let codingIndices: [[Int]] /// `lengths` don't have to be properly sorted, but there must not be any 0 code lengths. /// If `reverseCodes` is true, then bit order of tree codes will be reversed. Necessary for Deflate. @@ -20,7 +20,7 @@ class EncodingHuffmanTree { // Sort `lengths` array to calculate canonical Huffman code. let sortedLengths = lengths.sorted() - self.codingIndices = Array(repeating: [-1, -1], count: sortedLengths.count) + var codingIndices = Array(repeating: [-1, -1], count: sortedLengths.count) // Calculates symbols for each length in 'sortedLengths' array and put them in the tree. var loopBits = -1 @@ -36,8 +36,9 @@ class EncodingHuffmanTree { } // Then we reverse bit order of the symbol, if necessary. let treeCode = reverseCodes ? symbol.reversed(bits: loopBits) : symbol - self.codingIndices[length.symbol] = [treeCode, bits] + codingIndices[length.symbol] = [treeCode, bits] } + self.codingIndices = codingIndices } func code(symbol: Int) { From 1d838c1d7e7b83c6c7884c1f47094c3f4dea140d Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 7 Apr 2018 12:20:23 +0300 Subject: [PATCH 22/53] Slightly simplify and improve certain code --- Sources/BZip2/BZip2+Compress.swift | 4 ++-- Sources/TAR/ByteReader+Tar.swift | 8 +++----- Sources/TAR/TarExtendedHeader.swift | 4 ++-- Sources/ZIP/ZipEntryInfo.swift | 2 +- Tests/GzipTests.swift | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Sources/BZip2/BZip2+Compress.swift b/Sources/BZip2/BZip2+Compress.swift index 2b64a030..028e9f5c 100644 --- a/Sources/BZip2/BZip2+Compress.swift +++ b/Sources/BZip2/BZip2+Compress.swift @@ -269,9 +269,9 @@ extension BZip2: CompressionAlgorithm { } if (byte == 0 && i == array.count - 1) || byte != 0 { if lengthOfZerosRun > 0 { - let digitsNumber = floor(log2(Double(lengthOfZerosRun) + 1)) + let digitsNumber = Int(floor(log2(Double(lengthOfZerosRun) + 1))) var remainder = lengthOfZerosRun - for _ in 0.. Date: Sat, 7 Apr 2018 13:24:37 +0300 Subject: [PATCH 23/53] [TAR] Add entry info provider --- SWCompression.xcodeproj/project.pbxproj | 4 ++ Sources/TAR/TarEntryInfoProvider.swift | 59 +++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Sources/TAR/TarEntryInfoProvider.swift diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 63e79828..dd797a5d 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 06CDFCA81F111D9700292758 /* DeflateError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CDFCA71F111D9700292758 /* DeflateError.swift */; }; 06CDFCAD1F111DBE00292758 /* LZMAError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CDFCAC1F111DBE00292758 /* LZMAError.swift */; }; 06CDFCB21F111DEC00292758 /* LZMA2Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CDFCB11F111DEC00292758 /* LZMA2Error.swift */; }; + 06CFF6B22078C5A5003B8375 /* TarEntryInfoProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06CFF6B12078C5A5003B8375 /* TarEntryInfoProvider.swift */; }; 06D42DA52067B46800C1A98B /* test_custom_extra_field.zip in Resources */ = {isa = PBXBuildFile; fileRef = 06D42DA42067B46800C1A98B /* test_custom_extra_field.zip */; }; 06D42DA72067B71000C1A98B /* TestZipExtraField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06D42DA62067B71000C1A98B /* TestZipExtraField.swift */; }; 06D95AC11F4C54E0006B46AC /* BZip2+Compress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06D95AC01F4C54E0006B46AC /* BZip2+Compress.swift */; }; @@ -286,6 +287,7 @@ 06CDFCA71F111D9700292758 /* DeflateError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeflateError.swift; sourceTree = ""; }; 06CDFCAC1F111DBE00292758 /* LZMAError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LZMAError.swift; sourceTree = ""; }; 06CDFCB11F111DEC00292758 /* LZMA2Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LZMA2Error.swift; sourceTree = ""; }; + 06CFF6B12078C5A5003B8375 /* TarEntryInfoProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TarEntryInfoProvider.swift; sourceTree = ""; }; 06D42DA42067B46800C1A98B /* test_custom_extra_field.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = test_custom_extra_field.zip; sourceTree = ""; }; 06D42DA62067B71000C1A98B /* TestZipExtraField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestZipExtraField.swift; sourceTree = ""; }; 06D95AC01F4C54E0006B46AC /* BZip2+Compress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BZip2+Compress.swift"; sourceTree = ""; }; @@ -592,6 +594,7 @@ 061C06561F0E90C800832F0C /* TarError.swift */, 0651FEC11F8E2E9100C49646 /* ContainerEntryType+Tar.swift */, 0656B82A1F8A979A00111605 /* ByteReader+Tar.swift */, + 06CFF6B12078C5A5003B8375 /* TarEntryInfoProvider.swift */, ); path = TAR; sourceTree = ""; @@ -1078,6 +1081,7 @@ 0686A6451FA4C47300E89C9E /* FileSystemType+Zip.swift in Sources */, 06CDFCA31F111D6C00292758 /* BZip2Error.swift in Sources */, 06393DF51F1A7F8E00A647A0 /* ZipString.swift in Sources */, + 06CFF6B22078C5A5003B8375 /* TarEntryInfoProvider.swift in Sources */, 06CC3FE21F8AAF3100BD576D /* ByteReader+XZ.swift in Sources */, 065D0ADC1F2B9D9100CE2DA8 /* 7zEntryInfo.swift in Sources */, 06F276DF1F2BAB4A00E67335 /* 7zEntry.swift in Sources */, diff --git a/Sources/TAR/TarEntryInfoProvider.swift b/Sources/TAR/TarEntryInfoProvider.swift new file mode 100644 index 00000000..0c68b832 --- /dev/null +++ b/Sources/TAR/TarEntryInfoProvider.swift @@ -0,0 +1,59 @@ +// Copyright (c) 2018 Timofey Solomko +// Licensed under MIT License +// +// See LICENSE for license information + +import Foundation +import BitByteData + +// While it is tempting to make Provider conform to `IteratorProtocol` and `Sequence` protocols, it is in fact +// impossible to do so, since `TarEntryInfo.init(...)` is throwing and `IteratorProtocol.next()` cannot be throwing. +// TODO: Struct or class? +struct TarEntryInfoProvider { + + private let byteReader: ByteReader + private var lastGlobalExtendedHeader: TarExtendedHeader? + private var lastLocalExtendedHeader: TarExtendedHeader? + private var longLinkName: String? + private var longName: String? + + init(_ data: Data) { + self.byteReader = ByteReader(data: data) + } + + mutating func next() throws -> TarEntryInfo? { + // TODO: Check, if bytes left is >= 1024. + guard byteReader.data[byteReader.offset.. Date: Sat, 7 Apr 2018 13:24:55 +0300 Subject: [PATCH 24/53] [TAR] Use info provider in info function --- Sources/TAR/TarContainer.swift | 45 ++++------------------------------ 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index c8e57fd9..219c40f4 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -59,48 +59,13 @@ public class TarContainer: Container { guard data.count >= 512 else { throw TarError.tooSmallFileIsPassed } /// Object with input data which supports convenient work with bit shifts. - let byteReader = ByteReader(data: data) - + var infoProvider = TarEntryInfoProvider(data) var entries = [TarEntryInfo]() - var lastGlobalExtendedHeader: TarExtendedHeader? - var lastLocalExtendedHeader: TarExtendedHeader? - var longLinkName: String? - var longName: String? - - // Container ends with two zero-filled records. - while byteReader.data[byteReader.offset.. Date: Tue, 10 Apr 2018 00:17:36 +0300 Subject: [PATCH 25/53] [swcomp] Updates to support SwiftCLI 4.2.0 and higher --- Package.swift | 2 +- Sources/swcomp/Extensions/BlockSize+Keyable.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index b096f43d..eaa8c40b 100644 --- a/Package.swift +++ b/Package.swift @@ -11,7 +11,7 @@ let package = Package( dependencies: [ // SWCOMP: Uncomment the line below to build swcomp example program. // .package(url: "https://github.com/jakeheis/SwiftCLI", - // from: "4.0.0"), + // from: "4.2.0"), .package(url: "https://github.com/tsolomko/BitByteData", from: "1.1.0"), ], diff --git a/Sources/swcomp/Extensions/BlockSize+Keyable.swift b/Sources/swcomp/Extensions/BlockSize+Keyable.swift index 6a8030ba..e6e08e6f 100644 --- a/Sources/swcomp/Extensions/BlockSize+Keyable.swift +++ b/Sources/swcomp/Extensions/BlockSize+Keyable.swift @@ -8,9 +8,9 @@ import SwiftCLI import SWCompression /// This extension allows to use `BlockSize` as a `Key` option. -extension BZip2.BlockSize: Keyable { +extension BZip2.BlockSize: ConvertibleFromString { - public static func val(from: String) -> BZip2.BlockSize? { + public static func convert(from: String) -> BZip2.BlockSize? { guard let num = Int(from) else { return nil } return BZip2.BlockSize(rawValue: num) From 44582535adb4069f835db9b28f5640fd5ea711d8 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 10 Apr 2018 00:19:10 +0300 Subject: [PATCH 26/53] [Benchmark] Increase iterations amount from 6 to 10 --- Sources/swcomp/Benchmarks/CompBz2.swift | 4 ++-- Sources/swcomp/Benchmarks/CompDeflate.swift | 4 ++-- Sources/swcomp/Benchmarks/Info7z.swift | 4 ++-- Sources/swcomp/Benchmarks/InfoTar.swift | 4 ++-- Sources/swcomp/Benchmarks/InfoZip.swift | 4 ++-- Sources/swcomp/Benchmarks/UnBz2.swift | 4 ++-- Sources/swcomp/Benchmarks/UnGzip.swift | 4 ++-- Sources/swcomp/Benchmarks/UnXz.swift | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/swcomp/Benchmarks/CompBz2.swift b/Sources/swcomp/Benchmarks/CompBz2.swift index 7f1f543f..0c64a616 100644 --- a/Sources/swcomp/Benchmarks/CompBz2.swift +++ b/Sources/swcomp/Benchmarks/CompBz2.swift @@ -33,7 +33,7 @@ class CompBz2: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = BZip2.compress(data: fileData) @@ -47,7 +47,7 @@ class CompBz2: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("-----------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/CompDeflate.swift b/Sources/swcomp/Benchmarks/CompDeflate.swift index 0b535d4c..08e97051 100644 --- a/Sources/swcomp/Benchmarks/CompDeflate.swift +++ b/Sources/swcomp/Benchmarks/CompDeflate.swift @@ -33,7 +33,7 @@ class CompDeflate: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = Deflate.compress(data: fileData) @@ -47,7 +47,7 @@ class CompDeflate: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("----------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/Info7z.swift b/Sources/swcomp/Benchmarks/Info7z.swift index 87e7230b..5dd915bb 100644 --- a/Sources/swcomp/Benchmarks/Info7z.swift +++ b/Sources/swcomp/Benchmarks/Info7z.swift @@ -33,7 +33,7 @@ class Info7z: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = try SevenZipContainer.info(container: fileData) @@ -47,7 +47,7 @@ class Info7z: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("---------------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/InfoTar.swift b/Sources/swcomp/Benchmarks/InfoTar.swift index 7c46d581..84ff9b71 100644 --- a/Sources/swcomp/Benchmarks/InfoTar.swift +++ b/Sources/swcomp/Benchmarks/InfoTar.swift @@ -33,7 +33,7 @@ class InfoTar: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = try TarContainer.info(container: fileData) @@ -47,7 +47,7 @@ class InfoTar: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("-------------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/InfoZip.swift b/Sources/swcomp/Benchmarks/InfoZip.swift index 7b0d450f..5077ec2b 100644 --- a/Sources/swcomp/Benchmarks/InfoZip.swift +++ b/Sources/swcomp/Benchmarks/InfoZip.swift @@ -33,7 +33,7 @@ class InfoZip: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = try ZipContainer.info(container: fileData) @@ -47,7 +47,7 @@ class InfoZip: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("-------------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/UnBz2.swift b/Sources/swcomp/Benchmarks/UnBz2.swift index a2ce4b9d..e985cf3e 100644 --- a/Sources/swcomp/Benchmarks/UnBz2.swift +++ b/Sources/swcomp/Benchmarks/UnBz2.swift @@ -33,7 +33,7 @@ class UnBz2: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = try BZip2.decompress(data: fileData) @@ -47,7 +47,7 @@ class UnBz2: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("-----------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/UnGzip.swift b/Sources/swcomp/Benchmarks/UnGzip.swift index 23f557e9..087f1496 100644 --- a/Sources/swcomp/Benchmarks/UnGzip.swift +++ b/Sources/swcomp/Benchmarks/UnGzip.swift @@ -33,7 +33,7 @@ class UnGzip: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = try GzipArchive.unarchive(archive: fileData) @@ -47,7 +47,7 @@ class UnGzip: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("----------------------------------") } } diff --git a/Sources/swcomp/Benchmarks/UnXz.swift b/Sources/swcomp/Benchmarks/UnXz.swift index 96d2ddd9..6835a928 100644 --- a/Sources/swcomp/Benchmarks/UnXz.swift +++ b/Sources/swcomp/Benchmarks/UnXz.swift @@ -33,7 +33,7 @@ class UnXz: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) - for i in 1...6 { + for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() _ = try XZArchive.unarchive(archive: fileData) @@ -47,7 +47,7 @@ class UnXz: Command { minTime = timeElapsed } } - print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 6, (maxTime - minTime) / 2)) + print(String(format: "\nAverage time: %.3f \u{B1} %.3f", totalTime / 10, (maxTime - minTime) / 2)) print("--------------------------------") } } From bd8fa0561af6380f2ca4cb5e745489baebf232cf Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 10 Apr 2018 00:21:26 +0300 Subject: [PATCH 27/53] [Benchmark] Don't take into account "first" iteration --- Sources/swcomp/Benchmarks/CompBz2.swift | 1 + Sources/swcomp/Benchmarks/CompDeflate.swift | 1 + Sources/swcomp/Benchmarks/Info7z.swift | 1 + Sources/swcomp/Benchmarks/InfoTar.swift | 1 + Sources/swcomp/Benchmarks/InfoZip.swift | 1 + Sources/swcomp/Benchmarks/UnBz2.swift | 1 + Sources/swcomp/Benchmarks/UnGzip.swift | 1 + Sources/swcomp/Benchmarks/UnXz.swift | 1 + 8 files changed, 8 insertions(+) diff --git a/Sources/swcomp/Benchmarks/CompBz2.swift b/Sources/swcomp/Benchmarks/CompBz2.swift index 0c64a616..8d4667ec 100644 --- a/Sources/swcomp/Benchmarks/CompBz2.swift +++ b/Sources/swcomp/Benchmarks/CompBz2.swift @@ -33,6 +33,7 @@ class CompBz2: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = BZip2.compress(data: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/CompDeflate.swift b/Sources/swcomp/Benchmarks/CompDeflate.swift index 08e97051..5fba6ad4 100644 --- a/Sources/swcomp/Benchmarks/CompDeflate.swift +++ b/Sources/swcomp/Benchmarks/CompDeflate.swift @@ -33,6 +33,7 @@ class CompDeflate: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = Deflate.compress(data: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/Info7z.swift b/Sources/swcomp/Benchmarks/Info7z.swift index 5dd915bb..a315926d 100644 --- a/Sources/swcomp/Benchmarks/Info7z.swift +++ b/Sources/swcomp/Benchmarks/Info7z.swift @@ -33,6 +33,7 @@ class Info7z: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = try SevenZipContainer.info(container: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/InfoTar.swift b/Sources/swcomp/Benchmarks/InfoTar.swift index 84ff9b71..89852bf9 100644 --- a/Sources/swcomp/Benchmarks/InfoTar.swift +++ b/Sources/swcomp/Benchmarks/InfoTar.swift @@ -33,6 +33,7 @@ class InfoTar: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = try TarContainer.info(container: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/InfoZip.swift b/Sources/swcomp/Benchmarks/InfoZip.swift index 5077ec2b..53a12eb8 100644 --- a/Sources/swcomp/Benchmarks/InfoZip.swift +++ b/Sources/swcomp/Benchmarks/InfoZip.swift @@ -33,6 +33,7 @@ class InfoZip: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = try ZipContainer.info(container: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/UnBz2.swift b/Sources/swcomp/Benchmarks/UnBz2.swift index e985cf3e..3a4c8788 100644 --- a/Sources/swcomp/Benchmarks/UnBz2.swift +++ b/Sources/swcomp/Benchmarks/UnBz2.swift @@ -33,6 +33,7 @@ class UnBz2: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = try BZip2.decompress(data: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/UnGzip.swift b/Sources/swcomp/Benchmarks/UnGzip.swift index 087f1496..8639aa06 100644 --- a/Sources/swcomp/Benchmarks/UnGzip.swift +++ b/Sources/swcomp/Benchmarks/UnGzip.swift @@ -33,6 +33,7 @@ class UnGzip: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = try GzipArchive.unarchive(archive: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() diff --git a/Sources/swcomp/Benchmarks/UnXz.swift b/Sources/swcomp/Benchmarks/UnXz.swift index 6835a928..5b797f6d 100644 --- a/Sources/swcomp/Benchmarks/UnXz.swift +++ b/Sources/swcomp/Benchmarks/UnXz.swift @@ -33,6 +33,7 @@ class UnXz: Command { var maxTime = Double(Int.min) var minTime = Double(Int.max) + _ = try XZArchive.unarchive(archive: fileData) for i in 1...10 { print("Iteration \(i): ", terminator: "") let startTime = CFAbsoluteTimeGetCurrent() From 1452f685cb73484bfc58eb470804504ea32d0238 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Wed, 14 Mar 2018 14:46:53 +0300 Subject: [PATCH 28/53] Use test release of BBD 1.2.0 --- Cartfile | 2 +- Package.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cartfile b/Cartfile index ca433536..02555728 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "tsolomko/BitByteData" ~> 1.1 +github "tsolomko/BitByteData" "1.2.0-test.3" diff --git a/Package.swift b/Package.swift index eaa8c40b..805d1fee 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( // .package(url: "https://github.com/jakeheis/SwiftCLI", // from: "4.2.0"), .package(url: "https://github.com/tsolomko/BitByteData", - from: "1.1.0"), + from: "1.2.0-test"), ], targets: [ // SWCOMP: Uncomment the lines below to build swcomp example program. From 05852b179bb619beac2daf2def9bf129d8fceff8 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 17 Mar 2018 15:26:18 +0300 Subject: [PATCH 29/53] Use new int(fromBytes:) function --- Sources/7-Zip/7zContainer.swift | 4 ++-- Sources/LZMA/LZMA.swift | 2 +- Sources/XZ/XZArchive.swift | 4 ++-- Sources/ZIP/StandardExtraFields.swift | 18 ++++-------------- Sources/ZIP/ZipCentralDirectoryEntry.swift | 8 ++++---- Sources/ZIP/ZipContainer.swift | 2 +- Sources/ZIP/ZipEndOfCentralDirectory.swift | 2 +- Sources/ZIP/ZipLocalHeader.swift | 6 +++--- 8 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Sources/7-Zip/7zContainer.swift b/Sources/7-Zip/7zContainer.swift index 7d53cae9..22a0fcad 100644 --- a/Sources/7-Zip/7zContainer.swift +++ b/Sources/7-Zip/7zContainer.swift @@ -218,8 +218,8 @@ public class SevenZipContainer: Container { let startHeaderCRC = bitReader.uint32() /// - Note: Relative to SignatureHeader - let nextHeaderOffset = bitReader.uint64().toInt() - let nextHeaderSize = bitReader.uint64().toInt() + let nextHeaderOffset = bitReader.int(fromBytes: 8) + let nextHeaderSize = bitReader.int(fromBytes: 8) let nextHeaderCRC = bitReader.uint32() bitReader.offset = 12 diff --git a/Sources/LZMA/LZMA.swift b/Sources/LZMA/LZMA.swift index 0ace6881..a4b3c4ab 100644 --- a/Sources/LZMA/LZMA.swift +++ b/Sources/LZMA/LZMA.swift @@ -29,7 +29,7 @@ public class LZMA: DecompressionAlgorithm { try decoder.setProperties(byteReader.byte()) decoder.resetStateAndDecoders() - decoder.dictionarySize = byteReader.uint32().toInt() + decoder.dictionarySize = byteReader.int(fromBytes: 4) let uncompSize = uncompressedSize ?? byteReader.uint64() if uncompSize == UInt64.max { diff --git a/Sources/XZ/XZArchive.swift b/Sources/XZ/XZArchive.swift index 2ae25292..7e8b945d 100644 --- a/Sources/XZ/XZArchive.swift +++ b/Sources/XZ/XZArchive.swift @@ -160,8 +160,8 @@ public class XZArchive: Archive { _ byteReader: ByteReader) throws { let footerCRC = byteReader.uint32() /// Indicates the size of Index field. Should match its real size. - let backwardSize = (byteReader.uint32().toInt() + 1) * 4 - let streamFooterFlags = byteReader.uint16().toInt() + let backwardSize = (byteReader.int(fromBytes: 4) + 1) * 4 + let streamFooterFlags = byteReader.int(fromBytes: 2) byteReader.offset -= 6 guard CheckSums.crc32(byteReader.bytes(count: 6)) == footerCRC diff --git a/Sources/ZIP/StandardExtraFields.swift b/Sources/ZIP/StandardExtraFields.swift index 037384ef..4b3e33e1 100644 --- a/Sources/ZIP/StandardExtraFields.swift +++ b/Sources/ZIP/StandardExtraFields.swift @@ -84,8 +84,8 @@ struct InfoZipUnixExtraField: ZipExtraField { case .centralDirectory: return nil case .localHeader: - self.uid = byteReader.uint16().toInt() - self.gid = byteReader.uint16().toInt() + self.uid = byteReader.int(fromBytes: 2) + self.gid = byteReader.int(fromBytes: 2) } } @@ -111,24 +111,14 @@ struct InfoZipNewUnixExtraField: ZipExtraField { if uidSize > 8 { byteReader.offset += uidSize } else { - var uid = 0 - for i in 0.. 8 { byteReader.offset += gidSize } else { - var gid = 0 - for i in 0.. Date: Sat, 17 Mar 2018 15:26:32 +0300 Subject: [PATCH 30/53] Use new uint64(fromBits) function --- Sources/BZip2/BZip2.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/BZip2/BZip2.swift b/Sources/BZip2/BZip2.swift index 2c0aa5d8..6fbdfc26 100644 --- a/Sources/BZip2/BZip2.swift +++ b/Sources/BZip2/BZip2.swift @@ -41,9 +41,9 @@ public class BZip2: DecompressionAlgorithm { var totalCRC: UInt32 = 0 while true { // Using `Int64` because 48 bits may not fit into `Int` on some platforms. - let blockType = Int64(bitReader.int(fromBits: 48)) + let blockType = bitReader.uint64(fromBits: 48) - let blockCRC32 = UInt32(truncatingIfNeeded: bitReader.int(fromBits: 32)) + let blockCRC32 = bitReader.uint32(fromBits: 32) if blockType == 0x314159265359 { let blockData = try decode(bitReader, blockSize) From d5c86001372816ae6ffcc5d6ca12da02098b007b Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 17 Mar 2018 15:54:57 +0300 Subject: [PATCH 31/53] Use more new BBD functions --- Sources/7-Zip/7zContainer.swift | 2 +- Sources/GZip/GzipArchive.swift | 2 +- Sources/LZMA2/LZMA2Decoder.swift | 6 +++--- Sources/ZIP/ZipCentralDirectoryEntry.swift | 8 ++++---- Sources/ZIP/ZipContainer.swift | 4 ++-- Sources/ZIP/ZipEndOfCentralDirectory.swift | 16 ++++++++-------- Sources/ZIP/ZipLocalHeader.swift | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Sources/7-Zip/7zContainer.swift b/Sources/7-Zip/7zContainer.swift index 22a0fcad..09d9c1fb 100644 --- a/Sources/7-Zip/7zContainer.swift +++ b/Sources/7-Zip/7zContainer.swift @@ -120,7 +120,7 @@ public class SevenZipContainer: Container { let fileSize = substreamInfo.unpackSizes[nonEmptyFileIndex] // Check, if we aren't about to read too much from a stream. - guard unpackedStreamData.offset + fileSize <= unpackedStreamData.data.endIndex + guard fileSize <= unpackedStreamData.bytesLeft else { throw SevenZipError.internalStructureError } let fileData = Data(bytes: unpackedStreamData.bytes(count: fileSize)) diff --git a/Sources/GZip/GzipArchive.swift b/Sources/GZip/GzipArchive.swift index 6703e58f..76981b62 100644 --- a/Sources/GZip/GzipArchive.swift +++ b/Sources/GZip/GzipArchive.swift @@ -83,7 +83,7 @@ public class GzipArchive: Archive { bitReader.align() let crc32 = bitReader.uint32() - let isize = UInt64(truncatingIfNeeded: bitReader.uint32()) + let isize = bitReader.uint64(fromBytes: 4) guard UInt64(truncatingIfNeeded: memberData.count) % (UInt64(truncatingIfNeeded: 1) << 32) == isize else { throw GzipError.wrongISize } diff --git a/Sources/LZMA2/LZMA2Decoder.swift b/Sources/LZMA2/LZMA2Decoder.swift index 6fc08f34..b1c41884 100644 --- a/Sources/LZMA2/LZMA2Decoder.swift +++ b/Sources/LZMA2/LZMA2Decoder.swift @@ -23,7 +23,7 @@ class LZMA2Decoder { func setDictionarySize(_ byte: UInt8) throws { guard byte & 0xC0 == 0 else { throw LZMA2Error.wrongDictionarySize } - let bits = byte & 0x3F + let bits = (byte & 0x3F).toInt() guard bits < 40 else { throw LZMA2Error.wrongDictionarySize } @@ -31,8 +31,8 @@ class LZMA2Decoder { if bits == 40 { dictSize = UInt32.max } else { - dictSize = UInt32(2 | (bits.toInt() & 1)) - dictSize <<= UInt32(bits.toInt() / 2 + 11) + dictSize = UInt32(truncatingIfNeeded: 2 | (bits & 1)) + dictSize <<= UInt32(truncatingIfNeeded: bits / 2 + 11) } self.decoder.dictionarySize = dictSize.toInt() diff --git a/Sources/ZIP/ZipCentralDirectoryEntry.swift b/Sources/ZIP/ZipCentralDirectoryEntry.swift index d7b8a477..e620b1bb 100644 --- a/Sources/ZIP/ZipCentralDirectoryEntry.swift +++ b/Sources/ZIP/ZipCentralDirectoryEntry.swift @@ -61,19 +61,19 @@ struct ZipCentralDirectoryEntry { self.crc32 = byteReader.uint32() - self.compSize = UInt64(truncatingIfNeeded: byteReader.uint32()) - self.uncompSize = UInt64(truncatingIfNeeded: byteReader.uint32()) + self.compSize = byteReader.uint64(fromBytes: 4) + self.uncompSize = byteReader.uint64(fromBytes: 4) let fileNameLength = byteReader.int(fromBytes: 2) let extraFieldLength = byteReader.int(fromBytes: 2) let fileCommentLength = byteReader.int(fromBytes: 2) - self.diskNumberStart = UInt32(truncatingIfNeeded: byteReader.uint16()) + self.diskNumberStart = byteReader.uint32(fromBytes: 2) self.internalFileAttributes = byteReader.uint16() self.externalFileAttributes = byteReader.uint32() - self.localHeaderOffset = UInt64(truncatingIfNeeded: byteReader.uint32()) + self.localHeaderOffset = byteReader.uint64(fromBytes: 4) guard let fileName = byteReader.getZipStringField(fileNameLength, useUtf8) else { throw ZipError.wrongTextField } diff --git a/Sources/ZIP/ZipContainer.swift b/Sources/ZIP/ZipContainer.swift index 909e63a2..d074f3ec 100644 --- a/Sources/ZIP/ZipContainer.swift +++ b/Sources/ZIP/ZipContainer.swift @@ -115,8 +115,8 @@ public class ZipContainer: Container { compSize = byteReader.uint64() uncompSize = byteReader.uint64() } else { - compSize = UInt64(truncatingIfNeeded: byteReader.uint32()) - uncompSize = UInt64(truncatingIfNeeded: byteReader.uint32()) + compSize = byteReader.uint64(fromBytes: 4) + uncompSize = byteReader.uint64(fromBytes: 4) } } diff --git a/Sources/ZIP/ZipEndOfCentralDirectory.swift b/Sources/ZIP/ZipEndOfCentralDirectory.swift index 5c5b0566..24be9280 100644 --- a/Sources/ZIP/ZipEndOfCentralDirectory.swift +++ b/Sources/ZIP/ZipEndOfCentralDirectory.swift @@ -21,22 +21,22 @@ struct ZipEndOfCentralDirectory { /// Indicates if Zip64 records should be present. var zip64RecordExists = false - self.currentDiskNumber = UInt32(truncatingIfNeeded: byteReader.uint16()) - self.cdDiskNumber = UInt32(truncatingIfNeeded: byteReader.uint16()) + self.currentDiskNumber = byteReader.uint32(fromBytes: 2) + self.cdDiskNumber = byteReader.uint32(fromBytes: 2) guard self.currentDiskNumber == self.cdDiskNumber else { throw ZipError.multiVolumesNotSupported } /// Number of CD entries on the current disk. - var cdEntriesCurrentDisk = UInt64(truncatingIfNeeded: byteReader.uint16()) + var cdEntriesCurrentDisk = byteReader.uint64(fromBytes: 2) /// Total number of CD entries. - self.cdEntries = UInt64(truncatingIfNeeded: byteReader.uint16()) + self.cdEntries = byteReader.uint64(fromBytes: 2) guard cdEntries == cdEntriesCurrentDisk else { throw ZipError.multiVolumesNotSupported } /// Size of Central Directory. - self.cdSize = UInt64(truncatingIfNeeded: byteReader.uint32()) + self.cdSize = byteReader.uint64(fromBytes: 4) /// Offset to the start of Central Directory. - self.cdOffset = UInt64(truncatingIfNeeded: byteReader.uint32()) + self.cdOffset = byteReader.uint64(fromBytes: 4) // There is also a .ZIP file comment, but we don't need it. // Here's how it can be processed: @@ -65,13 +65,13 @@ struct ZipEndOfCentralDirectory { guard self.currentDiskNumber == zip64CDStartDisk else { throw ZipError.multiVolumesNotSupported } - let zip64CDEndOffset = byteReader.uint64() + let zip64CDEndOffset = byteReader.int(fromBytes: 8) let totalDisks = byteReader.uint32() guard totalDisks == 1 else { throw ZipError.multiVolumesNotSupported } // Now we need to move to Zip64 End of CD. - byteReader.offset = zip64CDEndOffset.toInt() + byteReader.offset = zip64CDEndOffset // Check signature. guard byteReader.uint32() == 0x06064b50 diff --git a/Sources/ZIP/ZipLocalHeader.swift b/Sources/ZIP/ZipLocalHeader.swift index b6ab79b1..fa96ef7a 100644 --- a/Sources/ZIP/ZipLocalHeader.swift +++ b/Sources/ZIP/ZipLocalHeader.swift @@ -55,8 +55,8 @@ struct ZipLocalHeader { self.crc32 = byteReader.uint32() - self.compSize = UInt64(truncatingIfNeeded: byteReader.uint32()) - self.uncompSize = UInt64(truncatingIfNeeded: byteReader.uint32()) + self.compSize = byteReader.uint64(fromBytes: 4) + self.uncompSize = byteReader.uint64(fromBytes: 4) let fileNameLength = byteReader.int(fromBytes: 2) let extraFieldLength = byteReader.int(fromBytes: 2) From adb8f485708fe63d566898caf1b460d472c282a6 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 10 Apr 2018 23:21:32 +0300 Subject: [PATCH 32/53] Exclude Carthage directory from linting --- .swiftlint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.swiftlint.yml b/.swiftlint.yml index d750ba04..c9df412d 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,6 +1,7 @@ excluded: - .build/ - Package.swift + - Carthage/ disabled_rules: - cyclomatic_complexity - file_length From a0ef7a3cfed8e1e311a633d8ce4ec5021c8e5e5b Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 10 Apr 2018 23:22:31 +0300 Subject: [PATCH 33/53] Swiftlinted --- Sources/7-Zip/7zFolder.swift | 2 +- Sources/ZIP/ZipLocalHeader.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/7-Zip/7zFolder.swift b/Sources/7-Zip/7zFolder.swift index 79ff0f04..b332b4d2 100644 --- a/Sources/7-Zip/7zFolder.swift +++ b/Sources/7-Zip/7zFolder.swift @@ -40,7 +40,7 @@ class SevenZipFolder { var numUnpackSubstreams = 1 lazy var orderedCompressionMethods: [CompressionMethod] = { - return self.orderedCoders().map { $0.compressionMethod } + self.orderedCoders().map { $0.compressionMethod } }() init(_ bitReader: MsbBitReader) throws { diff --git a/Sources/ZIP/ZipLocalHeader.swift b/Sources/ZIP/ZipLocalHeader.swift index fa96ef7a..e927a6bb 100644 --- a/Sources/ZIP/ZipLocalHeader.swift +++ b/Sources/ZIP/ZipLocalHeader.swift @@ -92,7 +92,7 @@ struct ZipLocalHeader { if let customExtraFieldType = ZipContainer.customExtraFields[headerID], customExtraFieldType.id == headerID, let customExtraField = customExtraFieldType.init(byteReader, size, location: .localHeader), - customExtraField.id == headerID { + customExtraField.id == headerID { precondition(customExtraField.location == .localHeader, "Custom field in Local Header with ID=\(headerID) of type=\(customExtraFieldType)" + " changed location.") From 41ca39d1fa680cf6a9b57e23107c0d83bbda2a54 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 10 Apr 2018 23:26:35 +0300 Subject: [PATCH 34/53] Remove certain TODOs --- Sources/TAR/TarEntryInfoProvider.swift | 5 ++--- Sources/ZIP/ZipLocalHeader.swift | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/TAR/TarEntryInfoProvider.swift b/Sources/TAR/TarEntryInfoProvider.swift index 0c68b832..fee3d5de 100644 --- a/Sources/TAR/TarEntryInfoProvider.swift +++ b/Sources/TAR/TarEntryInfoProvider.swift @@ -8,7 +8,6 @@ import BitByteData // While it is tempting to make Provider conform to `IteratorProtocol` and `Sequence` protocols, it is in fact // impossible to do so, since `TarEntryInfo.init(...)` is throwing and `IteratorProtocol.next()` cannot be throwing. -// TODO: Struct or class? struct TarEntryInfoProvider { private let byteReader: ByteReader @@ -22,8 +21,8 @@ struct TarEntryInfoProvider { } mutating func next() throws -> TarEntryInfo? { - // TODO: Check, if bytes left is >= 1024. - guard byteReader.data[byteReader.offset..= 1024, + byteReader.data[byteReader.offset.. Date: Wed, 11 Apr 2018 00:32:54 +0300 Subject: [PATCH 35/53] Use 4.3 version in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 17d230e5..ad77dd44 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ let package = Package( name: "PackageName", dependencies: [ .package(url: "https://github.com/tsolomko/SWCompression.git", - from: "4.2.0") + from: "4.3.0") ], targets: [ .target( @@ -66,7 +66,7 @@ More details you can find in [Swift Package Manager's Documentation](https://git ### CocoaPods -Add `pod 'SWCompression', '~> 4.2'` and `use_frameworks!` to your Podfile. +Add `pod 'SWCompression', '~> 4.3'` and `use_frameworks!` to your Podfile. To complete installation, run `pod install`. @@ -112,7 +112,7 @@ __Note:__ If you use Swift Package Manager or Carthage you always have everythin ### Carthage -Add to your Cartfile `github "tsolomko/SWCompression" ~> 4.2`. +Add to your Cartfile `github "tsolomko/SWCompression" ~> 4.3`. Then run `carthage update`. From 156f0a05166d362a44b0ada3a899d43c2358fef1 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Wed, 11 Apr 2018 00:43:08 +0300 Subject: [PATCH 36/53] Prepare for first test release of 4.3.0 --- .jazzy.yaml | 4 ++-- CHANGELOG.md | 17 +++++++++++++++++ SWCompression.podspec | 4 ++-- SWCompression.xcodeproj/SWCompression.plist | 4 ++-- SWCompression.xcodeproj/TestSWCompression.plist | 4 ++-- SWCompression.xcodeproj/project.pbxproj | 8 ++++---- Sources/swcomp/main.swift | 2 +- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.jazzy.yaml b/.jazzy.yaml index db7d4de5..bab8bf6b 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -3,11 +3,11 @@ sourcekitten_sourcefile: docs.json clean: true author: Timofey Solomko module: SWCompression -module_version: 4.2.2 +module_version: 4.3.0-test.1 copyright: '© 2018 Timofey Solomko' readme: README.md github_url: https://github.com/tsolomko/SWCompression -github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.2.2 +github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.3.0-test.1 theme: fullwidth custom_categories: diff --git a/CHANGELOG.md b/CHANGELOG.md index dddbb2e9..58d2419f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## 4.3.0 + +### Test 1 + +- Updated to support Swift 4.1. +- Minuimum required version of BitByteData is now 1.2.0-test.3. +- Added APIs to enable support of custom ZIP Extra Fields. + - Added `ZipExtraField` protocol. + - Added `ZipExtraFieldLocation` enum. + - Added `ZipContainer.customExtraFields` property. + - Added `ZipEntryInfo.customExtraFields` property. +- Added `TarEntryInfo.compressionMethod` property which is always equal to `.copy`. +- Reverted "disable symbol stripping" change from 4.2.0 update, since underlying problem was fixed in Carthage. +- Benchmarks changes: + - Iterations number increased from 6 to 10. + - There is now a zeroth iteration which is excluded from averages. + ## 4.2.2 - Fixed skipping entries in `SevenZipContainer.open(container:)` in some rare cases. diff --git a/SWCompression.podspec b/SWCompression.podspec index 0a68532f..4f53c122 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SWCompression" - s.version = "4.2.2" + s.version = "4.3.0-test.1" s.summary = "A framework with functions for working with compression, archives and containers." s.description = "A framework with (de)compression algorithms and functions for processing various archives and containers." @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.swift_version = "4.1" - s.dependency "BitByteData", "~> 1.1" + s.dependency "BitByteData", "~> 1.2.0-test.3" s.subspec "Deflate" do |sp| sp.source_files = "Sources/{Deflate/*,Common/*}.swift" diff --git a/SWCompression.xcodeproj/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist index 328506ea..4f4168aa 100644 --- a/SWCompression.xcodeproj/SWCompression.plist +++ b/SWCompression.xcodeproj/SWCompression.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.2.2 + 4.3.0-test.1 CFBundleVersion - 59 + 60 NSHumanReadableCopyright Copyright © 2018 Timofey Solomko. All rights reserved. diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist index 8b00954d..f69d89da 100644 --- a/SWCompression.xcodeproj/TestSWCompression.plist +++ b/SWCompression.xcodeproj/TestSWCompression.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 4.2.2 + 4.3.0-test.1 CFBundleVersion - 59 + 60 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index dd797a5d..bb4480ac 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1163,7 +1163,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 59; + CURRENT_PROJECT_VERSION = 60; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1220,7 +1220,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 59; + CURRENT_PROJECT_VERSION = 60; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; @@ -1258,7 +1258,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 59; + DYLIB_CURRENT_VERSION = 60; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -1286,7 +1286,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 59; + DYLIB_CURRENT_VERSION = 60; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Sources/swcomp/main.swift b/Sources/swcomp/main.swift index 5634f3eb..5517add8 100644 --- a/Sources/swcomp/main.swift +++ b/Sources/swcomp/main.swift @@ -7,7 +7,7 @@ import Foundation import SWCompression import SwiftCLI -let cli = CLI(name: "swcomp", version: "4.2.2", +let cli = CLI(name: "swcomp", version: "4.3.0-test.1", description: """ swcomp - small command-line client for SWCompression framework. Serves as an example of SWCompression usage. From 58d96a19615a52901cebe71560f562a8dbdd59b4 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 30 Mar 2018 23:04:42 +0300 Subject: [PATCH 37/53] [TAR] Add Format enum --- Sources/TAR/TarContainer.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index 219c40f4..1fb9ed35 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -9,6 +9,13 @@ import BitByteData /// Provides functions for work with TAR containers. public class TarContainer: Container { + public enum Format { + case prePosix + case ustar + case gnu + case pax + } + /** Processes TAR container and returns an array of `TarEntry` with information and data for all entries. From 150a3cfc1f8b6acd4f4949925785cfab9d6cdf75 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 7 Apr 2018 13:56:04 +0300 Subject: [PATCH 38/53] [TAR] Add internal property to entry info which shows if ustar-like magic was encountered --- Sources/TAR/TarEntryInfo.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/TAR/TarEntryInfo.swift b/Sources/TAR/TarEntryInfo.swift index 23a5680b..65b16459 100644 --- a/Sources/TAR/TarEntryInfo.swift +++ b/Sources/TAR/TarEntryInfo.swift @@ -91,6 +91,7 @@ public struct TarEntryInfo: ContainerEntryInfo { public let unknownExtendedHeaderRecords: [String: String]? let specialEntryType: SpecialEntryType? + let hasRecognizedMagic: Bool let blockStartIndex: Int @@ -174,6 +175,7 @@ public struct TarEntryInfo: ContainerEntryInfo { let magic = byteReader.uint64() if magic == 0x0020207261747375 || magic == 0x3030007261747375 || magic == 0x3030207261747375 { + self.hasRecognizedMagic = true let uname = try byteReader.nullEndedAsciiString(cutoff: 32) self.ownerUserName = (local?.uname ?? global?.uname) ?? uname @@ -191,6 +193,7 @@ public struct TarEntryInfo: ContainerEntryInfo { } } } else { + self.hasRecognizedMagic = false ownerUserName = local?.uname ?? global?.uname ownerGroupName = local?.gname ?? global?.gname deviceMajorNumber = nil From 477ebcf48e34fe76ba89baca89652542c4caa4e5 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 7 Apr 2018 13:37:17 +0300 Subject: [PATCH 39/53] [TAR] Add TarContainer.formatOf function --- Sources/TAR/TarContainer.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index 1fb9ed35..1a12bbe1 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -16,6 +16,28 @@ public class TarContainer: Container { case pax } + public static func formatOf(container data: Data) throws -> Format { + // TAR container should be at least 512 bytes long (when it contains only one header). + guard data.count >= 512 else { throw TarError.tooSmallFileIsPassed } + + /// Object with input data which supports convenient work with bit shifts. + var infoProvider = TarEntryInfoProvider(data) + + var specialMagicEncountered = false + + while let info = try infoProvider.next() { + if info.specialEntryType == .globalExtendedHeader || info.specialEntryType == .localExtendedHeader { + return .pax + } else if info.specialEntryType == .longName || info.specialEntryType == .longLinkName { + return .gnu + } else if info.hasRecognizedMagic { + specialMagicEncountered = true + } + } + + return specialMagicEncountered ? .ustar : .prePosix + } + /** Processes TAR container and returns an array of `TarEntry` with information and data for all entries. From 5a91fb2145e3ecf6a55be4ae72010c92d79126ae Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 7 Apr 2018 13:56:36 +0300 Subject: [PATCH 40/53] [Tests] Add tests for TarContainer.formatOf function --- Tests/TarTests.swift | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Tests/TarTests.swift b/Tests/TarTests.swift index 5dcd83e0..73923e97 100644 --- a/Tests/TarTests.swift +++ b/Tests/TarTests.swift @@ -15,6 +15,9 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + let result = try TarContainer.open(container: testData) XCTAssertEqual(result.count, 1) @@ -29,6 +32,9 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + XCTAssertEqual(try TarContainer.formatOf(container: testData), .pax) + let result = try TarContainer.open(container: testData) XCTAssertEqual(result.count, 5) @@ -62,6 +68,19 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + if testName == "test_gnu" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + } else if testName == "test_oldgnu" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + } else if testName == "test_pax" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .pax) + } else if testName == "test_ustar" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + } else if testName == "test_v7" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .prePosix) + } + let result = try TarContainer.open(container: testData) XCTAssertEqual(result.count, 1) @@ -80,6 +99,15 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + if testName == "long_test_gnu" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .gnu) + } else if testName == "long_test_oldgnu" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .gnu) + } else if testName == "long_test_pax" { + XCTAssertEqual(try TarContainer.formatOf(container: testData), .pax) + } + let result = try TarContainer.open(container: testData) XCTAssertEqual(result.count, 6) @@ -91,6 +119,9 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + let entries = try TarContainer.open(container: testData) XCTAssertEqual(entries.count, 2) @@ -111,6 +142,9 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + let entries = try TarContainer.open(container: testData) XCTAssertEqual(entries.count, 1) @@ -125,6 +159,9 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + let entries = try TarContainer.open(container: testData) XCTAssertEqual(entries.count, 1) @@ -139,6 +176,9 @@ class TarTests: XCTestCase { XCTFail("Unable to get test data.") return } + + XCTAssertEqual(try TarContainer.formatOf(container: testData), .prePosix) + let entries = try TarContainer.open(container: testData) XCTAssertEqual(entries.isEmpty, true) @@ -150,6 +190,8 @@ class TarTests: XCTestCase { return } + XCTAssertEqual(try TarContainer.formatOf(container: testData), .ustar) + _ = try TarContainer.info(container: testData) _ = try TarContainer.open(container: testData) } From 7e04fe1fba700c9530d581a5c2091db5b8a5fa0f Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 13 Apr 2018 18:16:47 +0300 Subject: [PATCH 41/53] [swcomp] Add --format (-f) option to TarCommand which prints format of the container --- Sources/swcomp/TarCommand.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/swcomp/TarCommand.swift b/Sources/swcomp/TarCommand.swift index 665b9846..5f7c6e1f 100644 --- a/Sources/swcomp/TarCommand.swift +++ b/Sources/swcomp/TarCommand.swift @@ -18,12 +18,13 @@ class TarCommand: Command { let info = Flag("-i", "--info", description: "Print list of entries in container and their attributes") let extract = Key("-e", "--extract", description: "Extract container into specified directory") + let format = Flag("-f", "--format", description: "Prints \"format\" of the container") let verbose = Flag("--verbose", description: "Print the list of extracted files and directories.") var optionGroups: [OptionGroup] { let compressions = OptionGroup(options: [gz, bz2, xz], restriction: .atMostOne) - let actions = OptionGroup(options: [info, extract], restriction: .exactlyOne) + let actions = OptionGroup(options: [info, extract, format], restriction: .exactlyOne) return [compressions, actions] } @@ -52,6 +53,19 @@ class TarCommand: Command { let entries = try TarContainer.open(container: fileData) try swcomp.write(entries, outputPath, verbose.value) + } else if format.value { + let format = try TarContainer.formatOf(container: fileData) + switch format { + case .prePosix: + print("TAR format: pre-POSIX") + case .ustar: + print("TAR format: POSIX aka \"ustar\"") + case .gnu: + print("TAR format: POSIX with GNU extensions") + case .pax: + print("TAR format: PAX") + } + } } From 8434e7b1bdc934c03176a526f8a902297dd32e9f Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 13 Apr 2018 18:45:28 +0300 Subject: [PATCH 42/53] [docs] Add documentation for TarContainer.Format and formatOf(container:) --- Sources/TAR/TarContainer.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index 1a12bbe1..7ef842e8 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -9,13 +9,31 @@ import BitByteData /// Provides functions for work with TAR containers. public class TarContainer: Container { + /** + Represents a "format" of TAR container: a minimal set of extensions to basic TAR format required to successfully + read particular container. + */ public enum Format { + /// Pre POSIX format (aka "basic TAR format"). case prePosix + /// "UStar" format introduced by POSIX IEEE P1003.1 standard. case ustar + /// "UStar"-like format with GNU extensions (e.g. special container entries for long file and link names). case gnu + /// "PAX" format introduced by POSIX.1-2001 standard, a set of extensions to "UStar" format. case pax } + /** + Processes TAR container and returns its "format": a minimal set of extensions to basic TAR format required to + successfully read this container. + + - Parameter container: TAR container's data. + + - Throws: `TarError`, which may indicate that either container is damaged or it might not be TAR container at all. + + - SeeAlso: `TarContainer.Format` + */ public static func formatOf(container data: Data) throws -> Format { // TAR container should be at least 512 bytes long (when it contains only one header). guard data.count >= 512 else { throw TarError.tooSmallFileIsPassed } From 05268bd44ea6f6d7add73d52b7327dbcaf68c07b Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 13 Apr 2018 18:53:58 +0300 Subject: [PATCH 43/53] [docs] Add "missing" docs for Container.Entry and and ContainerEntry.Info Apparently, something changed in Swift 4.1 and sourcekitten/jazzy now detects associated types and produces documentation for them. --- Sources/Common/Container/Container.swift | 1 + Sources/Common/Container/ContainerEntry.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/Common/Container/Container.swift b/Sources/Common/Container/Container.swift index f7f67287..f3376212 100644 --- a/Sources/Common/Container/Container.swift +++ b/Sources/Common/Container/Container.swift @@ -8,6 +8,7 @@ import Foundation /// A type that represents a container with files, directories and/or other data. public protocol Container { + /// A type that represents an entry from this container. associatedtype Entry: ContainerEntry /// Retrieve all container entries with their data. diff --git a/Sources/Common/Container/ContainerEntry.swift b/Sources/Common/Container/ContainerEntry.swift index 348c5d6d..b41f2e0a 100644 --- a/Sources/Common/Container/ContainerEntry.swift +++ b/Sources/Common/Container/ContainerEntry.swift @@ -8,6 +8,7 @@ import Foundation /// A type that represents an entry from the container with its data and information. public protocol ContainerEntry { + /// A type that provides information about an entry. associatedtype Info: ContainerEntryInfo /// Provides access to information about the entry. From 0686ce7b6d430e98a35d1671656ea8a8bf4628b3 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 13 Apr 2018 18:55:22 +0300 Subject: [PATCH 44/53] [docs] Add ZipExtraField and ZipExtraFieldLocation to Containers category --- .jazzy.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.jazzy.yaml b/.jazzy.yaml index db7d4de5..caec3e95 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -35,6 +35,8 @@ custom_categories: - ZipContainer - ZipEntry - ZipEntryInfo + - ZipExtraField + - ZipExtraFieldLocation - name: Errors children: - BZip2Error From 7929e580222be47ccc890576f9b745242146df90 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 13 Apr 2018 22:55:12 +0300 Subject: [PATCH 45/53] Synthesize Equatable conformance for HuffmanLength --- Sources/Common/HuffmanLength+Comparable.swift | 4 ---- Sources/Common/HuffmanLength.swift | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Common/HuffmanLength+Comparable.swift b/Sources/Common/HuffmanLength+Comparable.swift index 773a5f19..b4c996a5 100644 --- a/Sources/Common/HuffmanLength+Comparable.swift +++ b/Sources/Common/HuffmanLength+Comparable.swift @@ -15,8 +15,4 @@ extension HuffmanLength: Comparable { } } - static func == (left: HuffmanLength, right: HuffmanLength) -> Bool { - return left.codeLength == right.codeLength && left.symbol == right.symbol - } - } diff --git a/Sources/Common/HuffmanLength.swift b/Sources/Common/HuffmanLength.swift index 228eadf5..21c0ca01 100644 --- a/Sources/Common/HuffmanLength.swift +++ b/Sources/Common/HuffmanLength.swift @@ -5,7 +5,7 @@ import Foundation -struct HuffmanLength { +struct HuffmanLength: Equatable { let symbol: Int let codeLength: Int From 3d3d4a2c0e73af060fda3e860054472122f35eeb Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 13 Apr 2018 22:56:15 +0300 Subject: [PATCH 46/53] Move Comparable extension of HuffmanLength into its main file --- SWCompression.xcodeproj/project.pbxproj | 4 ---- Sources/Common/HuffmanLength+Comparable.swift | 18 ------------------ Sources/Common/HuffmanLength.swift | 12 ++++++++++++ 3 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 Sources/Common/HuffmanLength+Comparable.swift diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index dd797a5d..a27fbd14 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -93,7 +93,6 @@ 06DE29B81FB7024C0098A761 /* ByteReader+ZipString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06DE29B71FB7024C0098A761 /* ByteReader+ZipString.swift */; }; 06E2346C1E068E9600F18798 /* XZArchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E2346B1E068E9600F18798 /* XZArchive.swift */; }; 06E234821E06A6C200F18798 /* CheckSums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E234811E06A6C200F18798 /* CheckSums.swift */; }; - 06E30F391F82D2DD00F80167 /* HuffmanLength+Comparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E30F381F82D2DD00F80167 /* HuffmanLength+Comparable.swift */; }; 06E6A6391F5C0FBB00D04856 /* HuffmanLength.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06E6A6381F5C0FBB00D04856 /* HuffmanLength.swift */; }; 06F0659A1FFB761600312A82 /* SWCompression.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06BE1AC81DB410F100EE0F59 /* SWCompression.framework */; }; 06F066131FFB763300312A82 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F065A11FFB763300312A82 /* Constants.swift */; }; @@ -295,7 +294,6 @@ 06DE29B71FB7024C0098A761 /* ByteReader+ZipString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ByteReader+ZipString.swift"; sourceTree = ""; }; 06E2346B1E068E9600F18798 /* XZArchive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XZArchive.swift; sourceTree = ""; }; 06E234811E06A6C200F18798 /* CheckSums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CheckSums.swift; path = Sources/Common/CheckSums.swift; sourceTree = SOURCE_ROOT; }; - 06E30F381F82D2DD00F80167 /* HuffmanLength+Comparable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "HuffmanLength+Comparable.swift"; path = "Sources/Common/HuffmanLength+Comparable.swift"; sourceTree = SOURCE_ROOT; }; 06E6A6381F5C0FBB00D04856 /* HuffmanLength.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HuffmanLength.swift; path = Sources/Common/HuffmanLength.swift; sourceTree = SOURCE_ROOT; }; 06F065951FFB761600312A82 /* TestSWCompression.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestSWCompression.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 06F065A11FFB763300312A82 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; @@ -438,7 +436,6 @@ 06092A191FA4CB0300DE9FD5 /* CompressionMethod.swift */, 0686A63A1FA4C07D00E89C9E /* FileSystemType.swift */, 06E6A6381F5C0FBB00D04856 /* HuffmanLength.swift */, - 06E30F381F82D2DD00F80167 /* HuffmanLength+Comparable.swift */, 063DF1081DE1F07800F38082 /* DecodingHuffmanTree.swift */, 06FEAD911F54B9CD00AD016E /* EncodingHuffmanTree.swift */, ); @@ -1058,7 +1055,6 @@ 069AC20D1E02DB1D0041AC13 /* LZMA.swift in Sources */, 0686A6401FA4C18800E89C9E /* FileSystemType+Gzip.swift in Sources */, 06A3933A1DE0709300182E12 /* ZlibArchive.swift in Sources */, - 06E30F391F82D2DD00F80167 /* HuffmanLength+Comparable.swift in Sources */, 061C063D1F0E8AB700832F0C /* ZipError.swift in Sources */, 0606CF8120641209002B6EE9 /* StandardExtraFields.swift in Sources */, 0631CB061F81109E00A2E0AB /* Deflate+Constants.swift in Sources */, diff --git a/Sources/Common/HuffmanLength+Comparable.swift b/Sources/Common/HuffmanLength+Comparable.swift deleted file mode 100644 index b4c996a5..00000000 --- a/Sources/Common/HuffmanLength+Comparable.swift +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2018 Timofey Solomko -// Licensed under MIT License -// -// See LICENSE for license information - -import Foundation - -extension HuffmanLength: Comparable { - - static func < (left: HuffmanLength, right: HuffmanLength) -> Bool { - if left.codeLength == right.codeLength { - return left.symbol < right.symbol - } else { - return left.codeLength < right.codeLength - } - } - -} diff --git a/Sources/Common/HuffmanLength.swift b/Sources/Common/HuffmanLength.swift index 21c0ca01..a5200d75 100644 --- a/Sources/Common/HuffmanLength.swift +++ b/Sources/Common/HuffmanLength.swift @@ -11,3 +11,15 @@ struct HuffmanLength: Equatable { let codeLength: Int } + +extension HuffmanLength: Comparable { + + static func < (left: HuffmanLength, right: HuffmanLength) -> Bool { + if left.codeLength == right.codeLength { + return left.symbol < right.symbol + } else { + return left.codeLength < right.codeLength + } + } + +} From 3b8989549e340ed2bdf192c022760cb5d8815670 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Fri, 20 Apr 2018 19:23:29 +0300 Subject: [PATCH 47/53] Prepare for the second test release of 4.3.0 --- .jazzy.yaml | 4 ++-- CHANGELOG.md | 8 ++++++++ SWCompression.podspec | 2 +- SWCompression.xcodeproj/SWCompression.plist | 4 ++-- SWCompression.xcodeproj/TestSWCompression.plist | 4 ++-- SWCompression.xcodeproj/project.pbxproj | 8 ++++---- Sources/swcomp/main.swift | 2 +- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.jazzy.yaml b/.jazzy.yaml index adf07293..e361976b 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -3,11 +3,11 @@ sourcekitten_sourcefile: docs.json clean: true author: Timofey Solomko module: SWCompression -module_version: 4.3.0-test.1 +module_version: 4.3.0-test.2 copyright: '© 2018 Timofey Solomko' readme: README.md github_url: https://github.com/tsolomko/SWCompression -github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.3.0-test.1 +github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.3.0-test.2 theme: fullwidth custom_categories: diff --git a/CHANGELOG.md b/CHANGELOG.md index 58d2419f..ec4a9532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## 4.3.0 +### Test 2 + +- Added `TarContainer.Format` enum which represents various formats of TAR containers. +- Added `TarContainer.formatOf(container:)` function which returns format for the container. +- Added `-f`, `--format` option to `tar` command which prints format of TAR container. +- Added documenation for `Container.Entry` and `ContainerEntry.Info` associated types. +- [Test] Documentation pages for `ZipExtraField` and `ZipExtraFieldLocation` are now located in "Containers" category. + ### Test 1 - Updated to support Swift 4.1. diff --git a/SWCompression.podspec b/SWCompression.podspec index 4f53c122..b122cba1 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SWCompression" - s.version = "4.3.0-test.1" + s.version = "4.3.0-test.2" s.summary = "A framework with functions for working with compression, archives and containers." s.description = "A framework with (de)compression algorithms and functions for processing various archives and containers." diff --git a/SWCompression.xcodeproj/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist index 4f4168aa..42b5e6b7 100644 --- a/SWCompression.xcodeproj/SWCompression.plist +++ b/SWCompression.xcodeproj/SWCompression.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.3.0-test.1 + 4.3.0-test.2 CFBundleVersion - 60 + 61 NSHumanReadableCopyright Copyright © 2018 Timofey Solomko. All rights reserved. diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist index f69d89da..7d5b57aa 100644 --- a/SWCompression.xcodeproj/TestSWCompression.plist +++ b/SWCompression.xcodeproj/TestSWCompression.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 4.3.0-test.1 + 4.3.0-test.2 CFBundleVersion - 60 + 61 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 79073354..ebf5cd29 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1159,7 +1159,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 60; + CURRENT_PROJECT_VERSION = 61; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1216,7 +1216,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 60; + CURRENT_PROJECT_VERSION = 61; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; @@ -1254,7 +1254,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 60; + DYLIB_CURRENT_VERSION = 61; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -1282,7 +1282,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 60; + DYLIB_CURRENT_VERSION = 61; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Sources/swcomp/main.swift b/Sources/swcomp/main.swift index 5517add8..b1efa384 100644 --- a/Sources/swcomp/main.swift +++ b/Sources/swcomp/main.swift @@ -7,7 +7,7 @@ import Foundation import SWCompression import SwiftCLI -let cli = CLI(name: "swcomp", version: "4.3.0-test.1", +let cli = CLI(name: "swcomp", version: "4.3.0-test.2", description: """ swcomp - small command-line client for SWCompression framework. Serves as an example of SWCompression usage. From ed56b7d8bf18faae499e7a8c95e356087a653b39 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 21 Apr 2018 13:45:04 +0300 Subject: [PATCH 48/53] Add benchmark results for 4.3.0 --- Tests/Results.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/Results.md b/Tests/Results.md index 3a7d19a2..a944bec6 100644 --- a/Tests/Results.md +++ b/Tests/Results.md @@ -31,6 +31,7 @@ __Note:__ All results are averages over 6 iterations. |4.0.0|—|6.821 ± 0.042|54.214 ± 1.398|7.255 ± 0.117| |4.0.1|—|6.797 ± 0.080|54.046 ± 1.070|7.177 ± 0.029| |4.1.0|1.0.1|4.452 ± 0.125|36.768 ± 0.382|4.880 ± 0.094| +|4.3.0|1.2.0|3.481 ± 0.038|27.187 ± 0.152|3.914 ± 0.091| ## XZ Unarchive (LZMA/LZMA2 Decompress) @@ -39,6 +40,7 @@ __Note:__ All results are averages over 6 iterations. |4.0.0|—|error|24.663 ± 2.349|2.904 ± 0.076| |4.0.1|—|2.475 ± 0.067|23.507 ± 0.423|2.901 ± 0.049| |4.1.0|1.0.1|2.480 ± 0.091|24.126 ± 1.239|2.892 ± 0.052| +|4.3.0|1.2.0|2.664 ± 0.031|26.030 ± 1.200|3.111 ± 0.053| ## GZip Unarchive (Deflate Decompress) @@ -47,6 +49,7 @@ __Note:__ All results are averages over 6 iterations. |4.0.0|—|4.007 ± 0.196|32.043 ± 0.581|4.303 ± 0.045| |4.0.1|—|3.886 ± 0.100|32.390 ± 0.896|4.295 ± 0.040| |4.1.0|1.0.1|2.886 ± 0.571|22.134 ± 1.473|2.700 ± 0.168| +|4.3.0|1.2.0|1.622 ± 0.016|13.641 ± 0.069|1.804 ± 0.028| ## 7-Zip Info Function @@ -55,6 +58,7 @@ __Note:__ All results are averages over 6 iterations. |4.0.0|—|0.270 ± 0.010|crash|0.601 ± 0.057| |4.0.1|—|0.258 ± 0.003|0.601 ± 0.010|0.473 ± 0.008| |4.1.0|1.0.1|0.062 ± 0.008|0.208 ± 0.010|0.122 ± 0.003| +|4.3.0|1.2.0|0.060 ± 0.006|0.208 ± 0.008|0.123 ± 0.008| ## TAR Info Function @@ -63,6 +67,7 @@ __Note:__ All results are averages over 6 iterations. |4.0.0|—|0.248 ± 0.172|1.563 ± 0.442|1.254 ± 0.277| |4.0.1|—|0.187 ± 0.177|1.257 ± 0.404|1.016 ± 0.325| |4.1.0|1.0.1|0.194 ± 0.190|1.335 ± 0.475|1.062 ± 0.353| +|4.3.0|1.2.0|0.111 ± 0.008|1.014 ± 0.016|0.813 ± 0.015| ## ZIP Info Function @@ -71,3 +76,4 @@ __Note:__ All results are averages over 6 iterations. |4.0.0|—|0.072 ± 0.065|0.669 ± 0.147|0.120 ± 0.081| |4.0.1|—|0.076 ± 0.064|0.670 ± 0.142|0.123 ± 0.080| |4.1.0|1.0.1|0.063 ± 0.076|0.148 ± 0.107|0.105 ± 0.089| +|4.3.0|1.2.0|0.044 ± 0.007|0.122 ± 0.009|0.086 ± 0.008| From dfa4aeb478e6b337a930d819a0eb621cfb1eca30 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 21 Apr 2018 13:45:35 +0300 Subject: [PATCH 49/53] Use 5.0.0 version of cli framework --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 805d1fee..a713dc46 100644 --- a/Package.swift +++ b/Package.swift @@ -11,7 +11,7 @@ let package = Package( dependencies: [ // SWCOMP: Uncomment the line below to build swcomp example program. // .package(url: "https://github.com/jakeheis/SwiftCLI", - // from: "4.2.0"), + // from: "5.0.0"), .package(url: "https://github.com/tsolomko/BitByteData", from: "1.2.0-test"), ], From e152c3b2c49bc230a1ebfcc4f0591f6eaa038bc9 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 21 Apr 2018 13:48:06 +0300 Subject: [PATCH 50/53] Add Swift version column to benchmark results --- Tests/Results.md | 72 ++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/Tests/Results.md b/Tests/Results.md index a944bec6..7d4ed0dd 100644 --- a/Tests/Results.md +++ b/Tests/Results.md @@ -26,54 +26,54 @@ __Note:__ All results are averages over 6 iterations. ## BZip2 Decompress -|SWCompression
version|BitByteData
version|Test 1|Test 2|Test 3| -|:---:|:---:|---|---|---| -|4.0.0|—|6.821 ± 0.042|54.214 ± 1.398|7.255 ± 0.117| -|4.0.1|—|6.797 ± 0.080|54.046 ± 1.070|7.177 ± 0.029| -|4.1.0|1.0.1|4.452 ± 0.125|36.768 ± 0.382|4.880 ± 0.094| -|4.3.0|1.2.0|3.481 ± 0.038|27.187 ± 0.152|3.914 ± 0.091| +|SWCompression
version|BitByteData
version|Swift
version|Test 1|Test 2|Test 3| +|:---:|:---:|:---:|---|---|---| +|4.0.0|—|4.0.X|6.821 ± 0.042|54.214 ± 1.398|7.255 ± 0.117| +|4.0.1|—|4.0.X|6.797 ± 0.080|54.046 ± 1.070|7.177 ± 0.029| +|4.1.0|1.0.1|4.0.X|4.452 ± 0.125|36.768 ± 0.382|4.880 ± 0.094| +|4.3.0|1.2.0|4.1.0|3.481 ± 0.038|27.187 ± 0.152|3.914 ± 0.091| ## XZ Unarchive (LZMA/LZMA2 Decompress) -|SWCompression
version|BitByteData
version|Test 1|Test 2|Test 3| -|:---:|:---:|---|---|---| -|4.0.0|—|error|24.663 ± 2.349|2.904 ± 0.076| -|4.0.1|—|2.475 ± 0.067|23.507 ± 0.423|2.901 ± 0.049| -|4.1.0|1.0.1|2.480 ± 0.091|24.126 ± 1.239|2.892 ± 0.052| -|4.3.0|1.2.0|2.664 ± 0.031|26.030 ± 1.200|3.111 ± 0.053| +|SWCompression
version|BitByteData
version|Swift
version|Test 1|Test 2|Test 3| +|:---:|:---:|:---:|---|---|---| +|4.0.0|—|4.0.X|error|24.663 ± 2.349|2.904 ± 0.076| +|4.0.1|—|4.0.X|2.475 ± 0.067|23.507 ± 0.423|2.901 ± 0.049| +|4.1.0|1.0.1|4.0.X|2.480 ± 0.091|24.126 ± 1.239|2.892 ± 0.052| +|4.3.0|1.2.0|4.1.0|2.664 ± 0.031|26.030 ± 1.200|3.111 ± 0.053| ## GZip Unarchive (Deflate Decompress) -|SWCompression
version|BitByteData
version|Test 1|Test 2|Test 3| -|:---:|:---:|---|---|---| -|4.0.0|—|4.007 ± 0.196|32.043 ± 0.581|4.303 ± 0.045| -|4.0.1|—|3.886 ± 0.100|32.390 ± 0.896|4.295 ± 0.040| -|4.1.0|1.0.1|2.886 ± 0.571|22.134 ± 1.473|2.700 ± 0.168| -|4.3.0|1.2.0|1.622 ± 0.016|13.641 ± 0.069|1.804 ± 0.028| +|SWCompression
version|BitByteData
version|Swift
version|Test 1|Test 2|Test 3| +|:---:|:---:|:---:|---|---|---| +|4.0.0|—|4.0.X|4.007 ± 0.196|32.043 ± 0.581|4.303 ± 0.045| +|4.0.1|—|4.0.X|3.886 ± 0.100|32.390 ± 0.896|4.295 ± 0.040| +|4.1.0|1.0.1|4.0.X|2.886 ± 0.571|22.134 ± 1.473|2.700 ± 0.168| +|4.3.0|1.2.0|4.1.0|1.622 ± 0.016|13.641 ± 0.069|1.804 ± 0.028| ## 7-Zip Info Function -|SWCompression
version|BitByteData
version|Test 1|Test 2|Test 3| -|:---:|:---:|---|---|---| -|4.0.0|—|0.270 ± 0.010|crash|0.601 ± 0.057| -|4.0.1|—|0.258 ± 0.003|0.601 ± 0.010|0.473 ± 0.008| -|4.1.0|1.0.1|0.062 ± 0.008|0.208 ± 0.010|0.122 ± 0.003| -|4.3.0|1.2.0|0.060 ± 0.006|0.208 ± 0.008|0.123 ± 0.008| +|SWCompression
version|BitByteData
version|Swift
version|Test 1|Test 2|Test 3| +|:---:|:---:|:---:|---|---|---| +|4.0.0|—|4.0.X|0.270 ± 0.010|crash|0.601 ± 0.057| +|4.0.1|—|4.0.X|0.258 ± 0.003|0.601 ± 0.010|0.473 ± 0.008| +|4.1.0|1.0.1|4.0.X|0.062 ± 0.008|0.208 ± 0.010|0.122 ± 0.003| +|4.3.0|1.2.0|4.1.0|0.060 ± 0.006|0.208 ± 0.008|0.123 ± 0.008| ## TAR Info Function -|SWCompression
version|BitByteData
version|Test 1|Test 2|Test 3| -|:---:|:---:|---|---|---| -|4.0.0|—|0.248 ± 0.172|1.563 ± 0.442|1.254 ± 0.277| -|4.0.1|—|0.187 ± 0.177|1.257 ± 0.404|1.016 ± 0.325| -|4.1.0|1.0.1|0.194 ± 0.190|1.335 ± 0.475|1.062 ± 0.353| -|4.3.0|1.2.0|0.111 ± 0.008|1.014 ± 0.016|0.813 ± 0.015| +|SWCompression
version|BitByteData
version|Swift
version|Test 1|Test 2|Test 3| +|:---:|:---:|:---:|---|---|---| +|4.0.0|—|4.0.X|0.248 ± 0.172|1.563 ± 0.442|1.254 ± 0.277| +|4.0.1|—|4.0.X|0.187 ± 0.177|1.257 ± 0.404|1.016 ± 0.325| +|4.1.0|1.0.1|4.0.X|0.194 ± 0.190|1.335 ± 0.475|1.062 ± 0.353| +|4.3.0|1.2.0|4.1.0|0.111 ± 0.008|1.014 ± 0.016|0.813 ± 0.015| ## ZIP Info Function -|SWCompression
version|BitByteData
version|Test 1|Test 2|Test 3| -|:---:|:---:|---|---|---| -|4.0.0|—|0.072 ± 0.065|0.669 ± 0.147|0.120 ± 0.081| -|4.0.1|—|0.076 ± 0.064|0.670 ± 0.142|0.123 ± 0.080| -|4.1.0|1.0.1|0.063 ± 0.076|0.148 ± 0.107|0.105 ± 0.089| -|4.3.0|1.2.0|0.044 ± 0.007|0.122 ± 0.009|0.086 ± 0.008| +|SWCompression
version|BitByteData
version|Swift
version|Test 1|Test 2|Test 3| +|:---:|:---:|:---:|---|---|---| +|4.0.0|—|4.0.X|0.072 ± 0.065|0.669 ± 0.147|0.120 ± 0.081| +|4.0.1|—|4.0.X|0.076 ± 0.064|0.670 ± 0.142|0.123 ± 0.080| +|4.1.0|1.0.1|4.0.X|0.063 ± 0.076|0.148 ± 0.107|0.105 ± 0.089| +|4.3.0|1.2.0|4.1.0|0.044 ± 0.007|0.122 ± 0.009|0.086 ± 0.008| From e0cba7f4209bb33b084a6c4db51298b3ced61581 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sat, 21 Apr 2018 14:02:20 +0300 Subject: [PATCH 51/53] Mention iteration changes in benchmark results --- Tests/Results.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Tests/Results.md b/Tests/Results.md index 7d4ed0dd..0f749650 100644 --- a/Tests/Results.md +++ b/Tests/Results.md @@ -1,17 +1,22 @@ # Test Results -In this document you can find the results of benchmarking which were run on Macbook Pro, Late 2011. -The main purpose of these results is to track the progress from version to version. +In this document you can find the results of benchmarking which was performed on Macbook Pro, Late 2011. The main +purpose of these results is to track progress from version to version. -__Note:__ Since version 4.1.0 of SWCompression internal functionality related to reading/writing bits and bytes +__Note:__ Since 4.1.0 version of SWCompression internal functionality related to reading/writing bits and bytes is published as a separate framework, [BitByteData](https://github.com/tsolomko/BitByteData). -It is worth mentioning that overall performance depends on the speed of reading and writing, -and thus BitByteData's version (which is specified in a separate column in the tables below) -becomes relevant to benchmarking, since newer version can contain speed improvements. +The overall performance heavily depends on the speed of reading and writing, and thus BitByteData's version, which is +specified in a separate column in the tables below, becomes relevant to benchmarking, since newer versions can contain +performance improvements. + +__Note:__ Since 4.3.0 version of SWCompression the first (zeroth, actually) iteration is excluded from averages +calculation since this iteration has abnormally longer execution time than any of the following iterations. This +exclusion led not only to (artificially) improved results, but also to the increased quality of the results by reducing +calculated uncertainty. ## Tests description -There are three different datasets for testing. When choosing them I was trying to have something, +There are three different datasets for testing. When choosing them the intention was to have something that represents real life situations. For obvious reasons these test files aren't provided anywhere in the repository. @@ -22,7 +27,7 @@ in the repository. All tests were run using swcomp's "benchmark" command. SWCompression (and swcomp) were compiled using "Release" configuration. -__Note:__ All results are averages over 6 iterations. +__Note:__ All results are averages over 10 iterations (6 iterations until 4.3.0 version). ## BZip2 Decompress From f248862a79576aea094871cee8af853e9d83e80f Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 29 Apr 2018 11:26:28 +0300 Subject: [PATCH 52/53] Use final version of BBD 1.2.0 --- Cartfile | 2 +- Package.swift | 2 +- SWCompression.podspec | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cartfile b/Cartfile index 02555728..20558217 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "tsolomko/BitByteData" "1.2.0-test.3" +github "tsolomko/BitByteData" ~> 1.2 diff --git a/Package.swift b/Package.swift index a713dc46..0da00ff9 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( // .package(url: "https://github.com/jakeheis/SwiftCLI", // from: "5.0.0"), .package(url: "https://github.com/tsolomko/BitByteData", - from: "1.2.0-test"), + from: "1.2.0"), ], targets: [ // SWCOMP: Uncomment the lines below to build swcomp example program. diff --git a/SWCompression.podspec b/SWCompression.podspec index b122cba1..878df27a 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.swift_version = "4.1" - s.dependency "BitByteData", "~> 1.2.0-test.3" + s.dependency "BitByteData", "~> 1.2.0" s.subspec "Deflate" do |sp| sp.source_files = "Sources/{Deflate/*,Common/*}.swift" From d55607dd0669ca27db2f3874bb4c59bb4c015ee1 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 29 Apr 2018 11:27:40 +0300 Subject: [PATCH 53/53] Prepare for 4.3.0 release --- .jazzy.yaml | 4 ++-- CHANGELOG.md | 19 +++++++------------ SWCompression.podspec | 2 +- SWCompression.xcodeproj/SWCompression.plist | 4 ++-- .../TestSWCompression.plist | 4 ++-- SWCompression.xcodeproj/project.pbxproj | 8 ++++---- Sources/swcomp/main.swift | 2 +- 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/.jazzy.yaml b/.jazzy.yaml index e361976b..9eddaeb7 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -3,11 +3,11 @@ sourcekitten_sourcefile: docs.json clean: true author: Timofey Solomko module: SWCompression -module_version: 4.3.0-test.2 +module_version: 4.3.0 copyright: '© 2018 Timofey Solomko' readme: README.md github_url: https://github.com/tsolomko/SWCompression -github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.3.0-test.2 +github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.3.0 theme: fullwidth custom_categories: diff --git a/CHANGELOG.md b/CHANGELOG.md index ec4a9532..bba766f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,24 +2,19 @@ ## 4.3.0 -### Test 2 - -- Added `TarContainer.Format` enum which represents various formats of TAR containers. -- Added `TarContainer.formatOf(container:)` function which returns format for the container. -- Added `-f`, `--format` option to `tar` command which prints format of TAR container. -- Added documenation for `Container.Entry` and `ContainerEntry.Info` associated types. -- [Test] Documentation pages for `ZipExtraField` and `ZipExtraFieldLocation` are now located in "Containers" category. - -### Test 1 - - Updated to support Swift 4.1. -- Minuimum required version of BitByteData is now 1.2.0-test.3. -- Added APIs to enable support of custom ZIP Extra Fields. +- Minuimum required version of BitByteData is now 1.2.0. +- Added APIs which allow to use custom ZIP Extra Fields. - Added `ZipExtraField` protocol. - Added `ZipExtraFieldLocation` enum. - Added `ZipContainer.customExtraFields` property. - Added `ZipEntryInfo.customExtraFields` property. +- Added APIs which allow to get information about TAR's format: + - Added `TarContainer.Format` enum which represents various formats of TAR containers. + - Added `TarContainer.formatOf(container:)` function which returns format of the container. + - Added `-f`, `--format` option to swcomp's `tar` command which prints format of TAR container. - Added `TarEntryInfo.compressionMethod` property which is always equal to `.copy`. +- Added documenation for `Container.Entry` and `ContainerEntry.Info` associated types. - Reverted "disable symbol stripping" change from 4.2.0 update, since underlying problem was fixed in Carthage. - Benchmarks changes: - Iterations number increased from 6 to 10. diff --git a/SWCompression.podspec b/SWCompression.podspec index 878df27a..a0309604 100644 --- a/SWCompression.podspec +++ b/SWCompression.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SWCompression" - s.version = "4.3.0-test.2" + s.version = "4.3.0" s.summary = "A framework with functions for working with compression, archives and containers." s.description = "A framework with (de)compression algorithms and functions for processing various archives and containers." diff --git a/SWCompression.xcodeproj/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist index 42b5e6b7..f2425192 100644 --- a/SWCompression.xcodeproj/SWCompression.plist +++ b/SWCompression.xcodeproj/SWCompression.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.3.0-test.2 + 4.3.0 CFBundleVersion - 61 + 62 NSHumanReadableCopyright Copyright © 2018 Timofey Solomko. All rights reserved. diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist index 7d5b57aa..41412361 100644 --- a/SWCompression.xcodeproj/TestSWCompression.plist +++ b/SWCompression.xcodeproj/TestSWCompression.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 4.3.0-test.2 + 4.3.0 CFBundleVersion - 61 + 62 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index ebf5cd29..800d1067 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -1159,7 +1159,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 61; + CURRENT_PROJECT_VERSION = 62; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -1216,7 +1216,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 61; + CURRENT_PROJECT_VERSION = 62; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; "FRAMEWORK_SEARCH_PATHS[sdk=appletvos*]" = "\"$(SRCROOT)/Carthage/Build/tvOS\""; @@ -1254,7 +1254,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 61; + DYLIB_CURRENT_VERSION = 62; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -1282,7 +1282,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 61; + DYLIB_CURRENT_VERSION = 62; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SWCompression.xcodeproj/SWCompression.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/Sources/swcomp/main.swift b/Sources/swcomp/main.swift index b1efa384..86714538 100644 --- a/Sources/swcomp/main.swift +++ b/Sources/swcomp/main.swift @@ -7,7 +7,7 @@ import Foundation import SWCompression import SwiftCLI -let cli = CLI(name: "swcomp", version: "4.3.0-test.2", +let cli = CLI(name: "swcomp", version: "4.3.0", description: """ swcomp - small command-line client for SWCompression framework. Serves as an example of SWCompression usage.