mirror of
https://github.com/tsolomko/SWCompression.git
synced 2026-06-23 14:56:41 +00:00
[TAR] Remove compatibility with pre-Swift 5.2 compilers
This commit is contained in:
+15
-27
@@ -146,45 +146,33 @@ public struct TarReader {
|
||||
}
|
||||
|
||||
private func getOffset() throws -> UInt64 {
|
||||
#if compiler(<5.2)
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
return try handle.offset()
|
||||
} else {
|
||||
return handle.offsetInFile
|
||||
#else
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
return try handle.offset()
|
||||
} else {
|
||||
return handle.offsetInFile
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private func set(offset: UInt64) throws {
|
||||
#if compiler(<5.2)
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
try handle.seek(toOffset: offset)
|
||||
} else {
|
||||
handle.seek(toFileOffset: offset)
|
||||
#else
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
try handle.seek(toOffset: offset)
|
||||
} else {
|
||||
handle.seek(toFileOffset: offset)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private func getData(size: Int) throws -> Data {
|
||||
assert(size >= 0, "TarReader.getData(size:): negative size.")
|
||||
guard size > 0
|
||||
else { return Data() }
|
||||
#if compiler(<5.2)
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
guard let chunkData = try handle.read(upToCount: size)
|
||||
else { throw DataError.truncated }
|
||||
return chunkData
|
||||
} else {
|
||||
// Technically, this can throw NSException, but since it is ObjC exception we cannot handle it in Swift.
|
||||
return handle.readData(ofLength: size)
|
||||
#else
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
guard let chunkData = try handle.read(upToCount: size)
|
||||
else { throw DataError.truncated }
|
||||
return chunkData
|
||||
} else {
|
||||
// Technically, this can throw NSException, but since it is ObjC exception we cannot handle it in Swift.
|
||||
return handle.readData(ofLength: size)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -133,18 +133,13 @@ public struct TarWriter {
|
||||
}
|
||||
|
||||
private func write(_ data: Data) throws {
|
||||
#if compiler(<5.2)
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
try handle.write(contentsOf: data)
|
||||
try handle.synchronize()
|
||||
} else {
|
||||
handle.write(data)
|
||||
handle.synchronizeFile()
|
||||
#else
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
try handle.write(contentsOf: data)
|
||||
try handle.synchronize()
|
||||
} else {
|
||||
handle.write(data)
|
||||
handle.synchronizeFile()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,15 +8,11 @@ import Foundation
|
||||
extension FileHandle {
|
||||
|
||||
func closeCompat() throws {
|
||||
#if compiler(<5.2)
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
try self.close()
|
||||
} else {
|
||||
self.closeFile()
|
||||
#else
|
||||
if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
|
||||
try self.close()
|
||||
} else {
|
||||
self.closeFile()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user