I use the old code shown below to read a resource fork file, it works fine but contains many deprecated API (under 10.8) so I want to convert it.
The documentation for FSReadFork says
Deprecation Statement
To read the data fork at the Foundation layer, use NSFileHandle APIs instead.
But using NSFileHandle doesn't work, someone can point me in the right direction?
+ (NSData*)old_readResForkFile:(NSString*)path {
FSRef theFsRef;
OSStatus status = FSPathMakeRef((const UInt8 *)[path fileSystemRepresentation], &theFsRef, NULL);
if (status != noErr) {
return nil;
}
ResFileRefNum resFileRef = FSOpenResFile(&theFsRef, fsRdPerm);
if (resFileRef < 0) {
return nil;
}
NSMutableData* theData = nil;
ByteCount theByteCount;
SInt64 theForkSize;
if (FSGetForkSize(resFileRef, &theForkSize) == noErr && theForkSize <= UINT_MAX) {
theData = [NSMutableData dataWithLength:theForkSize];
if (FSReadFork(resFileRef, fsFromStart, 0, theForkSize, [theData mutableBytes], &theByteCount) != noErr || (SInt64)theByteCount != theForkSize ) {
theData = nil;
}
}
CloseResFile(resFileRef);
return theData;
}