Problem with loop in compression Step
Problem with loop in compression Step
- Subject: Problem with loop in compression Step
- From: "Erik J. Barzeski" <email@hidden>
- Date: Sat, 23 Mar 2002 10:46:15 -0500
Hi,
Possible solution, will test more, but it seems moving [gzip launch]; to
before the NS_DURING has solved the problem. Again, I'll do more testing,
but it seems to work fine currently:
2002-03-23 10:44:24.350 MeMail[12872] Data Length: 186645
2002-03-23 10:44:24.373 MeMail[12872] booya
P.S. The file size is pretty darn teeny.
941881 -rw-r--r-- 1 iacas wheel 1468 Mar 23 10:44 Untitled2.nodemap
Hi,
One of the features of an app I'm working on is compression before saving
the file. It's an AI type app with a bunch of nodes, vectors, etc. GZIP can
compress an 8 MB file to 190k, so, I figured why not do this within the app
itself?
The _decompression_ algorithm works (and is a fair amount shorter than
this).
The app GWOD's (Gay Wheel of Death's) during the [inHandle write
Data:data];
line. An NSLog() after that line is called very rarely - and only when we
have a few nodes. Any more than a certain number (usually around 103) and
the thing GWODs on us.
I put a Data Length: NSLog() before the problem line, and "booya" after to
signify that it "made it past" that line. Here's the interesting output:
2002-03-23 09:43:27.662 MeMail[12794] Data Length: 8158
2002-03-23 09:43:27.662 MeMail[12794] booya
2002-03-23 09:43:29.595 MeMail[12794] Data Length: 8196
// GWOD occurs here.... No booya is reached
Please CC me off-list as I get the digest and won't see any replies for
awhile otherwise.
(those are bytes of course). Anything greater than
Here's the code:
{
NSMutableData *fileData = [NSMutableData data];
NSData *data = [NSArchiver archivedDataWithRootObject:ourRootObj];
NSTask *gzip = [[NSTask alloc] init];
NSPipe *inPipe = [NSPipe pipe];
NSPipe *outPipe = [NSPipe pipe];
NSFileHandle *inHandle = [inPipe fileHandleForWriting];
NSFileHandle *outHandle = [outPipe fileHandleForReading];
// set up NSTask params
[gzip setLaunchPath:[[NSBundle mainBundle] pathForResource:@"gzip"
ofType:nil]];
[gzip setArguments:[NSArray array]];
[gzip setStandardInput:inPipe];
[gzip setStandardOutput:outPipe];
// write data to stdin pipe
NS_DURING
// problem line right here:
[inHandle write
Data:data];
[inHandle closeFile];
NS_HANDLER
NSLog( @"Exception occured: %@", [localException description] );
return nil;
NS_ENDHANDLER
// run gzip and return compressed data
[gzip launch];
while((data=[outHandle availableData]) && [data length])
{
[fileData append
Data:data];
}
[gzip release];
return fileData;
}
--
Best wishes,
Erik J. Barzeski
Rules? We don't have rules. We're trying to accomplish something!
*******************************************************************
Email: erik@(anything below)
AIM: iacas ICQ: 8186546
http://barzeski.com/ http://weims.net/
http://techstra.net/ http://cocoadevcentral.com/
http://soundsetcentral.com/ http://applescriptcentral.com/
*******************************************************************
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.