Resource fork & metadata - max size?
Resource fork & metadata - max size?
- Subject: Resource fork & metadata - max size?
- From: Karl Moskowski <email@hidden>
- Date: Tue, 6 May 2008 13:43:16 -0400
I've been working on an Objective-C Zip utilities class that wraps
around minizip. It works and it's mostly compatible with archives
produced by Leopard's Archive Utility.
I was able to create AppleDouble ._ files using Uli Kusterer's
UKXattrMetadataStore class a slightly hacked version of the
GMAppleDouble class from MacFUSE. (The current GMAppleDouble in the
project has a method for creating an NSData object from all the
entries, but no inverse method; I added a method to do so, plus an
accessor for the entries and I moved the entry interface to the public
header. I filed a bug at MacFUSE, but it's been deemed a low priority
enhancement request.)
To save a file's resource fork and extended attributes:
NSString *path = @"/path/to/a/file.ext";
NSString *appleDoublePath = @"/path/to/a/._file.ext";
GMAppleDouble *appleDouble = [GMAppleDouble appleDouble];
NSData *finderInfo = [UKXattrMetadataStore dataForKey:[NSString
stringWithCString:XATTR_FINDERINFO_NAME] atPath:path traverseLink:NO];
NSData *resourceFork = [UKXattrMetadataStore dataForKey:[NSString
stringWithCString:XATTR_RESOURCEFORK_NAME] atPath:path traverseLink:NO];
if (finderInfo.length > 0) [appleDouble
addEntryWithID:DoubleEntryFinderInfo data:finderInfo];
if (resourceFork.length > 0) [appleDouble
addEntryWithID:DoubleEntryResourceFork data:resourceFork];
NSData *appleDoubleData = [appleDouble data];
[appleDoubleData writeToFile:appleDoublePath atomically:YES];
To restore a resource fork and extended attributes to a file:
NSData * appleDoubleData = [NSData dataWithContentsOfFile:
appleDoublePath];
GMAppleDouble *appleDouble = [[GMAppleDouble alloc]
initWithData:appleDoubleData];
if ([appleDouble entries] && [appleDouble entries].count > 0) {
for (GMAppleDoubleEntry *entry in [appleDouble entries]) {
switch ([entry entryID]) {
case DoubleEntryFinderInfo:
[UKXattrMetadataStore setData:[entry data] forKey:[NSString
stringWithCString:XATTR_FINDERINFO_NAME] atPath:path traverseLink:NO];
break;
case DoubleEntryResourceFork:
[UKXattrMetadataStore setData:[entry data] forKey:[NSString
stringWithCString:XATTR_RESOURCEFORK_NAME] atPath:path traverseLink:NO];
break;
default:
break;
}
}
}
My question is, how big can the resource fork and Finder info get? Is
reading them into an in-memory NSData object feasible?
BTW, if anyone's interested in my still-rough source code (Leopard-
only, garbage collection required), let me know and I'd be happy to
pass it along.
----
Karl Moskowski <email@hidden>
Voodoo Ergonomics Inc. <http://voodooergonomics.com/>
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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