From 4bd4ec56d70dda3116099c380a9780d5e4737610 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sat, 18 Oct 2025 07:50:28 -0300 Subject: [PATCH 1/2] feat: rename package and add support for iOS 13, macOS 10.15 --- Package.swift | 12 ++++++------ .../Interface/MultipartFormData+HTTPBody.swift | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index b40f230..e5ca67e 100644 --- a/Package.swift +++ b/Package.swift @@ -4,13 +4,13 @@ import PackageDescription let package = Package( - name: "HTTPClient", + name: "swift-http-client", platforms: [ - .iOS(.v16), - .macOS(.v13), - .tvOS(.v16), - .watchOS(.v9), - .visionOS(.v1), + .iOS(.v13), + .macCatalyst(.v13), + .macOS(.v10_15), + .watchOS(.v6), + .tvOS(.v13), ], products: [ // Products define the executables and libraries a package produces, making them visible to other packages. diff --git a/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift b/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift index a304d35..665502a 100644 --- a/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift +++ b/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift @@ -59,7 +59,6 @@ extension HTTPBody { let fileHandle = try FileHandle(forReadingFrom: fileURL) let stream = AsyncThrowingStream { continuation in - continuation.onTermination = { _ in try? fileHandle.close() if deleteOnDeallocation { @@ -68,8 +67,12 @@ extension HTTPBody { } do { - while let byte = try fileHandle.read(upToCount: 64 * 1024) { // 64 KB chunks - continuation.yield(ByteChunk(byte)) + while true { + let bytes = fileHandle.readData(ofLength: 64 * 1024) // 64 KB chunks + if bytes.isEmpty { + break + } + continuation.yield(ByteChunk(bytes)) } continuation.finish() } catch { From 38bfd87042cfaa3ebe159d06674cedcb5b3d0fe2 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Sat, 18 Oct 2025 07:53:44 -0300 Subject: [PATCH 2/2] fix: remove try/catch --- .../Interface/MultipartFormData+HTTPBody.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift b/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift index 665502a..8fccc0a 100644 --- a/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift +++ b/Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift @@ -66,18 +66,14 @@ extension HTTPBody { } } - do { - while true { - let bytes = fileHandle.readData(ofLength: 64 * 1024) // 64 KB chunks - if bytes.isEmpty { - break - } - continuation.yield(ByteChunk(bytes)) + while true { + let bytes = fileHandle.readData(ofLength: 64 * 1024) // 64 KB chunks + if bytes.isEmpty { + break } - continuation.finish() - } catch { - continuation.finish(throwing: error) + continuation.yield(ByteChunk(bytes)) } + continuation.finish() } self.init(stream, length: length.map { .known(Int64($0)) } ?? .unknown)