jamesfake namesmith
jamesfake namesmith

Reputation: 65

How would I store different types of data in one file

I need to store data in a file in this format word, audio, jpeg How would I store that all in one file? Is it even possible do would I need to store links to other data files in place of the audio and jpeg. Would I need a custom file format?

Upvotes: 0

Views: 509

Answers (1)

WoodyDev
WoodyDev

Reputation: 1476

1. Your own filetype

As mentioned by @Ken White you would need to be creating your own custom file format for this sort of thing, which would then mean creating your own parser type. This could be achieved in almost any language you wanted but since you are planning on using word format, then maybe C# would be best for you. However, this technique could be quite complicated and take a relatively large amount of time to thoroughly test your file compresser / decompressor, but may be best depending on your needs.

2. Command line utilities

Another way to go about this would be to use a bash script to combine all of the files into one file, and then decompress it at the other end. For example the steps could involve:

  • Combine files using windows copy / linux cat command on command line
  • Create a metdata file of your own that says how many files are in this custom file, and how much memory each one takes up (could be a short XML or JSON file for example...)
  • Use the linux split command or install a Windows command line file splitter program (here's just one example) to split the file back into whatever components have made it up.

This way you only have to create a really small file type, and let the OS utilities handle the combining of them for you.

Example on Windows:

  1. Copy all of the files in your current directory into one output file called 'file.custom'

    copy /b * file.custom

    1. Generate custom file format describing metadata (i.e. get the file size on disk in C# example here). This is just maybe what I would do in JSON. SO formatting was being annoying so here's a link (Copy paste it into an editor or online JSON viewer).

    2. Use a decompress windows / linux command line tool to decompress each files to the exact length (and export it back to the exact name) specified in the JSON (metadata) file. (More info on splitting files on this post).

3. ZIP files

You could always store all of the files in a compressed zip file, and then just use a zip compressor, expander as and when you like to retreive any number of file formats stored within.

I found a couple of examples of :

Upvotes: 1

Related Questions