lukeredpath / LRResty

Yet another Objective-C REST client library, inspired by Ruby's restclient gem.
http://projects.lukeredpath.co.uk/resty/
461 stars 56 forks source link

Large file streaming downloads fail #20

Closed karnlund closed 12 years ago

karnlund commented 13 years ago

When using the streaming get method to download a 2.6 gigabyte sized file, LRResty fails with out of memory errors, because it is not releasing each block of data after it is passed to the onData block. I would like to stream the data to an NSFileHandle that is opened for writing.

- (void)restyClientWillPerformRequest:(LRRestyClient *)client {
    [[NSFileManager defaultManager] createFileAtPath:[self archiveFilePath]
                                            contents:nil
                                          attributes:nil];
    self.fh = [NSFileHandle fileHandleForWritingAtPath: [self archiveFilePath]];
}

- (void)requestDataFile {
    [[LRResty client] setDelegate:self];
    [[LRResty client] get:[self archiveURL]
                                  onData:^(NSData *data, BOOL *cancel) {
                                      [fh writeData:data];
                                  } onError:^(NSError *error) {
                                      [fh closeFile];
                                  }
}

malloc: * mmap(size=2337423360) failed (error code=12) * error: can't allocate region *\ set a breakpoint in malloc_error_break to debug

lukeredpath commented 12 years ago

Let me know if this doesn't solve your problem.