vapor / http

🚀 Non-blocking, event-driven HTTP built on Swift NIO.
MIT License
240 stars 65 forks source link

streaming multipart #357

Closed tanner0101 closed 5 years ago

tanner0101 commented 5 years ago

Fixes #355

let parser = MultipartParser(boundary: "12345")

var parts: [MultipartPart] = []
var headers: [String: String] = [:]
var body: String = ""

parser.onHeader = { (field, value) in
    headers[field] = value
}
parser.onBody = { new in
    body += new.readString(length: new.readableBytes)!
}
parser.onPartComplete = {
    let part = MultipartPart(headers: headers, body: body)
    headers = [:]
    body = ""
    parts.append(part)
}

for chunk in data.chunked(by: i) {
    try parser.execute(.init(chunk))
}
print(parts)
penny-coin commented 5 years ago

Hey @tanner0101, you just merged a pull request, have a coin!

You now have 1181 coins.