Permalink
Browse files

fixed a whitespace bug in the perl script, encode test passes

  • Loading branch information...
1 parent 83f7b2a commit 79c1879e8170c4811186119819bf2769c9863859 @substack substack committed Nov 20, 2010
Showing with 19 additions and 35 deletions.
  1. +0 −20 test/decode.js
  2. +16 −12 test/encode.js
  3. +1 −1 test/hashes.json
  4. +2 −2 test/perl-base64-encode.pl
View
@@ -1,20 +0,0 @@
-var base64_decode = require('base64').decode;
-var crypto = require('crypto');
-var fs = require('fs');
-var Hash = require('traverse/hash');
-var hashes = JSON.parse(
- fs.readFileSync(__dirname + '/hashes.json').toString()
-);
-
-function md5sum (data) {
- return new crypto.Hash('md5').update(data).digest('hex');
-}
-
-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)));
- });
- });
-};
View
@@ -1,16 +1,20 @@
-var base64_encode = require('base64').encode;
-var sys = require('sys');
+var base64 = require('base64');
+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-encode.js <file>`');
- process.exit(1);
+function md5hex (data) {
+ return new crypto.Hash('md5').update(data.toString()).digest('hex');
}
-var file = fs.readFileSync(process.argv[2], 'binary');
-var fileBuf = new Buffer(file.length);
-fileBuf.write(file, 'binary');
-
-sys.print(base64_encode(fileBuf));
-
+exports.encode = function (assert) {
+ Hash(hashes).forEach(function (hash, file) {
+ fs.readFile(file, function (err, buf) {
+ if (err) throw err;
+ assert.equal(hash, md5hex(base64.encode(buf)));
+ });
+ });
+};
View
@@ -1 +1 @@
-{"data/data-png.png":"548520f69c729f360a0aa4551ba0960b","data/data-rand-14":"3248419b78b256c7adafc95248c14137","data/data-rand-13":"648b78d7ee4a7a0af2d3dbda8d7b7d57","data/data-rand-17":"1de788e6b3210265d9ca6c7074ad3fd2","data/data-rand-03":"21cfce2fd1139ee2cc183ecc77a4f5e5","data/data-rand-20":"1c5eec2b5f512e13151991e47d40938c","data/data-rand-12":"94ee2ba841d27338654dea8b1fa4d4d8","data/data-rand-05":"6e69465580a7bb42deef6c6ea53973af","data/data-rand-19":"a4941ce69f9f2fb5fdc6a97aa529d166","data/data-rand-01":"ac629c88b103d231bd72e5502af32475","data/data-rand-15":"6ca1d38ee971bd48f597ad72700415f0","data/data-png.png-node-out":"d41d8cd98f00b204e9800998ecf8427e","data/data-png.png-perl-out":"a51e0d8830aa136db584b6b483a2f932","data/data-rand-18":"74212ef8822144f95d26da9e27389615","data/data-rand-07":"8dee8bfd7af68b16c4f4f6ac570243ad","data/data-rand-10":"0f962d76955f3396da02894ced195214","data/data-rand-16":"ba8481f2fc2a5e60fcc6377876cd458d","data/data-rand-02":"a1d7280e597a234ed64381c2d3f5d63f","data/data-rand-11":"2fd15bf19a5f3862758d1bd7518c5043","data/data-rand-09":"6e67528dd61a9fcf5ff69a765b574b83","data/data-source-code.c":"3aed4614a67e69869515deb764ad571e","data/data-rand-06":"27d78faea63cb97f4413d715656ecb42","data/data-rand-04":"e8226d7cde3421de741dd5b0b03a55cd","data/data-rand-08":"8759d2d8a3af80bc66ba11a598c82818"}
+{"data/data-png.png":"2054021af507f5e7918f19ad70e65535","data/data-rand-14":"c06dc9c60cf1656b209eed81795bd567","data/data-rand-13":"93690414d726b5d94e5664d8bd14e349","data/data-rand-17":"a7b3087d9672987bb4816c48d1e19817","data/data-rand-03":"d4868c6a880db6b4b3a5040f351d2edd","data/data-rand-20":"9ee81d8ce7287b8c1048e7cc90c350f3","data/data-rand-12":"48a265c77e007c50618e3f8bd4d66788","data/data-rand-05":"238a24dafdbe37aa65e4e7b300973abd","data/data-rand-19":"b7677c3ed7a301c72e4b1d5d69dfd46d","data/data-rand-01":"73ee8eea6d118e7ef290f240656ff860","data/data-rand-15":"0f2bdc3e4edd681447794293da15cf2d","data/data-png.png-node-out":"d41d8cd98f00b204e9800998ecf8427e","data/data-png.png-perl-out":"f81e67a2c004cdd10aac4932f5d5db1d","data/data-rand-18":"ffa08760cd50a8ebce9aab0a612081f8","data/data-rand-07":"757b65998ba0c1878eb89912072ffc58","data/data-rand-10":"20715b7f90660e5de91cd7a5b67c8c1d","data/data-rand-16":"e994a7f48d9b9a74978e4bd59f056799","data/data-rand-02":"b5b23ca2bb4dfb3828d755fe5a16a99d","data/data-rand-11":"17ef8d10e499c91c7f991de1f275886a","data/data-rand-09":"bb3e7e19fb5cfdde4d5b691125037150","data/data-source-code.c":"69911e1859fc241c9f56d2e80cdb3fc7","data/data-rand-06":"1aea9e22d8f0ab27200e8399c9de979d","data/data-rand-04":"ff50850a6be21360908e8cd96006f645","data/data-rand-08":"75ab879739a0123f432403ebc6f5d8d4"}
@@ -8,5 +8,5 @@
use Slurp qw/slurp/;
print encode_json({ map {
- $_ => md5_hex(encode_base64(slurp($_)))
-} glob "data/*" });
+ $_ => md5_hex(join '', split /\s+/, encode_base64(scalar slurp($_)))
+} glob 'data/*' });

0 comments on commit 79c1879

Please sign in to comment.