Skip to content
Merged
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
12 changes: 6 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 6 additions & 7 deletions Sources/HTTPClient/Interface/MultipartFormData+HTTPBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,21 @@ extension HTTPBody {
let fileHandle = try FileHandle(forReadingFrom: fileURL)

let stream = AsyncThrowingStream<ByteChunk, any Error> { continuation in

continuation.onTermination = { _ in
try? fileHandle.close()
if deleteOnDeallocation {
try? FileManager.default.removeItem(at: fileURL)
}
}

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)
Expand Down
Loading