Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed needless utf8 decoding of binary files #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function(grunt) {
test: {
flatten: true,
expand: true,
src: ['test/fixtures/*.txt'],
src: ['test/fixtures/*.{txt,bin}'],
dest: 'tmp/',
},
},
Expand All @@ -56,6 +56,12 @@ module.exports = function(grunt) {
},
src: ['tmp/international.txt']
},
binary_options: {
options: {
encoding: 'binary'
},
src: ['tmp/binary.bin']
}
},

// Unit tests.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
]
}
}
3 changes: 2 additions & 1 deletion tasks/rev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Binary file added test/fixtures/binary.bin
Binary file not shown.
7 changes: 7 additions & 0 deletions test/rev_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};