Skip to content

Commit

Permalink
Merge pull request #35 from sprohaska/p/fix-2g
Browse files Browse the repository at this point in the history
fix 2g
  • Loading branch information
srijs committed Sep 18, 2016
2 parents 06322fd + afe4853 commit ca8f50a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"grunt-saucelabs": "^8.3.2",
"grunt-sweet.js": "~0.1.5",
"microtime": "^2.1.1",
"mocha": "^3.0.2",
"sweet.js": "~0.7.1"
},
"testling": {
Expand Down
4 changes: 3 additions & 1 deletion rusha.sweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@

var padData = function (bin, chunkLen, msgLen) {
bin[chunkLen>>2] |= 0x80 << (24 - (chunkLen % 4 << 3));
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 14] = msgLen >> 29;
// To support msgLen >= 2 GiB, use a float division when computing the
// high 32-bits of the big-endian message length in bits.
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 14] = (msgLen / (1 << 29)) |0;
bin[(((chunkLen >> 2) + 2) & ~0x0f) + 15] = msgLen << 3;
};

Expand Down
63 changes: 63 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,69 @@
});
});

// To execute the tests, run `npm test`, then open `test/test.html` in
// Safari. The tests work in Firefox when loaded via HTTP, e.g. from
// `localhost`. The 1 and 2 GiB tests fail in Chrome with `NotFoundError`
// when loaded via HTTP.
if (typeof Worker !== 'undefined') {
describe('webworker', function () {
it('1 kiB', function(done) {
var rw = new Worker('../rusha.min.js')
var zero1k = new Int8Array(1024);
var blob = new Blob([zero1k]);
rw.onmessage = function (e) {
if (e.data.error) {
throw e.data.error;
}
assert.strictEqual('60cacbf3d72e1e7834203da608037b1bf83b40e8', e.data.hash);
done();
}
rw.postMessage({ id: 0, data: blob })
});
it('1 MiB', function(done) {
var rw = new Worker('../rusha.min.js')
var zero1M = new Int8Array(1024 * 1024);
var blob = new Blob([zero1M]);
rw.onmessage = function (e) {
if (e.data.error) {
throw e.data.error;
}
assert.strictEqual('3b71f43ff30f4b15b5cd85dd9e95ebc7e84eb5a3', e.data.hash);
done();
}
rw.postMessage({ id: 0, data: blob })
});
it('1 GiB', function(done) {
this.timeout(30 * 1000);
var rw = new Worker('../rusha.min.js')
var zero1M = new Int8Array(1024 * 1024);
var blob = new Blob(Array(1024).fill(zero1M));
rw.onmessage = function (e) {
if (e.data.error) {
throw e.data.error;
}
assert.strictEqual('2a492f15396a6768bcbca016993f4b4c8b0b5307', e.data.hash);
done();
}
rw.postMessage({ id: 0, data: blob })
});
it('2 GiB', function(done) {
this.timeout(60 * 1000);
var rw = new Worker('../rusha.min.js')
var zero1M = new Int8Array(1024 * 1024);
var blob = new Blob(Array(2 * 1024).fill(zero1M));
rw.onmessage = function (e) {
if (e.data.error) {
throw e.data.error;
}
assert.strictEqual('91d50642dd930e9542c39d36f0516d45f4e1af0d', e.data.hash);
done();
}
rw.postMessage({ id: 0, data: blob })
});
});
}

describe('digestFromString', function() {
it('returns hex string from string', function() {
assert.strictEqual('a9993e364706816aba3e25717850c26c9cd0d89d', r.digestFromString(abcString));
Expand Down

0 comments on commit ca8f50a

Please sign in to comment.