mindsnacks/Zinc — pull request #4 by amrox (2012-08-08 23:29:45+00:00)
Title: Basic file filters (flavors)

This introduces a basic way to create different "flavors" of a bundle by filtering files. A different flavor of a bundle has the same contents conceptually, but files might be a different format. For example, you might create flavors for regular (non-retina) and retina (@2x) images.

To create a bundle with flavors, you must pass a flavorspec on the command line. *This is highly subject to change*. A flavorspec is a dictionary where the keys are the name of the flavor, and the value is a list of patterns.

```
{
"small" : ["+ */photos/85x85/*",
"- */photos/*"],
"medium" : ["+ */photos/170x170/*",
"- */photos/*"],
"large" : ["+ */photos/340x340/*",
"- */photos/*"]
}
```

The patterns are inspired by rsync's ignore/exclude format, but currently far less powerful. A single pattern looks like this

```
- */photos/*
```
All patterns must begin with a `+` (accept) or `-` (reject). Paths are tested against the list of patterns in order, until a match is found. If no match is found, accept is assumed.

Next save the flavorspec to a file, and update a bundle like this

```
zinc bundle:update -f myflavorspec.json bar path
```

This will create a bundle as normal (with all files), but it will add some additional information to the manifest, as well as create some new archives.

Manifests now contain a list of flavors at the top level:

```
{
"bundle": "bar",
"catalog": "com.foo",
"flavors": [
"large",
"small",
"medium"
],
"files": {
"photos/340x340/three@2x~ipad.jpg": {
"formats": {
"gz": {
"size": 72725
}
},
"flavors": [
"large"
],
"sha": "7a0ec70c44168123afcde33502c5cdd78b4582a0"
},
}
```

And in addition, every file entry now includes the flavors it belongs to (snippet from above):

```
"photos/340x340/three@2x~ipad.jpg": {
"formats": {
"gz": {
"size": 72725
}
},
"flavors": [
"large"
],
"sha": "7a0ec70c44168123afcde33502c5cdd78b4582a0"
}
}
```

Finally, archives are created for each flavor `~` is appended to archive name:

```
com.foo.bar-1~small.tar
com.foo.bar-1~medium.tar
com.foo.bar-1~large.tar
```

This information will allow clients to download or bootstrap a particular flavor, which should reduce IO and processing time.

Clients can choose to ignore flavor information and just download the full archive or use all files in the manifest.