• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: piped unzip (and this time it's not the wrong codesnipper)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: piped unzip (and this time it's not the wrong codesnipper)


  • Subject: Re: piped unzip (and this time it's not the wrong codesnipper)
  • From: Stefan Fisk <email@hidden>
  • Date: Thu, 19 Feb 2004 13:46:43 +0100

No that's not it, the documentation for NSPipe and NSFileHandle clearly
specifies that if you get the filehandle of a pipe and then call
readToEndOfFile on it it reads until it receives EOF.
And i've gotten it to work before, which pisses me off even more,
because then i got it on the first try =)

2004-02-19 kl. 12.48 skrev p3consulting:

> It looks like calling readDataToEndOfFile doesn't do what you expect:
>
> you probably mean "read data until you see an EOF"
> but the fact that readDataOfLength is the source of the exception make
> me think that
> what the readDataToEndOfFile actually does is
> "seek to EOF to know the size of the NSData to allocate and then read
> the data"
>
> and of course "seeking" on a pipe doesn't work !
>
> you should use readInBackgroundAndNotify instead
> and install an observer for NSFileHandleReadCompletionNotification
> notification
>
> roughly (not tested) something like this:
>
> - (void)launchTaskForKey:(NSString *)key
> {
> fUnzipTask = [[NSTask alloc] init]; // fUnzipTask should be an
> instance variable of your class
> fData = [NSMutableData data] ; // fData - another instance variable
> of your class - will accumulate the data read from the pipe
>
> [zip setArguments:[NSArray arrayWithObjects:@"-p", path, key,
> nil]];
> [zip setLaunchPath:@"/usr/bin/unzip"];
> NSPipe *outputPipe = [NSPipe pipe];
> [zip setStandardOutput:outputPipe];
>
> [[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(getData:)
> name: NSFileHandleReadCompletionNotification
> object: [[zip standardOutput] fileHandleForReading]];
>
> [[NSNotificationCenter defaultCenter] addObserver:self
> selector:@selector(taskCompleted:) name:NSTaskDidTerminateNotification
> object:zip];
>
> [[[zip standardOutput] fileHandleForReading]
> readInBackgroundAndNotify];
>
> [zip launch];
> }
>
> - (void)taskCompleted: (NSNotification *)aNotification
> {
> // here you know fData contains all the data you want
> // you can release fUnzipTask now
> }
>
> - (void) getData: (NSNotification *)aNotification
> {
> NSData *data = [[aNotification userInfo]
> objectForKey:NSFileHandleNotificationDataItem];
>
> if ([data length])
> {
> [fData appendData:data];
> }
> else if (![fUnzipTask isRunning]) {
> [fUnzipTask terminate];
> return ;
> }
>
> if ([fUnzipTask isRunning])
> {
> [[aNotification object] readInBackgroundAndNotify];
> }
> else
> {
> [fUnzipTask terminate];
> }
> }
>
> Pascal Pochet
> email@hidden
>
> On 18 fivr. 2004, at 21:46, Stefan Fisk wrote:
>
>> hi again all!
>>
>> i already knew that i had to clear the pipe, but even when i do that
>> it doesn't work, i just get: Exception raised during posting of
>> notification. Ignored. exception: *** -[NSConcreteFileHandle
>> readDataOfLength:]: Interrupted system call
>>
>> - (NSData *)dataForKey:(NSString *)key {
>> NSTask *zip = [[[NSTask alloc] init] autorelease];
>> [zip setArguments:[NSArray arrayWithObjects:@"-p", path, key,
>> nil]];
>> [zip setLaunchPath:@"/usr/bin/unzip"];
>> NSPipe *outputPipe = [NSPipe pipe];
>> [zip setStandardOutput:outputPipe];
>> [zip launch];
>>
>> NSData *data = [[outputPipe fileHandleForReading]
>> readDataToEndOfFile];
>> [zip waitUntilExit];
>>
>> if ([zip terminationStatus] != 0)
>> return nil;
>> else
>> return data;
>> }
>>
>> this is all really bugging me to no end, i know it's easy =)
>> _______________________________________________
>> 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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: piped unzip (and this time it's not the wrong codesnipper)
      • From: "b.bum" <email@hidden>
References: 
 >piped unzip (and this time it's not the wrong codesnipper) (From: Stefan Fisk <email@hidden>)

  • Prev by Date: Re: NSString categories
  • Next by Date: comboBox menu choice validation
  • Previous by thread: piped unzip (and this time it's not the wrong codesnipper)
  • Next by thread: Re: piped unzip (and this time it's not the wrong codesnipper)
  • Index(es):
    • Date
    • Thread