From d06cff2a360839c67ce42a695f01bb933ba820c0 Mon Sep 17 00:00:00 2001 From: Eric Kuck Date: Wed, 12 Dec 2018 12:28:27 -0600 Subject: Tons more swiftlint warnings fixed. Still a few remaining. Signed-off-by: Eric Kuck --- WireGuard/WireGuard/ZipArchive/ZipArchive.swift | 31 +++++++++---------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'WireGuard/WireGuard/ZipArchive/ZipArchive.swift') diff --git a/WireGuard/WireGuard/ZipArchive/ZipArchive.swift b/WireGuard/WireGuard/ZipArchive/ZipArchive.swift index 900341e..12cfb69 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.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) -> 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 -- cgit v1.2.3-59-g8ed1b