Socket
Socket
Sign inDemoInstall

crc-32

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crc-32 - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

misc/integration.js

2

bits/01_version.js

@@ -1,1 +0,1 @@

CRC32.version = '0.1.0';
CRC32.version = '0.2.0';

@@ -18,5 +18,5 @@ /* see perf/crc32table.js */

return table;
return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
}
var table = signed_crc_table();
/* charCodeAt is the best approach for binary strings */
var use_buffer = typeof Buffer !== 'undefined';
function crc32_bstr(bstr) {
for(var crc = -1, i = 0, L=bstr.length-1; i < L;) {
crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
if(bstr.length > 32768) if(use_buffer) return crc32_buf(Buffer(bstr));
var crc = -1, L = bstr.length - 1;
for(var i = 0; i < L;) {
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8);
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8);
}
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i)) & 0xFF];
return crc ^ -1;

@@ -12,5 +15,14 @@ }

function crc32_buf(buf) {
for(var crc = -1, i = 0; i != buf.length; ++i) {
crc = (crc >>> 8) ^ table[(crc ^ buf[i]) & 0xFF];
for(var crc = -1, i = 0, L=buf.length-3; i < L;) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
}
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; }}}
return crc ^ -1;

@@ -17,0 +29,0 @@ }

@@ -5,3 +5,3 @@ /* crc32.js (C) 2014 SheetJS -- http://sheetjs.com */

(function(CRC32) {
CRC32.version = '0.1.0';
CRC32.version = '0.2.0';
/* see perf/crc32table.js */

@@ -24,3 +24,3 @@ function signed_crc_table() {

return table;
return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
}

@@ -30,8 +30,11 @@

/* charCodeAt is the best approach for binary strings */
var use_buffer = typeof Buffer !== 'undefined';
function crc32_bstr(bstr) {
for(var crc = -1, i = 0, L=bstr.length-1; i < L;) {
crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
if(bstr.length > 32768) if(use_buffer) return crc32_buf(Buffer(bstr));
var crc = -1, L = bstr.length - 1;
for(var i = 0; i < L;) {
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8);
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8);
}
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i)) & 0xFF];
return crc ^ -1;

@@ -41,5 +44,14 @@ }

function crc32_buf(buf) {
for(var crc = -1, i = 0; i != buf.length; ++i) {
crc = (crc >>> 8) ^ table[(crc ^ buf[i]) & 0xFF];
for(var crc = -1, i = 0, L=buf.length-3; i < L;) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
}
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; }}}
return crc ^ -1;

@@ -46,0 +58,0 @@ }

@@ -5,3 +5,3 @@ /* crc32.js (C) 2014 SheetJS -- http://sheetjs.com */

(function(CRC32) {
CRC32.version = '0.1.0';
CRC32.version = '0.2.0';
/* see perf/crc32table.js */

@@ -24,3 +24,3 @@ function signed_crc_table() {

return table;
return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
}

@@ -30,8 +30,11 @@

/* charCodeAt is the best approach for binary strings */
var use_buffer = typeof Buffer !== 'undefined';
function crc32_bstr(bstr) {
for(var crc = -1, i = 0, L=bstr.length-1; i < L;) {
crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
if(bstr.length > 32768) if(use_buffer) return crc32_buf(Buffer(bstr));
var crc = -1, L = bstr.length - 1;
for(var i = 0; i < L;) {
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8);
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8);
}
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i++)) & 0xFF];
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i)) & 0xFF];
return crc ^ -1;

@@ -41,5 +44,14 @@ }

function crc32_buf(buf) {
for(var crc = -1, i = 0; i != buf.length; ++i) {
crc = (crc >>> 8) ^ table[(crc ^ buf[i]) & 0xFF];
for(var crc = -1, i = 0, L=buf.length-3; i < L;) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
}
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF];
if(i < L+3) {
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; }}}
return crc ^ -1;

@@ -46,0 +58,0 @@ }

@@ -9,2 +9,94 @@ var bits = [

if(typeof module !== "undefined") module.exports = bits;
if(typeof require !== 'undefined') {
var js_crc32 = require('../');
var buffer_crc32 = require('./buffer-crc32');
var crc32 = require('./crc32');
var node_crc = require('./node-crc');
function z1(bstr) { return js_crc32.bstr(bstr); }
function z2(bstr) { return buffer_crc32.signed(bstr); }
function z3(bstr) { return crc32(bstr); }
function z4(bstr) { return node_crc.crc32(bstr);}
function b1(buf) { return js_crc32.buf(buf); }
function b2(buf) { return buffer_crc32.signed(buf); }
function b3(buf) { return crc32(buf); }
function b4(buf) { return node_crc.crc32(buf); }
function u1(str) { return js_crc32.str(str); }
function u2(str) { return buffer_crc32.signed(str); }
var ntests, len_max;
switch(process.env.MODE) {
case "A": ntests = 100000; len_max = 256; break;
case "B": ntests = 10000; len_max = 1024; break;
case "C": ntests = 10000; len_max = 4096; break;
case "D": ntests = 1000; len_max = 16384; break;
case "E": ntests = 1000; len_max = 65536; break;
case "F": ntests = 100; len_max = 262144; break;
default: ntests = 10000; len_max = 1024; break;
}
var btest = true, utest = true;
var bstr_tests = [];
var ustr_tests = [];
var len_min = 1;
var corpus = new Array(0x0800);
for(var k = 0; k < 0x0800; ++k) corpus[k] = String.fromCharCode(k)
len_max --;
k = (Math.random()*0x800)|0;
for(var i = 0; i < ntests; ++i) {
var l = (Math.random() * (len_max - len_min))|0 + len_min;
var s = new Array(l), t = new Array(l);
if(btest) for(var j = 0; j < l; ++j) s[j] = corpus[(i+j+k)&127];
if(utest) for(var j = 0; j < l; ++j) t[j] = corpus[(i+j+k)&0x7FF];
var ss = s.join("");
bstr_tests[i] = [ss, new Buffer(ss)];
ustr_tests[i] = t.join("");
}
var assert = require('assert');
function fix(str) { return parseInt(str, 16)|0; }
if(btest) for(var j = 0; j != ntests; ++j) {
assert.equal(z1(bstr_tests[j][0]), b1(bstr_tests[j][1]));
assert.equal(z1(bstr_tests[j][0]), z2(bstr_tests[j][0]));
assert.equal(z1(bstr_tests[j][0]), fix(z3(bstr_tests[j][0])));
assert.equal(z1(bstr_tests[j][0]), fix(z4(bstr_tests[j][0])));
assert.equal(b1(bstr_tests[j][1]), b2(bstr_tests[j][1]));
assert.equal(b1(bstr_tests[j][1]), fix(b3(bstr_tests[j][1])));
assert.equal(b1(bstr_tests[j][1]), fix(b4(bstr_tests[j][1])));
}
if(utest) for(var j = 0; j != ntests; ++j) {
assert.equal(u1(ustr_tests[j]), u2(ustr_tests[j]));
}
var BM = require('../perf/bm');
var suite = new BM('binary string (' + len_max + ')');
suite.add('js-crc32', function() { for(var j = 0; j != ntests; ++j) z1(bstr_tests[j][0]); });
suite.add('buffer-crc32', function() { for(var j = 0; j != ntests; ++j) z2(bstr_tests[j][0]); });
if(len_max < 4096) {
suite.add('crc32', function() { for(var j = 0; j != ntests; ++j) z3(bstr_tests[j][0]); });
suite.add('node_crc', function() { for(var j = 0; j != ntests; ++j) z4(bstr_tests[j][0]); });
}
suite.run();
suite = new BM('buffer (' + len_max + ')');
suite.add('js-crc32', function() { for(var j = 0; j != ntests; ++j) b1(bstr_tests[j][1]); });
suite.add('buffer-crc32', function() { for(var j = 0; j != ntests; ++j) b2(bstr_tests[j][1]); });
if(len_max < 1024) {
suite.add('crc32', function() { for(var j = 0; j != ntests; ++j) b3(bstr_tests[j][1]); });
suite.add('node_crc', function() { for(var j = 0; j != ntests; ++j) b4(bstr_tests[j][1]); });
}
suite.run();
var suite = new BM('unicode string (' + len_max + ')');
suite.add('js-crc32', function() { for(var j = 0; j != ntests; ++j) u1(ustr_tests[j]); });
suite.add('buffer-crc32', function() { for(var j = 0; j != ntests; ++j) u2(ustr_tests[j]); });
suite.run();
}
crc32table = [

@@ -11,0 +103,0 @@ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,

{
"name": "crc-32",
"version": "0.1.0",
"version": "0.2.0",
"author": "sheetjs",

@@ -5,0 +5,0 @@ "description": "Pure-JS CRC-32",

@@ -1,2 +0,2 @@

/* ssf.js (C) 2014 SheetJS -- http://sheetjs.com */
/* bm.js (C) 2014 SheetJS -- http://sheetjs.com */
var Benchmark = require('benchmark');

@@ -15,8 +15,14 @@ var c = require('ansi')(process.stdout);

this.suite = new Benchmark.Suite(name, { onComplete: suite_end });
this.suites = [];
this.maxlen = 0;
}
BM.prototype.run = function() { this.suite.run(); };
BM.prototype.run = function() {
var maxlen = this.maxlen, ss = this.suite;
this.suites.forEach(function(s) { ss.add(s[0] + new Array(maxlen-s[0].length+1).join(" "), s[1]); });
if(this.suites.length > 0) this.suite.run();
};
BM.prototype.add = function(msg, test) {
this.suite.add(msg, {
this.suites.push([msg, {
onCycle: test_cycle,

@@ -26,5 +32,6 @@ onComplete: test_end,

fn: test
});
}]);
this.maxlen = Math.max(this.maxlen, msg.length);
};
module.exports = BM;

@@ -36,4 +36,13 @@ # crc32

`make perf` will run performance tests.
`make perf` will run algorithmic performance tests (which should justify certain
decisions in the code).
`make perf-all` compares the performance of various crc-32 algorithms that
implement the correct form (note that the SSE intrinsic is designed for the
CRC32C checksum and uses a different polynomial).
Unexpected code patterns were based on performance testing in node and browser:
- [Loop unrolling helps!](http://jsperf.com/crc32-table/2)
## In the future ...

@@ -50,3 +59,3 @@

[![Build Status](https://travis-ci.org/SheetJS/js-crc32.png?branch=master)](https://travis-ci.org/SheetJS/js-crc32)
[![Build Status](https://travis-ci.org/SheetJS/js-crc32.svg?branch=master)](https://travis-ci.org/SheetJS/js-crc32)

@@ -53,0 +62,0 @@ [![Coverage Status](https://coveralls.io/repos/SheetJS/js-crc32/badge.png?branch=master)](https://coveralls.io/r/SheetJS/js-crc32?branch=master)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc