I want to use an NSOutputStream to accumulate data, then when finished, create an NSData object with the contents. I can do it when the output stream is based on a file, as follows:
NSString *tmpDirectory = NSTemporaryDirectory();
NSString *filePath = [tmpDirectory stringByAppendingPathComponent:@"tempfile"];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
NSOutputStream *outputStream = [[NSOutputStream alloc] initToFileAtPath:filePath append:NO]; [outputStream open];
// fill the output stream here
NSData *contents = [NSData dataWithContentsOfFile:filePath];
[outputStream close];
I want the 'contents' variable filled without the temp file being created. Can I do this all in memory? I don't see API for that in the NSOutputStream documentation.