-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using paths as keys #8
Comments
The other option is to just encode the key when making the path. This solves for any characters that are not safe in file names. I modified static inline NSString* cachePathForKey(NSString* key) {
NSString *encodeKey = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)key,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
return [EGOCacheDirectory() stringByAppendingPathComponent:encodeKey];
} |
If you're using only paths as key, the fix you provided is great but in my case a lot of keys wasn't paths (they was regular keys) so using a function like CFURLCreateStringByAddingPercentEscapes has a real performance cost. So I use an equivalent function as yours but only on demand ;-) |
Can you post an example? |
Just extract your encoding function out of the
|
As it is, It's not possible to use path as key because directories contained in path doesn't exists.
maybe something like this may fix the issue
[[NSFileManager defaultManager] createDirectoryAtPath:[[path stringByExpandingTildeInPath] stringByDeletingLastPathComponent]
withIntermediateDirectories:YES
attributes:nil
error:nil];
[data writeToFile:path atomically:YES];
}
I don't wanted to alter the original file (thus I can update it without asking me if I had to merge any modifications) so I changed my keys by replacing path separator by # ;-)
Cheers.
The text was updated successfully, but these errors were encountered: