Skip to content

Commit

Permalink
Merge branch 'hotfix-3.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsolomko committed Jul 8, 2017
2 parents d237520 + 0d1e952 commit 62f0c80
Show file tree
Hide file tree
Showing 84 changed files with 436 additions and 387 deletions.
4 changes: 2 additions & 2 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ clean: true
exclude: Tests/
author: Timofey Solomko
module: SWCompression
module_version: 3.1.2
module_version: 3.1.3
copyright: '© 2017 Timofey Solomko'
readme: README.md
github_url: https://github.com/tsolomko/SWCompression
github_file_prefix: https://github.com/tsolomko/SWCompression/tree/v3.1.2
github_file_prefix: https://github.com/tsolomko/SWCompression/tree/v3.1.3
theme: fullwidth

custom_categories:
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog
v3.1.1
v3.1.3
----------------
- Added support for GNU LongLing and LongName extenstions to TAR format.
- Added support for modification timestamp from extended timestamps ZIP extra field.

v3.1.2
----------------
- `wrongUstarVersion` error is no longer incorrectly thrown for GNU tar containers.

Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ Comment: Philosophy for such errors is that by the time these errors are thrown,
decompression was already performed, so we can still provide the result of decompression to the caller.
It is intended to fix this problem, but solution requires backwards-incompatible API changes so it is delayed until 4.0 release.

- GNU-specific extensions to TAR format (such as 'L' file type aka LongLink) are not fully supported.
Currently, they are returned as usual files with `typeUnknown` file type,
instead of being used as source of information about following entries.

Future plans
-------------
- Better Deflate compression.
Expand Down
2 changes: 1 addition & 1 deletion SWCompression.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SWCompression"
s.version = "3.1.2"
s.version = "3.1.3"
s.summary = "Framework with implementations in Swift of different (de)compression algorithms"

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Sources/Service/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.1.2</string>
<string>3.1.3</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
45 changes: 38 additions & 7 deletions Sources/TarContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TarEntry: ContainerEntry {

/// Name of the file or directory.
public var name: String {
return paxPath ?? ((fileNamePrefix ?? "") + (fileName ?? ""))
return (paxPath ?? gnuLongName) ?? ((fileNamePrefix ?? "") + (fileName ?? ""))
}

/// True, if an entry is a directory.
Expand Down Expand Up @@ -170,16 +170,33 @@ public class TarEntry: ContainerEntry {

/// Path to a linked file.
public var linkPath: String? {
return paxLinkPath ?? linkedFileName
return (paxLinkPath ?? gnuLongLinkName) ?? linkedFileName
}

private var paxLinkPath: String?

/// Other entries from PAX extended headers.
public private(set) var unknownExtendedHeaderEntries: [String: String] = [:]

let isLongName: Bool
let isLongLinkName: Bool

private let gnuLongName: String?
private let gnuLongLinkName: String?

fileprivate init(_ data: Data, _ index: inout Int,
_ globalExtendedHeader: String?, _ localExtendedHeader: String?) throws {
_ globalExtendedHeader: String?, _ localExtendedHeader: String?,
_ longName: String?, _ longLinkName: String?) throws {
if let longName = longName {
gnuLongName = longName
} else {
gnuLongName = nil
}
if let longLinkName = longLinkName {
gnuLongLinkName = longLinkName
} else {
gnuLongLinkName = nil
}
var attributesDict = [FileAttributeKey: Any]()

let blockStartIndex = index
Expand Down Expand Up @@ -248,7 +265,10 @@ public class TarEntry: ContainerEntry {
index += 8

// File type
let fileType = EntryType(rawValue: String(Character(UnicodeScalar(data[index])))) ?? .vendorUnknownOrReserved
let fileTypeIndicator = String(Character(UnicodeScalar(data[index])))
isLongLinkName = fileTypeIndicator == "K"
isLongName = fileTypeIndicator == "L"
let fileType = EntryType(rawValue: fileTypeIndicator) ?? .vendorUnknownOrReserved
type = fileType
switch fileType {
case .normal:
Expand Down Expand Up @@ -424,21 +444,32 @@ public class TarContainer: Container {

var lastGlobalExtendedHeader: String?
var lastLocalExtendedHeader: String?
var longLinkName: String?
var longName: String?

while true {
// Container ends with two zero-filled records.
if data.subdata(in: index..<index + 1024) == Data(bytes: Array(repeating: 0, count: 1024)) {
break
}
let entry = try TarEntry(data, &index, lastGlobalExtendedHeader, lastLocalExtendedHeader)
let entry = try TarEntry(data, &index, lastGlobalExtendedHeader, lastLocalExtendedHeader,
longName, longLinkName)
switch entry.type {
case .globalExtendedHeader:
lastGlobalExtendedHeader = String(data: entry.data(), encoding: .utf8)
case .localExtendedHeader:
lastLocalExtendedHeader = String(data: entry.data(), encoding: .utf8)
default:
output.append(entry)
lastLocalExtendedHeader = nil
if entry.isLongName {
longName = try entry.data().nullEndedAsciiString(0, entry.size)
} else if entry.isLongLinkName {
longLinkName = try entry.data().nullEndedAsciiString(0, entry.size)
} else {
output.append(entry)
lastLocalExtendedHeader = nil
longName = nil
longLinkName = nil
}
}
}

Expand Down
31 changes: 30 additions & 1 deletion Sources/ZipContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public class ZipEntry: ContainerEntry {
attributesDict[FileAttributeKey.modificationDate] = mtime
}

// Extended Timestamp
if let mtimestamp = cdEntry.modificationTimestamp {
attributesDict[FileAttributeKey.modificationDate] = Date(timeIntervalSince1970: TimeInterval(mtimestamp))
}

// Size
attributesDict[FileAttributeKey.size] = cdEntry.uncompSize

Expand Down Expand Up @@ -331,6 +336,10 @@ struct LocalHeader {

let fileName: String

private(set) var modificationTimestamp: Int?
private(set) var accessTimestamp: Int?
private(set) var creationTimestamp: Int?

init(_ pointerData: inout DataWithPointer) throws {
// Check signature.
guard pointerData.uint32FromAlignedBytes(count: 4) == 0x04034b50
Expand Down Expand Up @@ -372,6 +381,18 @@ struct LocalHeader {
self.compSize = pointerData.uint64FromAlignedBytes(count: 8)

self.zip64FieldsArePresent = true
case 0x5455: // Extended Timestamp
let flags = pointerData.alignedByte()
guard flags & 0xF8 == 0 else { break }
if flags & 0x01 != 0 {
self.modificationTimestamp = pointerData.intFromAlignedBytes(count: 4)
}
if flags & 0x02 != 0 {
self.accessTimestamp = pointerData.intFromAlignedBytes(count: 4)
}
if flags & 0x04 != 0 {
self.creationTimestamp = pointerData.intFromAlignedBytes(count: 4)
}
default:
pointerData.index += size
}
Expand Down Expand Up @@ -412,6 +433,8 @@ struct CentralDirectoryEntry {

private(set) var offset: UInt64

private(set) var modificationTimestamp: Int?

init(_ pointerData: inout DataWithPointer, _ currentDiskNumber: UInt32) throws {
// Check signature.
guard pointerData.uint32FromAlignedBytes(count: 4) == 0x02014b50
Expand Down Expand Up @@ -456,7 +479,7 @@ struct CentralDirectoryEntry {
let headerID = pointerData.intFromAlignedBytes(count: 2)
let size = pointerData.intFromAlignedBytes(count: 2)
switch headerID {
case 0x0001:
case 0x0001: // Zip64
if self.uncompSize == 0xFFFFFFFF {
self.uncompSize = pointerData.uint64FromAlignedBytes(count: 8)
}
Expand All @@ -469,6 +492,12 @@ struct CentralDirectoryEntry {
if self.diskNumberStart == 0xFFFF {
self.diskNumberStart = pointerData.uint32FromAlignedBytes(count: 4)
}
case 0x5455: // Extended Timestamp
let flags = pointerData.alignedByte()
guard flags & 0xF8 == 0 else { break }
if flags & 0x01 != 0 {
self.modificationTimestamp = pointerData.intFromAlignedBytes(count: 4)
}
default:
pointerData.index += size
}
Expand Down
10 changes: 5 additions & 5 deletions docs/Archives.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L189-L386">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L189-L386">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -242,7 +242,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L36-L186">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L36-L186">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -277,7 +277,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/ZlibArchive.swift#L117-L183">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/ZlibArchive.swift#L117-L183">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -308,7 +308,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/ZlibArchive.swift#L29-L114">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/ZlibArchive.swift#L29-L114">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -343,7 +343,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/XZArchive.swift#L45-L401">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/XZArchive.swift#L45-L401">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/BZip2.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ <h4>Return Value</h4>
<p>Decompressed data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/BZip2.swift#L53-L57">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/BZip2.swift#L53-L57">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/Deflate.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ <h4>Return Value</h4>
<p>Decompressed data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/Deflate.swift#L73-L77">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/Deflate.swift#L73-L77">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -314,7 +314,7 @@ <h4>Parameters</h4>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/Deflate.swift#L272-L323">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/Deflate.swift#L272-L323">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
8 changes: 4 additions & 4 deletions docs/Classes/GzipArchive.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L192-L200">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L192-L200">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -288,7 +288,7 @@ <h4>Return Value</h4>
<p>Unarchived data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L219-L224">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L219-L224">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -357,7 +357,7 @@ <h4>Return Value</h4>
<p>Unarchived data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L243-L253">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L243-L253">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -500,7 +500,7 @@ <h4>Return Value</h4>
<p>Resulting archive&rsquo;s data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L292-L384">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L292-L384">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/GzipArchive/Member.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L195">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L195">Show on GitHub</a>
</div>
</section>
</div>
Expand Down Expand Up @@ -248,7 +248,7 @@ <h4>Declaration</h4>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/GzipArchive.swift#L198">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/GzipArchive.swift#L198">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/LZMA.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ <h4>Return Value</h4>
<p>Decompressed data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/LZMA.swift#L49-L54">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/LZMA.swift#L49-L54">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/LZMA2.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ <h4>Return Value</h4>
<p>Decompressed data.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/LZMA2.swift#L46-L53">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/LZMA2.swift#L46-L53">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/TarContainer.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ <h4>Return Value</h4>
<p>Array of <code><a href="../Classes/TarEntry.html">TarEntry</a></code> as an array of <code><a href="../Protocols/ContainerEntry.html">ContainerEntry</a></code>.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.2/Sources/TarContainer.swift#L416-L446">Show on GitHub</a>
<a href="https://github.com/tsolomko/SWCompression/tree/v3.1.3/Sources/TarContainer.swift#L436-L477">Show on GitHub</a>
</div>
</section>
</div>
Expand Down
Loading

0 comments on commit 62f0c80

Please sign in to comment.