Skip to content

Commit

Permalink
Add private GzipError.Kind initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Apr 29, 2023
1 parent 91ec8d1 commit 527bdda
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions Sources/Gzip/Data+Gzip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,35 @@ public struct GzipError: Swift.Error {
internal init(code: Int32, msg: UnsafePointer<CChar>?) {

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))
}
}
}

Expand Down Expand Up @@ -285,7 +291,6 @@ extension Data {

stream.next_in = nil
}

} while (status == Z_OK)

totalIn += stream.total_in
Expand Down

0 comments on commit 527bdda

Please sign in to comment.