diff --git a/Gruntfile.js b/Gruntfile.js index a9e2b22..6dfbf90 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,7 +33,7 @@ module.exports = function(grunt) { test: { flatten: true, expand: true, - src: ['test/fixtures/*.txt'], + src: ['test/fixtures/*.{txt,bin}'], dest: 'tmp/', }, }, @@ -56,6 +56,12 @@ module.exports = function(grunt) { }, src: ['tmp/international.txt'] }, + binary_options: { + options: { + encoding: 'binary' + }, + src: ['tmp/binary.bin'] + } }, // Unit tests. diff --git a/README.md b/README.md index 95972c1..cdc72f5 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ grunt.initConfig({ Type: `String` Default value: `'utf8'` -The encoding of the file contents. +The encoding of the file contents. Possible values `'utf8'`, `'ascii'` or `'binary'`. #### options.algorithm Type: `String` diff --git a/package.json b/package.json index a33eb2d..9d72238 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-rev", "description": "Static file asset revisioning through content hashing", - "version": "0.1.0", + "version": "0.1.1", "homepage": "https://github.com/cbas/grunt-rev", "author": { "name": "Sebastiaan Deckers", @@ -29,13 +29,14 @@ "test": "grunt test" }, "devDependencies": { + "grunt": "0.4.0", + "grunt-contrib-clean": "0.4.0rc6", "grunt-contrib-copy": "0.4.0", "grunt-contrib-jshint": "0.1.1rc6", - "grunt-contrib-clean": "0.4.0rc6", - "grunt-contrib-nodeunit": "0.1.2rc6", - "grunt": "0.4.0rc6" + "grunt-contrib-nodeunit": "^0.4.1", + "nodeunit": "^0.9.1" }, "keywords": [ "gruntplugin" ] -} \ No newline at end of file +} diff --git a/tasks/rev.js b/tasks/rev.js index f6f77c2..f9959cf 100644 --- a/tasks/rev.js +++ b/tasks/rev.js @@ -17,7 +17,8 @@ module.exports = function(grunt) { function md5(filepath, algorithm, encoding, fileEncoding) { var hash = crypto.createHash(algorithm); grunt.log.verbose.write('Hashing ' + filepath + '...'); - hash.update(grunt.file.read(filepath), fileEncoding); + //set encoding to null because in other case grunt.file.read use utf8 by default + hash.update(grunt.file.read(filepath, {encoding: null}), fileEncoding); return hash.digest(encoding); } diff --git a/test/fixtures/binary.bin b/test/fixtures/binary.bin new file mode 100644 index 0000000..0ee99d2 Binary files /dev/null and b/test/fixtures/binary.bin differ diff --git a/test/rev_test.js b/test/rev_test.js index b876642..97ce49a 100644 --- a/test/rev_test.js +++ b/test/rev_test.js @@ -50,5 +50,12 @@ exports.rev = { test.ok(exists, '8 character MD5 hash prefix for international content'); test.done(); + }, + binary_options: function(test) { + test.expect(1); + var exists = grunt.file.exists('tmp/2ac69376.binary.bin'); + test.ok(exists, '8 character MD5 hash prefix for binary content'); + + test.done(); } };