Revision: 4047
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4047&view=rev
Author:   hofman
Date:     2008-06-20 14:30:19 -0700 (Fri, 20 Jun 2008)

Log Message:
-----------
Compress plist data for EA when the manager doesn't split the EAs and it's too 
long. Decompress plist data when reading if necessary.

Modified Paths:
--------------
    trunk/SkimNotes/SKNExtendedAttributeManager.m

Modified: trunk/SkimNotes/SKNExtendedAttributeManager.m
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.m       2008-06-20 17:02:40 UTC 
(rev 4046)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.m       2008-06-20 21:30:19 UTC 
(rev 4047)
@@ -44,8 +44,8 @@
 
 @interface SKNExtendedAttributeManager (SKNPrivate)
 // private methods to (un)compress data
-- (NSData *)bzip2:(NSData *)data;
-- (NSData *)bunzip2:(NSData *)data;
+- (NSData *)bzip2Data:(NSData *)data;
+- (NSData *)bunzip2Data:(NSData *)data;
 // private method to print error messages
 - (NSError *)xattrError:(int)err forPath:(NSString *)path;
 @end
@@ -261,7 +261,7 @@
         }
         
         [attribute release];
-        attribute = success ? [[self bunzip2:buffer] retain] : nil;
+        attribute = success ? [[self bunzip2Data:buffer] retain] : nil;
     }
     return [attribute autorelease];
 }
@@ -274,6 +274,16 @@
     if (nil == data) {
         if (outError) *outError = [NSError errorWithDomain:SKNErrorDomain 
code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:path, 
NSFilePathErrorKey, error, NSUnderlyingErrorKey, nil]];
     } else {
+        // decompress the data if necessary, we may have compressed when 
setting
+        static NSData *bzipHeaderData = nil;
+        if (nil == bzipHeaderData) {
+            char *h = "BZh";
+            bzipHeaderData = [[NSData alloc] initWithBytes:h length:strlen(h)];
+        }
+        
+        if ([data length] >= [bzipHeaderData length] && [bzipHeaderData 
isEqual:[data subdataWithRange:NSMakeRange(0, [bzipHeaderData length])]])
+            data = [self bunzip2Data:data];
+        
         NSString *errorString;
         plist = [NSPropertyListSerialization propertyListFromData:data 
                                                  
mutabilityOption:NSPropertyListImmutable 
@@ -309,7 +319,7 @@
     if ((options & kSKNXattrNoSplitData) == 0 && namePrefix && [value length] 
> MAX_XATTR_LENGTH) {
                     
         // compress to save space, and so we don't identify this as a plist 
when reading it (in case it really is plist data)
-        value = [self bzip2:value];
+        value = [self bzip2Data:value];
         
         // this will be a unique identifier for the set of keys we're about to 
write (appending a counter to the UUID)
         NSString *uniqueValue = [namePrefix 
stringByAppendingString:UNIQUE_VALUE];
@@ -366,6 +376,10 @@
         [errorString release];
         success = NO;
     } else {
+        // if we don't split and the data is too long, compress the data using 
bzip to save space
+        if (((options & kSKNXattrNoSplitData) != 0 || namePrefix == nil) && 
[data length] > MAX_XATTR_LENGTH)
+            data = [self bzip2Data:data];
+        
         success = [self setExtendedAttributeNamed:attr toValue:data 
atPath:path options:options error:error];
     }
     return success;
@@ -536,7 +550,7 @@
 // implementation modified after 
http://www.cocoadev.com/index.pl?NSDataPlusBzip (removed exceptions)
 //
 
-- (NSData *)bzip2:(NSData *)data;
+- (NSData *)bzip2Data:(NSData *)data;
 {
        int compression = 5;
     int bzret, buffer_size = 1000000;
@@ -570,7 +584,7 @@
        return compressed;
 }
 
-- (NSData *)bunzip2:(NSData *)data;
+- (NSData *)bunzip2Data:(NSData *)data;
 {
        int bzret;
        bz_stream stream = { 0 };


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to