Skip to content

Commit

Permalink
Remove Gzip dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobSyndeo committed Apr 18, 2023
1 parent a5ba997 commit 79deb17
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.1.1"),
// .package(url: "https://github.com/1024jp/GzipSwift", from: "5.1.1"),
// .package(url: "https://github.com/vapor/vapor", .upToNextMajor(from: "4.0.0")),
// .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
// .package(url: "https://github.com/themomax/swift-docc-plugin", branch: "add-extended-types-flag")
Expand All @@ -32,7 +32,9 @@ let package = Package(

// 🎆 Ether
.target(name: "Ether",
dependencies: [.product(name: "Gzip", package: "GzipSwift")]
dependencies: [
// .product(name: "Gzip", package: "GzipSwift")
]
// swiftSettings: [.unsafeFlags(["-emit-extension-block-symbols"])]
),
// .testTarget(
Expand Down
1 change: 0 additions & 1 deletion Sources/Ether/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//

import Foundation
import Gzip
import OSLog

/// The core of Ether. All the core functions and types are namespaced under this.
Expand Down
15 changes: 7 additions & 8 deletions Sources/Ether/Error.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Gzip

extension Ether {
public enum Error: Swift.Error, LocalizedError {
Expand All @@ -10,7 +9,7 @@ extension Ether {
case badResponseCode(_ responseCode: Int)
case jsonEncodingFailed(_ error: EncodingError?)
case jsonDecodingFailed(_ error: DecodingError?)
case gZipError(_ error: GzipError)
// case compressionError(_ error: GzipError)
case miscResponseIssue // For unknown/uncaught

public var errorDescription: String? {
Expand Down Expand Up @@ -45,8 +44,8 @@ extension Ether {
}

return message
case let .gZipError(error):
return "An error occurred while trying to gZip the request's data: \(error)"
// case let .compressionError(error):
// return "An error occurred while trying to compress the request's data: \(error)"
case .miscResponseIssue:
return "An unknown miscellaneous error occurred. Please report this to Ether's maintainer."
}
Expand All @@ -68,8 +67,8 @@ extension Ether {
return error?.failureReason
case let .jsonDecodingFailed(error):
return error?.failureReason
case let .gZipError(error):
return "Error kind: \(error.kind). \(error.message)"
// case let .gZipError(error):
// return "Error kind: \(error.kind). \(error.message)"
case .miscResponseIssue:
return nil
}
Expand Down Expand Up @@ -104,8 +103,8 @@ extension Ether {
return error?.recoverySuggestion
case let .jsonDecodingFailed(error):
return error?.recoverySuggestion
case .gZipError(_):
return nil
// case .gZipError(_):
// return nil
case .miscResponseIssue:
return nil
}
Expand Down
9 changes: 4 additions & 5 deletions Sources/Ether/URLRequest+Encoding.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import Gzip

internal extension URLRequest {
/// Creates an instance with the specified `method` and `urlString.
Expand Down Expand Up @@ -61,7 +60,7 @@ internal extension URLRequest {
urlRequest.allHTTPHeaderFields?["Content-Encoding"] = "gzip"

// Set the body of the request to the gZipped JSON data
urlRequest.httpBody = try data.gzipped()
urlRequest.httpBody = try ((data as NSData).compressed(using: .zlib) as Data)
} else {
// Set the body of the request to the raw JSON data
urlRequest.httpBody = data
Expand All @@ -71,9 +70,9 @@ internal extension URLRequest {
if let error = error as? EncodingError {
// If we failed to serialize the parameters into JSON, throw an error
throw Ether.Error.jsonEncodingFailed(error)
} else if let error = error as? GzipError {
// If we failed to zip the JSON, throw an error
throw Ether.Error.gZipError(error)
// } else if let error = error as? GzipError {
// // If we failed to zip the JSON, throw an error
// throw Ether.Error.gZipError(error)
} else {
// Something else went wrong during encoding
throw Ether.Error.jsonEncodingFailed(nil)
Expand Down

0 comments on commit 79deb17

Please sign in to comment.