Skip to content

Instantly share code, notes, and snippets.

@iluvcapra
Created January 12, 2010 18:59
Show Gist options
  • Save iluvcapra/275485 to your computer and use it in GitHub Desktop.
Save iluvcapra/275485 to your computer and use it in GitHub Desktop.
-(NSData *)dataFromResource:(OSType)ident
resID:(NSInteger)idnum
inFile:(NSString *)path {
FSRef feRef;
FSPathMakeRef((UInt8 *)[path fileSystemRepresentation], &feRef, NULL);
ResFileRefNum refFileNum = FSOpenResFile(&feRef, fsRdPerm);
UseResFile(refFileNum);
Handle resHandle = Get1Resource(ident, idnum);
long size = GetResourceSizeOnDisk(resHandle);
NSData *retVal = nil;
if (size > 0) {
retVal = [NSData dataWithBytes:*resHandle length:size];
}
CloseResFile(refFileNum);
return retVal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment