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..8fccc0a 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 { @@ -67,14 +66,14 @@ 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.finish() - } catch { - continuation.finish(throwing: error) + continuation.yield(ByteChunk(bytes)) } + continuation.finish() } self.init(stream, length: length.map { .known(Int64($0)) } ?? .unknown)