Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting plist to binary plist

Tags:

Apple strongly recommends using the binary plist format when reading large XML-based data sets into iPhone apps. Among their reasoning is the fact that XML parsing is very taxing on the iPhone. However, this requires that files residing on the remote web server be converted first.

For frequently-changing content, it is not acceptable to do this manually. If at all possible, I'd like to avoid having a web based app call the command line to perform the conversion (i.e., plutil).

Are there publicly available algorithms to perform this conversion?

like image 534
Brian Cline Avatar asked Nov 05 '08 06:11

Brian Cline


People also ask

What is binary plist?

A Visual Studio Code extension that enables editing of binary property list files as XML. It is inspired by the BinaryPlist Sublime Text package, although the experience is not as seamless (the user must agree to opening a binary file and the editing takes place in an additional tab).

What is a Bplist?

Binary plists (bplists) can be easily identified using the file command on macOS. $ file config.plist. config.plist: Apple binary property list. Converting between different plist formats can be performed using the plutil command, e.g. to convert the above bplist to XML: $ plutil -convert xml1 config.plist.

How do I edit a plist file on a Mac?

plist file. If you need to edit these items, Control-click (or right-click) Info. plist in the sidebar and select Edit Manually. This allows you to add or edit items in raw XML format.


1 Answers

Yes. All the plist code is part of CoreFoundation, which is opensource. CoreFoundation can be directly built and run on Linux and Windows, so you can write a CF tool using the normal APIs you would use on Mac OS X, but build and run it on other platforms.

The particular API you want to be looking at is CFPropertyListWriteToStream(). The code for CoreFoundation is available from Apple (tarball), among other places.

Finally depending on how often you update the file, how much processor you have to spare on the server, and how much repetition there is your data there may be one significant enhancement left that you can do. By default certain elements in binary plists are uniqued (such as strings). Other elements are not (such as arrays and dictionarts). The binary plist format allows them to be uniqued, the issue is that it is expensive to actually walk through and unique arrays and dictionaries. If you have a lot of identical arrays or dicts in your content you may see a significant size reduction by uniquing them. You can enable that by hacking up _flattenPlist() in CFBinaryPlist.c.

If you do that make sure to test it very thoroughly, and do not do on any files you cannot update over the network, just in case a future release makes any optimizations that break that. Also, make sure you are ready to turn it off at a moments notice.

like image 146
Louis Gerbarg Avatar answered Sep 17 '22 22:09

Louis Gerbarg