Re: NSXMLParser useless with HUGE files
Re: NSXMLParser useless with HUGE files
- Subject: Re: NSXMLParser useless with HUGE files
- From: Johan Kool <email@hidden>
- Date: Wed, 14 Dec 2005 18:39:57 +0000
Hello Matt,
I had some trouble reading in a large file too, although I wasn't
using the XML parser. The following code does chop the text file up in
smaller pieces which I then process. 65536 is a bit arbitrary, but I
figured it was safest to use a number to the power of 2.
You do have to make sure that the last round doesn't trip over the
remainder as your file might not divide to 65536 to an exact number.
Hope this helps.
Johan
// Read a huge file piece by piece
NSData *aHugeFileData = [NSData dataWithContentsOfMappedFile:path];
int count = [aHugeFileData length]/65536;
unsigned char aBuffer[65536];
for (i = 0; i <= count; i++) {
[aHugeFileData getBytes:aBuffer range:NSMakeRange(65536*i, 65536)];
NSString *tempString = [[NSString alloc] initWithBytes:aBuffer
length:65536 encoding:NSASCIIStringEncoding];
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden