While Justin answered my question, I was using NSFileWrapper
internally so I couldn't always use contentsEqualAtPath:andPath:
.
In case it helps anyone, here's what I wrote to compare the contents of a NSFileWrapper
to the contents of a file:
- (BOOL) contentsOfFileWrapper:(NSFileWrapper*)fileWrapper equalContentsAtPath:(NSString*)path {
NSDictionary *fileAttrs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
NSUInteger fileSize = [attrs fileSize];
NSUInteger fileWrapperSize = [fileWrapper.fileAttributes fileSize]; // Will return zero if the file wrapper hasn't been written
if (fileWrapperSize > 0 && fileSize != fileWrapperSize) return NO;
NSData *fileData = [NSData dataWithContentsOfURL:fileURL];
NSData *fileWrapperData = fileWrapper.regularFileContents;
return [fileData isEqualToData:resourceData];
}
As Justin suggested, I'm only using the above method if I'm unable to reconstruct the path of the file wrapper. If I can, then I use contentsEqualAtPath:andPath:
.
contentsEqualAtPath:
equivalent forNSFileWrapper
? – Symbolics