Skip to content

Instantly share code, notes, and snippets.

@jcutrell
Created November 3, 2013 18:31
Show Gist options
  • Save jcutrell/7293249 to your computer and use it in GitHub Desktop.
Save jcutrell/7293249 to your computer and use it in GitHub Desktop.
Translating Objective-C to RubyMotion code
- (NSData *)getDataPartAtOffset:(NSInteger)offset {
__block NSData *chunkData = nil;
if (fileAsset_){
static const NSUInteger BufferSize = PART_SIZE; // 5 MB chunk
ALAssetRepresentation *rep = [fileAsset_ defaultRepresentation];
uint8_t *buffer = calloc(BufferSize, sizeof(*buffer));
NSUInteger bytesRead = 0;
NSError *error = nil;
@try
{
bytesRead = [rep getBytes:buffer fromOffset:offset length:BufferSize error:&error];
chunkData = [NSData dataWithData:[NSData dataWithBytesNoCopy:buffer length:bytesRead freeWhenDone:NO]];
}
@catch (NSException *exception)
{
free(buffer);
chunkData = nil;
// Handle the exception here...
}
free(buffer);
} else {
NSLog(@"failed to retrive Asset");
}
return chunkData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment