• 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
Re: How to determine if a data blob is a plist ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to determine if a data blob is a plist ?


  • Subject: Re: How to determine if a data blob is a plist ?
  • From: Chris Kane <email@hidden>
  • Date: Mon, 27 Jan 2003 18:18:58 -0800

String conversion is not going to produce anything useful if the archive is a binary plist from NSKeyedArchiver.

The best way to tell if is a plist is to parse it/unarchive it. This will fail if it is not an archive, in the case of a keyed archive, for example. Either the creation will fail or an attempt to extract something you know should be in your documents will fail.

If you don't want to go to all that work (which in the case of a binary plist is not really a lot), and want to live a little dangerously (this isn't documented), the first 6 bytes of a binary plist are "bplist". This doesn't verify that it is actually one of yours, of course.

Chris Kane
Cocoa Frameworks, Apple


On Monday, January 27, 2003, at 05:19 PM, Jeff Disher wrote:

You could create an NSString from the data using:
- (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding

I guess you would use the encoding constant for ASCII. Then you could send that string the propertyList message. If it doesn't throw an exception, it is a property list.

Check the docs on NSString for the details of doing this.

Hope that helps,
Jeff.


On Monday, January 27, 2003, at 02:10 PM, Bob Miller wrote:

Hello,

Can anyone tell me if there is a way to check an NSData object to see if it is a valid plist. I want to be able to detect an attempt at opening an invalid file in my appl. The appl. archives data using an NSKeyArchiver and saves the NSData away. It is possible for a user to force the application's file extension to be that of the one used by the appl. on a file that was not created by the appl. How is this scenario protected against, am I missing something very basic(could be.)

Thanks in advance for any help,
Regards,
Bob M.
_______________________________________________
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.


Jeff Disher
President and Lead Developer of Spectral Class
Spectral Class: Shedding Light on Innovation
http://www.spectralclass.com/
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Re: How to determine if a data blob is a plist ? (From: Jeff Disher <email@hidden>)

  • Prev by Date: Re: How to determine if a data blob is a plist ?
  • Next by Date: Invoking another app's service?
  • Previous by thread: Re: How to determine if a data blob is a plist ?
  • Next by thread: NSTableView & NSDragOperation
  • Index(es):
    • Date
    • Thread