MIME multipart reader/writer code
MIME multipart reader/writer code
- Subject: MIME multipart reader/writer code
- From: Jens Alfke <email@hidden>
- Date: Sun, 05 Feb 2012 19:01:55 -0800
A few weeks ago someone here was asking about code for reading and writing MIME multipart format. It turned out I needed this too, so I implemented some classes to do the job. They handle streaming of large bodies, so you can upload and download large files without taking up much RAM.
They’re part of my TouchDB project, not a standalone framework, so they’ll take a little bit of work to adapt into your code, but not too much.
The git repo is here: https://github.com/couchbaselabs/TouchDB-iOS
Source files: https://github.com/couchbaselabs/TouchDB-iOS/tree/master/Source
The relevant classes are
TDMultipartDownloader (for downloads)
TDMultipartReader (for uploads)
TDMultiInputStream (base class of TDMultipartReader)
TDMultipartReader is a subclass of NSInputStream, which may seem weird for something that uploads, but that’s because it’s meant to be connected to NSURLRequest.HTTPBodyStream. It makes sense if you think of the NSURLConnection reading the bytes from the stream and transmitting them over HTTP.
FYI, if you want to use any kind of custom NSInputStream subclass with HTTPBodyStream, you’ll run into some frustrating CFNetwork bugs. I figured out how to work around them and TDMultiInputStream shows how.
All of this is Apache 2 licensed (very liberal).
You’re welcome :)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden