aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-12 12:28:27 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-12 12:28:27 -0600
commitd06cff2a360839c67ce42a695f01bb933ba820c0 (patch)
tree3aa166de8c75947345b9bfb8398ee8b7c6b581c7 /WireGuard/WireGuard/ZipArchive/ZipArchive.swift
parentAdded swiftlint and fixed all errors (and a bunch, but not all, warnings) (diff)
downloadwireguard-apple-d06cff2a360839c67ce42a695f01bb933ba820c0.tar.xz
wireguard-apple-d06cff2a360839c67ce42a695f01bb933ba820c0.zip
Tons more swiftlint warnings fixed. Still a few remaining.
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/WireGuard/ZipArchive/ZipArchive.swift')
-rw-r--r--WireGuard/WireGuard/ZipArchive/ZipArchive.swift31
1 files changed, 11 insertions, 20 deletions
diff --git a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
index 900341ec..12cfb698 100644
--- a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
+++ b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift
@@ -9,7 +9,7 @@ enum ZipArchiveError: WireGuardAppError {
case badArchive
func alertText() -> (String, String)? {
- switch (self) {
+ switch self {
case .cantOpenInputZipFile:
return ("Unable to read zip archive", "The zip archive could not be read.")
case .cantOpenOutputZipFileForWriting:
@@ -49,15 +49,11 @@ class ZipArchive {
defer {
unzClose(zipFile)
}
- guard (unzGoToFirstFile(zipFile) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzGoToFirstFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
var resultOfGoToNextFile: Int32
repeat {
- guard (unzOpenCurrentFile(zipFile) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzOpenCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
let bufferSize = 16384 // 16 KiB
var fileNameBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
@@ -68,38 +64,33 @@ class ZipArchive {
dataBuffer.deallocate()
}
- guard (unzGetCurrentFileInfo64(zipFile, nil, fileNameBuffer, UInt(bufferSize), nil, 0, nil, 0) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzGetCurrentFileInfo64(zipFile, nil, fileNameBuffer, UInt(bufferSize), nil, 0, nil, 0) == UNZ_OK else { throw ZipArchiveError.badArchive }
let lastChar = String(cString: fileNameBuffer).suffix(1)
let isDirectory = (lastChar == "/" || lastChar == "\\")
let fileURL = URL(fileURLWithFileSystemRepresentation: fileNameBuffer, isDirectory: isDirectory, relativeTo: nil)
- if (!isDirectory && requiredFileExtensions.contains(fileURL.pathExtension)) {
+ if !isDirectory && requiredFileExtensions.contains(fileURL.pathExtension) {
var unzippedData = Data()
var bytesRead: Int32 = 0
repeat {
bytesRead = unzReadCurrentFile(zipFile, dataBuffer, UInt32(bufferSize))
- if (bytesRead > 0) {
+ if bytesRead > 0 {
let dataRead = dataBuffer.withMemoryRebound(to: UInt8.self, capacity: bufferSize) {
- (buf: UnsafeMutablePointer<UInt8>) -> Data in
- return Data(bytes: buf, count: Int(bytesRead))
+ return Data(bytes: $0, count: Int(bytesRead))
}
unzippedData.append(dataRead)
}
- } while (bytesRead > 0)
+ } while bytesRead > 0
results.append((fileBaseName: fileURL.deletingPathExtension().lastPathComponent, contents: unzippedData))
}
- guard (unzCloseCurrentFile(zipFile) == UNZ_OK) else {
- throw ZipArchiveError.badArchive
- }
+ guard unzCloseCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
resultOfGoToNextFile = unzGoToNextFile(zipFile)
- } while (resultOfGoToNextFile == UNZ_OK)
+ } while resultOfGoToNextFile == UNZ_OK
- if (resultOfGoToNextFile == UNZ_END_OF_LIST_OF_FILE) {
+ if resultOfGoToNextFile == UNZ_END_OF_LIST_OF_FILE {
return results
} else {
throw ZipArchiveError.badArchive