Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension FormDataDecoder.Decoder: SingleValueDecodingContainer {

let decoded =
switch T.self {
case let multipartDecodable as any MultipartPartDecodable.Type:
case let multipartDecodable as any MultipartPartDecodable<Body>.Type:
try multipartDecodable.init(multipart: part) as? T
case is MultipartPart<Body>.Type:
part as? T
Expand Down
4 changes: 2 additions & 2 deletions Sources/MultipartKit/MultipartPartConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ public protocol MultipartPartEncodable<Body> {
}

/// A type that can be converted from a `MultipartPart`.
public protocol MultipartPartDecodable {
public protocol MultipartPartDecodable<Body> {
associatedtype Body: MultipartPartBodyElement

init(multipart: MultipartPart<some MultipartPartBodyElement>) throws
init(multipart: MultipartPart<Body>) throws
}

/// A type that can be converted to and from a `MultipartPart`.
Expand Down
2 changes: 1 addition & 1 deletion Tests/MultipartKitTests/FormDataDecodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ struct FormDataDecodingTests {
age: 4,
image: File(filename: "droplet.png", data: Array("<contents of image>".utf8)))

let message = ArraySlice(
let message = Array(
"""
--helloBoundary\r
Content-Disposition: form-data; name="name"\r
Expand Down
10 changes: 5 additions & 5 deletions Tests/MultipartKitTests/Utilities/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct File: Codable, Equatable, MultipartPartConvertible {
typealias Body = [UInt8]

let filename: String
let data: [UInt8]
let data: Body

enum MultipartError: Error {
case invalidFileName
Expand All @@ -21,7 +21,7 @@ struct File: Codable, Equatable, MultipartPartConvertible {

init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let data = try container.decode([UInt8].self, forKey: .data)
let data = try container.decode(Body.self, forKey: .data)
let filename = try container.decode(String.self, forKey: .filename)
self.init(filename: filename, data: data)
}
Expand All @@ -32,15 +32,15 @@ struct File: Codable, Equatable, MultipartPartConvertible {
try container.encode(self.filename, forKey: .filename)
}

var multipart: MultipartPart<[UInt8]> {
var multipart: MultipartPart<Body> {
let part = MultipartPart(
headerFields: [.contentDisposition: "form-data; name=\"image\"; filename=\"\(filename)\""],
body: self.data
)
return part
}

init(multipart: MultipartPart<some MultipartPartBodyElement>) throws {
init(multipart: MultipartPart<Body>) throws {
let contentDisposition = multipart.headerFields[.contentDisposition] ?? ""
let filenamePattern = "filename=\"([^\"]+)\""
let filename: String
Expand All @@ -54,6 +54,6 @@ struct File: Codable, Equatable, MultipartPartConvertible {
throw MultipartError.invalidFileName
}

self.init(filename: filename, data: Array(multipart.body))
self.init(filename: filename, data: multipart.body)
}
}
Loading