From def7c88639338ae20c01e8b63c0d06707a2dd57f Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 29 Mar 2012 10:26:02 +0000 Subject: [PATCH] Hash.js, minor formatting changes --- source/Ox/js/Hash.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/source/Ox/js/Hash.js b/source/Ox/js/Hash.js index b1b8f346..2cfd1c72 100644 --- a/source/Ox/js/Hash.js +++ b/source/Ox/js/Hash.js @@ -1,10 +1,11 @@ 'use strict'; /*@ -Ox.oshash compute oshahs for given File or Blob object (async) +Ox.oshash Calculates oshash for a given file or blob object. Async. @*/ Ox.oshash = function(file, callback) { - //needs to go via string to work for files > 2GB + + // Needs to go via string to work for files > 2GB var hash = fromString(file.size.toString()); read(0); @@ -18,7 +19,7 @@ Ox.oshash = function(file, callback) { c &= 0xffff; a = A[0] + B[0] + (b >> 16); b &= 0xffff; - //cut of overflow + // Cut off overflow a &= 0xffff; return [a, b, c ,d]; } @@ -26,10 +27,10 @@ Ox.oshash = function(file, callback) { function fromData(s, offset) { offset = offset || 0; return [ - s.charCodeAt(offset+6) + (s.charCodeAt(offset+7) << 8), - s.charCodeAt(offset+4) + (s.charCodeAt(offset+5) << 8), - s.charCodeAt(offset+2) + (s.charCodeAt(offset+3) << 8), - s.charCodeAt(offset+0) + (s.charCodeAt(offset+1) << 8) + s.charCodeAt(offset + 6) + (s.charCodeAt(offset + 7) << 8), + s.charCodeAt(offset + 4) + (s.charCodeAt(offset + 5) << 8), + s.charCodeAt(offset + 2) + (s.charCodeAt(offset + 3) << 8), + s.charCodeAt(offset + 0) + (s.charCodeAt(offset + 1) << 8) ]; } @@ -40,13 +41,13 @@ Ox.oshash = function(file, callback) { num, pos, r = [0, 0, 0, 0]; - for(pos=0;pos>>= 16; } if (num) { @@ -58,10 +59,12 @@ Ox.oshash = function(file, callback) { } function hex(h) { - return (Ox.pad(h[0].toString(16), 4) + return ( + Ox.pad(h[0].toString(16), 4) + Ox.pad(h[1].toString(16), 4) + Ox.pad(h[2].toString(16), 4) - + Ox.pad(h[3].toString(16), 4)).toLowerCase(); + + Ox.pad(h[3].toString(16), 4) + ).toLowerCase(); } function read(offset, last) { @@ -73,21 +76,21 @@ Ox.oshash = function(file, callback) { var s = data.target.result, s_length = s.length - length, i; - for(i=0;i<=s_length; i+=length) { + for (i = 0; i <= s_length; i += length) { hash = add(hash, fromData(s, i)); } - if(file.size < block || last) { + if (file.size < block || last) { callback(hex(hash)); } else { read(file.size - block, true); } }; - if(file.mozSlice) { - blob = file.mozSlice(offset, offset+block); - } else if(file.webkitSlice) { - blob = file.webkitSlice(offset, offset+block); + if (file.mozSlice) { + blob = file.mozSlice(offset, offset + block); + } else if (file.webkitSlice) { + blob = file.webkitSlice(offset, offset + block); } else { - blob = file.slice(offset, offset+block); + blob = file.slice(offset, offset + block); } reader.readAsBinaryString(blob); }