Re: piped unzip (and this time it's not the wrong codesnipper)
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: "b.bum" <email@hidden>
- Date: Thu, 19 Feb 2004 13:26:14 -0800
On Feb 19, 2004, at 4:46 AM, Stefan Fisk wrote:
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 =)
You are reading from a Task through a Pipe. That means that you have
to deal with tasking and I/O issues. Because the data is coming from
a Pipe, the data is not available all at once. Furthermore, the
background process is going to continue barfing up data as it runs.
Also, your code reads as:
NSData *data = [[outputPipe fileHandleForReading]
readDataToEndOfFile];
[zip waitUntilExit];
If the zip process hasn't finish executing, then all of the data will
not have been written to the pipe. You want to -waitUntilExit before
trying to read all the data!
But if you do that, then your app is very likely going to deadlock
immediately after the pipe you have connected to Standard Output on the
zip NSTask is full.
So you need to consume the data as it is produced.
In other words, you really do need to -readInBackgroundAndNotify: in
the fashion that the previous poster indicated.
Note that calling -waitUntilExit without -readInBackgroundAndNotify:
will work without deadlocking in the case where the amount of data
produced by the task is less than the buffer size of the pipe.
b.bum
_______________________________________________
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.