• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Type of NSData contents
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Type of NSData contents


  • Subject: Type of NSData contents
  • From: Ben <email@hidden>
  • Date: Sat, 12 Jun 2010 13:18:47 +0100

Hi list

Given an NSData object, with no context as to what it might be, is it possible to find if it contains a document of recognised file type?

I know this is possible for image files, by using the imageIO framework and doing the following:

CGImageSourceRef imageSource = CGImageSourceCreateWithData(myNSDataObjectGoesHere, NULL);
NSString *uti = (NSString *)CGImageSourceGetType(imageSource);
NSString *extension = [[NSWorkspace sharedWorkspace] preferredFilenameExtensionForType:uti];
CFRelease(imageSource);
// Standard typed-in-mail-disclaimer here


I suppose I could take the long route of writing the data to disk, then using the NSWorkspace method -typeOfFile:error:, but that seems a bit heavy-handed.

Can anyone suggest a better way of doing this? I've been unable to find anything in the archives or Google, but perhaps I'm using the wrong search terms.

- Ben

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Type of NSData contents
      • From: Jens Alfke <email@hidden>
    • Re: Type of NSData contents
      • From: Charles Srstka <email@hidden>
    • Re: Type of NSData contents
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Help system question...
  • Next by Date: Re: NSArrayController/Modal dialog/KVO Gordian knot
  • Previous by thread: Re: NSArrayController/Modal dialog/KVO Gordian knot
  • Next by thread: Re: Type of NSData contents
  • Index(es):
    • Date
    • Thread