In the FileHandle
Class there is a fileHandleWithStandardOutput
method. According to the Documentation, "Conventionally this is a terminal device that receives a stream of data from a program."
What I want to do is read a file per 128 bytes and display it to the terminal, using fileHandleWithStandardOutput
method.
Here's a code fragment of how am I reading it per 128 bytes.
i = 0;
while((i + kBufSize) <= sourceFileSize){
[inFile seekToFileOffset: i];
buffer = [inFile readDataOfLength: kBufSize];
[outFile seekToEndOfFile];
[outFile writeData: buffer];
i += kBufSize + 1;
}
//Get the remaining bytes...
[inFile seekToFileOffset: i ];
buffer = [inFile readDataOfLength: ([[attr objectForKey: NSFileSize]intValue] - i)];
[outFile seekToEndOfFile];
[outFile writeData: buffer];
kBufSize is a preprocessor which is equal to 128;
My Answer:
Set outFile the return NSFileHandle of fileHandleWithStandardOutput
..
I tried it before..but it didn't worked..and now it worked. May be there is something else or something is interfering. Anyways I got the answer now.