diff --git a/Sources/Gzip/Data+Gzip.swift b/Sources/Gzip/Data+Gzip.swift index c9f16bb..92ee408 100644 --- a/Sources/Gzip/Data+Gzip.swift +++ b/Sources/Gzip/Data+Gzip.swift @@ -114,29 +114,35 @@ public struct GzipError: Swift.Error { internal init(code: Int32, msg: UnsafePointer?) { self.message = msg.flatMap { String(validatingUTF8: $0) } ?? "Unknown gzip error" + self.kind = Kind(code: code) + } + + + public var localizedDescription: String { + + return self.message + } +} + + +private extension GzipError.Kind { + + init(code: Int32) { - self.kind = { - switch code { + switch code { case Z_STREAM_ERROR: - return .stream + self = .stream case Z_DATA_ERROR: - return .data + self = .data case Z_MEM_ERROR: - return .memory + self = .memory case Z_BUF_ERROR: - return .buffer + self = .buffer case Z_VERSION_ERROR: - return .version + self = .version default: - return .unknown(code: Int(code)) - } - }() - } - - - public var localizedDescription: String { - - return self.message + self = .unknown(code: Int(code)) + } } } @@ -285,7 +291,6 @@ extension Data { stream.next_in = nil } - } while (status == Z_OK) totalIn += stream.total_in