Re: / NSFileHandle in rtf and mpg files /
Re: / NSFileHandle in rtf and mpg files /
- Subject: Re: / NSFileHandle in rtf and mpg files /
- From: Clark Cox <email@hidden>
- Date: Tue, 8 Jun 2004 15:58:13 -0400
On Jun 08, 2004, at 12:48, TM Systems::Luis Pojan wrote:
>
I'm trying to read a rtf file. My code is more or less like this ((I'm
>
not including parts of the code like obtaining the file from the panel
>
and editing the path)):
>
>
NSString *scriptFile;
>
NSFileHandle *scriptFileHandle;
>
NSData *theData;
>
unsigned char dataBuffer[40];
>
unsigned long long fileOffset;
>
unsigned off = 21;
>
>
/* I get the file from a panel */
>
>
/* I edit the string of the path. I remove the 'file://localhost' part
>
*/
First, if you are getting a "file://" URL from the open panel, then
there is a well defined way to get a file path string from a "file://"
URL (i.e. don't strip it yourself):
if([theURL isFileURL])
{
scriptFile = [theURL path];
}
else
{
//Handle the error
}
>
scriptFileHandle = [NSFileHandle fileHandleForReadingAtPath:
>
scriptFile];
Make sure that scriptFileHandle is not nil ...
>
fileOffset = [scriptFileHandle seekToEndOfFile];
... because if it is, this call will return garbage
>
[bDisplay setDoubleValue: fileOffset];
Using setDoubleValue here, you will lose some precision, try this
instead (assuming that bDisplay is some standard NSControl):
[bDisplay setObjectValue: [NSNumber numberWithUnsignedLongLong:
fileOffset]];
>
fileOffset -= off;
>
[scriptFileHandle seekToFileOffset: fileOffset];
>
theData = [scriptFileHandle readDataOfLength:30];
How can you get 30 bytes of data if you've just seek'ed to 21 bytes
before the end of the file?
>
[theData getBytes: dataBuffer];
>
>
When I print what's in fileOffset ((it should return the size of the
>
file, right?)), it always returns the same misterious number:
>
2424892184.
--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://www.livejournal.com/users/clarkcox3/
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.