Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
So I have started to look into objc and Cocoa and have come accross NSFileManager and NSData. Are there any methods to read in just the data part of a file into an NSData object, what I mean is to strip of the header?

And are there any templates for common file formats, so that raw data can be packed and written corectly to these formats?

Also are there a similar level of control over the content of an NSData object as with NSArray?
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
So I have started to look into objc and Cocoa and have come accross NSFileManager and NSData. Are there any methods to read in just the data part of a file into an NSData object, what I mean is to strip of the header?

And are there any templates for common file formats, so that raw data can be packed and written corectly to these formats?

Also are there a similar level of control over the content of an NSData object as with NSArray?

You use NSFileManager when _you_ determine the exact file format and nobody else. With NSFileManager you just get the raw data (or you could use Posix calls instead, if you want code that runs on other OSes as well).

There are special classes for XML files, classes for Preference files, classes for RTF and HTML, classes for image data and so on.
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
You use NSFileManager when _you_ determine the exact file format and nobody else. With NSFileManager you just get the raw data (or you could use Posix calls instead, if you want code that runs on other OSes as well).

There are special classes for XML files, classes for Preference files, classes for RTF and HTML, classes for image data and so on.

Hmm, ok so say that I have an application that perform some manipulation on audio file data. Does this mean that I manually will have to check for all possible fileformats that could be used with the program, and set different offsets accordingly? I was hoping that there was a way for this to be handled in the background, since the os allready know this stuff.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Hmm, ok so say that I have an application that perform some manipulation on audio file data. Does this mean that I manually will have to check for all possible fileformats that could be used with the program, and set different offsets accordingly? I was hoping that there was a way for this to be handled in the background, since the os allready know this stuff.

No, it doesn't mean that, and that is not what I wrote. If you use NSFileManager, then you have to understand all possible file formats. That's why you wouldn't use NSFileManager, but something more appropriate. For audio files, I would have a good look at the Quicktime or CoreAudio documentation.

It also shows that when you ask questions, you should ask about what you actually want to know, and not about the things that you think you want to know. You wanted to know about handling audio files, but you asked about NSFileManager. Obviously you get answers about NSFileManager, because we are all not very good at distance mind reading.
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
No, it doesn't mean that, and that is not what I wrote. If you use NSFileManager, then you have to understand all possible file formats. That's why you wouldn't use NSFileManager, but something more appropriate. For audio files, I would have a good look at the Quicktime or CoreAudio documentation.

It also shows that when you ask questions, you should ask about what you actually want to know, and not about the things that you think you want to know. You wanted to know about handling audio files, but you asked about NSFileManager. Obviously you get answers about NSFileManager, because we are all not very good at distance mind reading.

To be fair though, the title of the thread is: Some general Cocoa questions about files.

I then continued to say that I have started to look into Cocoa and have come accross NSFileManager and NSData. If there are better methods to achive what I want to know, I want to know, that is the purpose of the thread, a general discussion. So the audio file example served as an example, could have been graphic formats as well.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
For graphics you'd use NSImage, or CGImage, or ImageIO. The point is that in general you're better off using APIs designed for the type of file you're working with, rather than general file reading APIs.
 

subsonix

macrumors 68040
Original poster
Feb 2, 2008
3,551
79
The point is that in general you're better off using APIs designed for the type of file you're working with, rather than general file reading APIs.

Ok, get it. Just starting to look into Cocoa and it helps to get a sense of some of the benefits it presents when dealing with files, as well as how things are organised.

Cheers
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.