Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a file bundle on OSX

For an application I would like to store a collection of files together, and have them appear in the filesystem as a single file so its easy to manage. I am currently storing everything in a folder.

I would like to keep things accessible so you can manually edit the inside contents if neccesary.

One way to do this would be to create a zip archive and give it a custom extension other then .zip. Then it appears as a filetype and if needed you can unpack and access the content, but for normal use keep it hidden.

I can't seem to find a convenient way to do this. Boost and zlib can do the compression but don't work with archives. I found libzip but I have a hard time understanding how to use it and to me it seems that it only reads/writes zip archives without doing the actual compression.

Is there a more convenient way to tackle this?

Can you call system functions for creating an archive on OSX from c++ / Carbon?

Is there another way to make a folder appear as a single file?

like image 266
Thijs Koerselman Avatar asked Jan 19 '23 15:01

Thijs Koerselman


1 Answers

In OSX, you can create Document Packages (similar to application bundles) which are treated as a single file in the Finder, but are really just directories with some internal structure.

Apple does not zip these packages, but they do provide the functionality you describe and they can be created and accessed through CoreFoundation by using CFBundleRef .

From the documentation:

... The important thing to remember about creating a document package is that it is just a directory. As long as the type of the document package is registered (as described in “Registering Your Document Type”), all you have to do is create a directory with the appropriate filename extension. (The Finder uses the filename extension as its cue to treat the directory as a package.) You can create the directory (and create any files you want to put inside that directory) using the standard BSD file system routines ...

like image 68
e.James Avatar answered Jan 24 '23 17:01

e.James