Created
November 3, 2013 18:31
-
-
Save jcutrell/7293249 to your computer and use it in GitHub Desktop.
Translating Objective-C to RubyMotion code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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