Navigation Menu

Skip to content

Commit

Permalink
decode test, fails
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Nov 20, 2010
1 parent a4ef9b3 commit 83f7b2a
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/decode.js
@@ -1,16 +1,20 @@
var base64_decode = require('base64').decode;
var sys = require('sys');
var crypto = require('crypto');
var fs = require('fs');
var Buffer = require('buffer').Buffer;
var Hash = require('traverse/hash');
var hashes = JSON.parse(
fs.readFileSync(__dirname + '/hashes.json').toString()
);

if (!process.argv[2]) {
sys.log('No argument specified, use `node-base64-decode.js <file>`');
process.exit(1);
function md5sum (data) {
return new crypto.Hash('md5').update(data).digest('hex');
}

var file = fs.readFileSync(process.argv[2], 'ascii');
var fileBuf = new Buffer(file.length);
fileBuf.write(file, 'ascii');

process.stdout.write(base64_decode(fileBuf), 'binary');

exports.decode = function (assert) {
Hash(hashes).forEach(function (hash, file) {
fs.readFile(file, function (err, buf) {
if (err) throw err;
assert.equal(hash, md5sum(base64_decode(buf)));
});
});
};

0 comments on commit 83f7b2a

Please sign in to comment.