AFNetworking/AFNetworking — pull request #270 by steipete (2012-03-25 08:56:00+00:00)
Title: Add support for downloading files via streaming and support for resuming partial downloads

I believe AFNetworking is missing a base class called AFDownloadRequestOperation, as we support even XML, but not such a basic operation like file downloads. Further, while file downloads are trivial, streamed file downloads can be a little tricky, especially with downloading them into a temporary directory and only moving once the download was successful.

As a bonus, this class supports [Content-Range](http://tools.ietf.org/html/rfc2616#section-14.16) and is able to resume partial downloads (as long as the temporary file is still there).

I use it here in my upcoming project and it's very useful (e.g. for downloading larger pdf file).
I also exposed totalContentLength and offsetContentLength, so the a progressView can show the actual download progress. For convenience, there is also a new block called "progressiveDownloadBlock" because we might wanna show a progressView that displays such a partially downloaded progress correctly.

[downloadOperation_ setProgressiveDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
float progress = totalBytesReadForFile/(float)totalBytesExpectedToReadForFile;
dispatch_async(dispatch_get_main_queue(), ^{
[self.progressView setProgress:progress animated:YES];
});

As a change on AFURLConnectionOperation, this removes the restriction of files that are greater than 2GB. This is a discussable change when just looking in an iOS context, but makes sense because AFNetworking also supports the Mac. (NSInteger translates to long, while we now use long long, which should be more than enough)
An indicator that this is The Right Thing™ is also that previously we down-casted NSURLResponse's expectedContentLength ( (NSInteger)self.response.expectedContentLength ), which already is long long.

I had this code for quite some time now, but finally came around giving a major overhaul - I really want to see this inside AFN directly. This could potentially help a lot of people, it's also the last step of removing asi-http-request in my [pspdfkit example project](https://github.com/steipete/PSPDFKit-Demo/tree/master/Examples/PSPDFKitExample).