Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gruntjs/grunt-contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kellen committed Jun 15, 2012
2 parents 474a09d + c79866e commit b7c5af4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
21 changes: 10 additions & 11 deletions docs/compress.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
## Compress files
> Contributed By: Chris Talkington (@ctalkington) and Tyler Kellen (@tkellen)
### Overview

Inside your `grunt.js` file add a section named `compress`. This section specifies the files to compress and the options passed to either [zipstream](https://github.com/wellawaretech/node-zipstream) (for zip) or [tar](https://github.com/isaacs/node-tar) (for tar).
Inside your `grunt.js` file, add a section named `compress`. This section specifies the files to compress and the options passed to either [zipstream](https://github.com/wellawaretech/node-zipstream) (for zip) or [tar](https://github.com/isaacs/node-tar) (for tar/tgz) or [zlib](http://nodejs.org/api/zlib.html#zlib_options) (for gzip).

#### Parameters

##### files ```object```

This parameter defines what files this task will compress and should contain key:value pairs.
This defines what files this task will compress and should contain key:value pairs.

The key (destination) should be an unique filepath (supports [grunt.template](https://github.com/cowboy/grunt/blob/master/docs/api_template.md)) and the value (source) should be a filepath or an array of filepaths (supports [minimatch](https://github.com/isaacs/minimatch) regex).

##### options ```object```

This parameter controls how this task operates and should contain key:value pairs, see options below.
This controls how this task operates and should contain key:value pairs, see options below.

#### Options

##### mode ```string``` ```null```
##### mode ```string```

This option is used to define which mode to use, currently supports gzip, tar, tgz (tar gzip) and zip.
This is used to define which mode to use, currently supports gzip, tar, tgz (tar gzip) and zip.

##### basePath ```string``` ```null```
##### basePath ```string```

This option adjusts internal filenames to be relative to provided path, within the resulting archive file.

##### level ```integer``` ```1``` ```zip only```
##### level ```integer``` (zip only)

This option sets the level of archive compression.
This option sets the level of archive compression (defaults to 1).

> Currently, gzip compression related options are not supported due to deficiencies in node's zlib library.
Expand Down Expand Up @@ -79,6 +80,4 @@ compress: {
}
}
},
```

> Contributed By: Chris Talkington (@ctalkington) and Tyler Kellen (@tkellen)
```
20 changes: 13 additions & 7 deletions tasks/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ module.exports = function(grunt) {

grunt.registerHelper("zipHelper", function(files, dest, options, callback) {
var fs = require("fs"),
zip = require("zipstream").createZip(options);

var destdir = _(dest).strLeftBack("/");
zip = require("zipstream").createZip(options),
destdir = _(dest).strLeftBack("/");

if (require("path").existsSync(destdir) === false) {
grunt.file.mkdir(destdir);
Expand Down Expand Up @@ -106,13 +105,20 @@ module.exports = function(grunt) {
grunt.registerHelper("tarHelper", function(files, dest, options, callback) {
var fstream = require("fstream"),
tar = require("tar"),
zlib = require("zlib");

var destdir = _(dest).strLeftBack("/"),
zlib = require("zlib"),
destdir = _(dest).strLeftBack("/"),
destfile = _(dest).strRight("/"),
tempdir = destdir + "/tar_temp",
tardir = _(destfile).strLeftBack(".");

function getSize(filename) {
try {
return require("fs").statSync(filename).size;
} catch (e) {
return 0;
}
}

// support tar.gz naming when getting root folder for tar
if (_(tardir).strRightBack(".") === "tar") {
tardir = _(tardir).strLeftBack(".");
Expand Down Expand Up @@ -155,7 +161,7 @@ module.exports = function(grunt) {

tard.on("close", function() {
grunt.helper("clean", tempdir);
callback(null, require("fs").statSync(dest).size);
callback(null, getSize(dest));
});
});

Expand Down

0 comments on commit b7c5af4

Please sign in to comment.