Chapter 6. Plain text Foods files, and choosing which type of Foods file to use
Prev |  | Next

## Chapter 6. Plain text Foods files, and choosing which type of Foods file to use

So far, all the files that we have worked with have either been binary files[16] or XML files. Pantry can also store foods in a more traditionally Unix plain text format--that is, in a text file with each row representing a single food and each column representing something about that food. In this chapter you'll learn about the advantages and disadvantages of this file format and how you can use it.

## 6.1. How Foods Text files work

As you know, a food in Pantry consists of traits, nutrients, and available units. That's a lot of data. The two file formats we have seen so far--the Pantry native file and the Pantry XML file--both contain all of this data for each and every food. The Pantry native file is fast, but you can't edit that with your text editor at all. The Pantry XML file can be edited with your text editor, but the format is so verbose that you don't ordinarily want to touch it unless you have to--if, for example, you are creating an entirely new food.

The Foods Text file is a little different from the Pantry XML and Pantry native files because it does not contain all the data for each and every food. Instead, it relies upon another Pantry XML or Pantry native file to contain all the food data. In the Foods Text file, each line corresponds to a particular food. Each line specifies a source file for the food. The source file will be a Pantry XML or Pantry native file that will contain the nutrient and unit data for the food.

Pantry must look up the food in the source file. To do this, Pantry uses the food's name. There must be exactly one match for the food name that you specify; therefore, you will find Foods Text files to be easiest to use if you have source files in which every food name is unique. The `master` file meets this criterion; you might also set up a `quick` file that also meets this criterion.

This will all get more clear with examples:

[16] The distinction between binary files and plain-text files is quite arbitrary. It is fair to say that there is no such thing as plain text. But for our purposes we will call anything that you usually edit in a text editor "plain text".

Prev |  | Next
5.4. Validation of Pantry XML files | Home | 6.2. Foods Text files: an example