diff --git a/.jazzy.yaml b/.jazzy.yaml index db7d4de5..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.2.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.2.2 +github_file_prefix: https://github.com/tsolomko/SWCompression/tree/4.3.0 theme: fullwidth custom_categories: @@ -35,6 +35,8 @@ custom_categories: - ZipContainer - ZipEntry - ZipEntryInfo + - ZipExtraField + - ZipExtraFieldLocation - name: Errors children: - BZip2Error 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/.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 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/CHANGELOG.md b/CHANGELOG.md index dddbb2e9..bba766f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## 4.3.0 + +- Updated to support Swift 4.1. +- 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. + - 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/Cartfile b/Cartfile index ca433536..20558217 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "tsolomko/BitByteData" ~> 1.1 +github "tsolomko/BitByteData" ~> 1.2 diff --git a/Package.swift b/Package.swift index b096f43d..0da00ff9 100644 --- a/Package.swift +++ b/Package.swift @@ -11,9 +11,9 @@ 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: "5.0.0"), .package(url: "https://github.com/tsolomko/BitByteData", - from: "1.1.0"), + from: "1.2.0"), ], targets: [ // SWCOMP: Uncomment the lines below to build swcomp example program. diff --git a/README.md b/README.md index 23455135..ad77dd44 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) @@ -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`. diff --git a/SWCompression.podspec b/SWCompression.podspec index d089ab03..a0309604 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" 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." @@ -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.2.0" - 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/SWCompression.plist b/SWCompression.xcodeproj/SWCompression.plist index 328506ea..f2425192 100644 --- a/SWCompression.xcodeproj/SWCompression.plist +++ b/SWCompression.xcodeproj/SWCompression.plist @@ -15,9 +15,9 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.2.2 + 4.3.0 CFBundleVersion - 59 + 62 NSHumanReadableCopyright Copyright © 2018 Timofey Solomko. All rights reserved. diff --git a/SWCompression.xcodeproj/TestSWCompression.plist b/SWCompression.xcodeproj/TestSWCompression.plist index 8b00954d..41412361 100644 --- a/SWCompression.xcodeproj/TestSWCompression.plist +++ b/SWCompression.xcodeproj/TestSWCompression.plist @@ -15,8 +15,8 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 4.2.2 + 4.3.0 CFBundleVersion - 59 + 62 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 84aed303..800d1067 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -3,10 +3,11 @@ archiveVersion = 1; classes = { }; - objectVersion = 48; + objectVersion = 50; 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 */; }; @@ -37,6 +38,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 */; }; @@ -83,12 +85,14 @@ 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 */; }; 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 */; }; 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 */; }; @@ -204,6 +208,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 = ""; }; @@ -236,6 +241,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; }; @@ -280,12 +286,14 @@ 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 = ""; }; 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 = ""; }; 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 = ""; }; @@ -428,7 +436,6 @@ 06092A191FA4CB0300DE9FD5 /* CompressionMethod.swift */, 0686A63A1FA4C07D00E89C9E /* FileSystemType.swift */, 06E6A6381F5C0FBB00D04856 /* HuffmanLength.swift */, - 06E30F381F82D2DD00F80167 /* HuffmanLength+Comparable.swift */, 063DF1081DE1F07800F38082 /* DecodingHuffmanTree.swift */, 06FEAD911F54B9CD00AD016E /* EncodingHuffmanTree.swift */, ); @@ -560,6 +567,8 @@ 067518351E2A86F700D16354 /* ZipContainer.swift */, 061C06411F0E8AD500832F0C /* ZipEntry.swift */, 06BAC5931F8CFF28002443F4 /* ZipEntryInfo.swift */, + 0642998A206017590044BA0C /* ZipExtraField.swift */, + 0606CF8020641209002B6EE9 /* StandardExtraFields.swift */, 061C063C1F0E8AB700832F0C /* ZipError.swift */, 06393DF41F1A7F8E00A647A0 /* ZipString.swift */, 061C064C1F0E901C00832F0C /* ZipLocalHeader.swift */, @@ -582,6 +591,7 @@ 061C06561F0E90C800832F0C /* TarError.swift */, 0651FEC11F8E2E9100C49646 /* ContainerEntryType+Tar.swift */, 0656B82A1F8A979A00111605 /* ByteReader+Tar.swift */, + 06CFF6B12078C5A5003B8375 /* TarEntryInfoProvider.swift */, ); path = TAR; sourceTree = ""; @@ -623,6 +633,7 @@ 06F065A61FFB763300312A82 /* TarTests.swift */, 06F065A91FFB763300312A82 /* XzTests.swift */, 06F065A41FFB763300312A82 /* ZipTests.swift */, + 06D42DA62067B71000C1A98B /* TestZipExtraField.swift */, 06F065A31FFB763300312A82 /* ZlibTests.swift */, ); path = Tests; @@ -717,6 +728,7 @@ 06F065DB1FFB763300312A82 /* test_empty_cont.zip */, 06F065DC1FFB763300312A82 /* SWCompressionSourceCode.zip */, 06F065DD1FFB763300312A82 /* test_zip64.zip */, + 06D42DA42067B46800C1A98B /* test_custom_extra_field.zip */, ); path = ZIP; sourceTree = ""; @@ -854,7 +866,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 0920; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Timofey Solomko"; TargetAttributes = { 06BE1AC71DB410F100EE0F59 = { @@ -867,7 +879,7 @@ }; }; buildConfigurationList = 06BE1AC21DB410F100EE0F59 /* Build configuration list for PBXProject "SWCompression" */; - compatibilityVersion = "Xcode 8.0"; + compatibilityVersion = "Xcode 9.3"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( @@ -965,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 */, @@ -1042,8 +1055,8 @@ 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 */, 06D95AC11F4C54E0006B46AC /* BZip2+Compress.swift in Sources */, 06912BD21F5C8F3D0070BB60 /* Deflate+Lengths.swift in Sources */, @@ -1064,6 +1077,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 */, @@ -1083,6 +1097,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 */, @@ -1101,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 */, @@ -1125,25 +1141,35 @@ 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; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 59; + CURRENT_PROJECT_VERSION = 62; 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; @@ -1155,8 +1181,11 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = ( + "-framework", + BitByteData, + ); SDKROOT = macosx; - STRIP_INSTALLED_PRODUCT = NO; SUPPORTED_PLATFORMS = "macosx watchsimulator iphonesimulator appletvsimulator watchos appletvos iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TVOS_DEPLOYMENT_TARGET = 9.0; @@ -1169,24 +1198,34 @@ 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; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CURRENT_PROJECT_VERSION = 59; + CURRENT_PROJECT_VERSION = 62; 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; @@ -1196,10 +1235,13 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; + OTHER_LDFLAGS = ( + "-framework", + BitByteData, + ); SDKROOT = macosx; - STRIP_INSTALLED_PRODUCT = NO; 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; @@ -1212,18 +1254,17 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 59; + DYLIB_CURRENT_VERSION = 62; 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 = "$(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, @@ -1241,18 +1282,17 @@ APPLICATION_EXTENSION_API_ONLY = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 59; + DYLIB_CURRENT_VERSION = 62; 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 = "$(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, @@ -1269,7 +1309,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; @@ -1281,7 +1327,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 @@ = 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 fileSize <= unpackedStreamData.bytesLeft + 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 @@ -220,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/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.. 0 { - let digitsNumber = floor(log2(Double(lengthOfZerosRun) + 1)) + let digitsNumber = Int(floor(log2(Double(lengthOfZerosRun) + 1))) var remainder = lengthOfZerosRun - for _ in 0..>= 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) { 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/Common/HuffmanLength+Comparable.swift b/Sources/Common/HuffmanLength+Comparable.swift deleted file mode 100644 index 773a5f19..00000000 --- a/Sources/Common/HuffmanLength+Comparable.swift +++ /dev/null @@ -1,22 +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 - } - } - - 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..a5200d75 100644 --- a/Sources/Common/HuffmanLength.swift +++ b/Sources/Common/HuffmanLength.swift @@ -5,9 +5,21 @@ import Foundation -struct HuffmanLength { +struct HuffmanLength: Equatable { let symbol: Int 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 + } + } + +} 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/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/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/TAR/ByteReader+Tar.swift b/Sources/TAR/ByteReader+Tar.swift index fb9ebc1e..81eac888 100644 --- a/Sources/TAR/ByteReader+Tar.swift +++ b/Sources/TAR/ByteReader+Tar.swift @@ -13,13 +13,11 @@ extension ByteReader { var buffer = [UInt8]() while offset - startIndex < cutoff { let byte = self.byte() - if ends.contains(byte) { - offset -= 1 - break - } + guard !ends.contains(byte) + else { break } buffer.append(byte) } - offset += cutoff - (offset - startIndex) + offset = startIndex + cutoff return buffer } diff --git a/Sources/TAR/TarContainer.swift b/Sources/TAR/TarContainer.swift index ebf3ad8b..7ef842e8 100644 --- a/Sources/TAR/TarContainer.swift +++ b/Sources/TAR/TarContainer.swift @@ -9,6 +9,53 @@ 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 } + + /// 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. @@ -59,52 +106,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.. TarEntryInfo? { + guard byteReader.bytesLeft >= 1024, + byteReader.data[byteReader.offset.. 8 { + byteReader.offset += uidSize + } else { + self.uid = byteReader.int(fromBytes: uidSize) + } + + let gidSize = byteReader.byte().toInt() + if gidSize > 8 { + byteReader.offset += gidSize + } else { + self.gid = byteReader.int(fromBytes: gidSize) + } + } + +} diff --git a/Sources/ZIP/ZipCentralDirectoryEntry.swift b/Sources/ZIP/ZipCentralDirectoryEntry.swift index 79d80177..e620b1bb 100644 --- a/Sources/ZIP/ZipCentralDirectoryEntry.swift +++ b/Sources/ZIP/ZipCentralDirectoryEntry.swift @@ -29,18 +29,17 @@ 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 customExtraFields: [ZipExtraField] let nextEntryOffset: Int @@ -62,31 +61,33 @@ 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.uint16().toInt() - let extraFieldLength = byteReader.uint16().toInt() - let fileCommentLength = byteReader.uint16().toInt() + 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 } 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() - let size = byteReader.uint16().toInt() + let size = byteReader.int(fromBytes: 2) 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,56 +101,38 @@ 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.. BZip2.BlockSize? { + public static func convert(from: String) -> BZip2.BlockSize? { guard let num = Int(from) else { return nil } return BZip2.BlockSize(rawValue: num) 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") + } + } } diff --git a/Sources/swcomp/main.swift b/Sources/swcomp/main.swift index 5634f3eb..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.2.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. diff --git a/Tests/GzipTests.swift b/Tests/GzipTests.swift index 48fb35b5..9675dbf9 100644 --- a/Tests/GzipTests.swift +++ b/Tests/GzipTests.swift @@ -48,7 +48,7 @@ class GzipTests: XCTestCase { // Options for archiving. let mtimeDate = Date(timeIntervalSinceNow: 0.0) - let mtime = Double(Int(mtimeDate.timeIntervalSince1970)) + let mtime = mtimeDate.timeIntervalSince1970.rounded(.towardZero) // Test GZip archiving. let archiveData = try GzipArchive.archive(data: answerData, comment: "some file comment", diff --git a/Tests/Results.md b/Tests/Results.md index 3a7d19a2..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,52 +27,58 @@ 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 -|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| +|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| +|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| +|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| +|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| +|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| +|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| 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) } 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.")