problem with dataWithContentsOfFile on Lion
problem with dataWithContentsOfFile on Lion
- Subject: problem with dataWithContentsOfFile on Lion
- From: Wilker <email@hidden>
- Date: Thu, 21 Jul 2011 15:01:18 -0300
Hi guys,
I updated to Lion yesterday, but I'm having an issue now with [NSData
dataWithContentsOfFile]
This code is to generate a hash based on 64kb of start and 64kb of end from
a file:
+ (NSString *)generateHashFromPath:(NSString *)path
{
const NSUInteger CHUNK_SIZE = 65536;
NSError *error = nil;
NSData *fileData = [NSData dataWithContentsOfFile:path options:
NSDataReadingMapped | NSDataReadingUncached error:&error];
if (error) {
return nil;
}
const uint8_t* buffer = [fileData bytes];
NSUInteger byteLength = [fileData length];
NSUInteger byteOffset = 0;
if (byteLength > CHUNK_SIZE) {
byteOffset = byteLength - CHUNK_SIZE;
byteLength = CHUNK_SIZE;
}
CC_MD5_CTX md5;
CC_MD5_Init(&md5);
CC_MD5_Update(&md5, buffer, (CC_LONG) byteLength);
CC_MD5_Update(&md5, buffer + byteOffset, (CC_LONG) byteLength);
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5_Final(digest, &md5);
NSMutableString *hexDigest = [NSMutableString stringWithCapacity:
CC_MD5_DIGEST_LENGTH * 2];
for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
[hexDigest appendFormat:@"x", digest[i]];
}
return [hexDigest lowercaseString];
}
Before Lion, it really works well and fast, even on Wifi external drive
(through Airport Extreme), but now it get's really slow... I did some
checks, and now its reading the entire file... instead of just read 128kb
(start and end). Anyone have an ideia on why its happening now? And how to
make it works as before on Snow Leopard?
---
Wilker LĂșcio
http://about.me/wilkerlucio/bio
Kajabi Consultant
+55 81 82556600
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden