Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / June 2005



Tip: Looking for answers? Try searching our database.

NSData's +dataWithContentsOfFile

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pf - 29 Jun 2005 07:39 GMT
Hi,

I'm considering using Cocoa rather than Carbon...

How do I init an NSData object with data from a file *but* only from x bytes
in with a length of y bytes into the file? I don't want to read the whole
file into one data object then copy x bytes into another NSData object.

NSFile doesn't seem to be what I thought - similar to MFC's CFile...

Thanks,

Paul
Gregory Weston - 29 Jun 2005 12:05 GMT
In article
<42c24225$0$845$61c65585@uq-127creek-reader-03.brisbane.pipenetworks.com
.au>,

> Hi,
>
[quoted text clipped - 3 lines]
> in with a length of y bytes into the file? I don't want to read the whole
> file into one data object then copy x bytes into another NSData object.

+ (id)dataWithContentsOfMappedFile:(NSString *)path can create an NSData
that simply references the file. So you could...

NSData* theChunk = [[NSData dataWithContentsOfMappedFile:@"foo"]
subdataWithRange:NSMakeRange(theStart, theLength)];

> NSFile doesn't seem to be what I thought - similar to MFC's CFile...

I don't know what NSFile is. NSFileHandle might be what you're looking
for.

NSFileHandle* theFile = [NSFileHandle fileHandleForReadingAtPath:@"foo"];
[theFile seekToFileOffset:theStart];
NSData* theChunk = [theFile readDataOfLength:theLength];

G

Signature

Goal 2005: Convincing James Hetfield to cover the Strawberry Shortcake
"Are You Berry Berry Happy?" song.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.