version bump 1.0.2: demos and CLI
This commit is contained in:
		
							parent
							
								
									6927488edc
								
							
						
					
					
						commit
						029cc99249
					
				
							
								
								
									
										14
									
								
								.npmignore
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										14
									
								
								.npmignore
									
									
									
									
									
								
							| @ -1,14 +0,0 @@ | ||||
| node_modules | ||||
| misc/ | ||||
| perf/ | ||||
| bits/ | ||||
| ctest/ | ||||
| test_files/ | ||||
| test.js | ||||
| .travis.yml | ||||
| .jscs.json | ||||
| .jshintrc | ||||
| .flowconfig | ||||
| .npmignore | ||||
| perf.txt | ||||
| Makefile | ||||
| @ -8,8 +8,8 @@ node_js: | ||||
|   - "0.10" | ||||
|   - "0.8" | ||||
| before_install: | ||||
|   - "npm install -g npm@next" | ||||
|   - "npm install -g mocha" | ||||
|   - "npm install -g npm@4.3.0" | ||||
|   - "npm install -g mocha@2.x voc" | ||||
|   - "npm install codepage" | ||||
|   - "npm install blanket" | ||||
|   - "npm install coveralls mocha-lcov-reporter" | ||||
|  | ||||
| @ -96,6 +96,15 @@ $ bin/crc32.py t.txt | ||||
| 1912935186 | ||||
| ``` | ||||
| 
 | ||||
| On OSX the command `cksum` generates unsigned CRC-32 with Algorithm 3: | ||||
| 
 | ||||
| ```bash | ||||
| $ cksum -o 3 < IE8.Win7.For.Windows.VMware.zip | ||||
| 1891069052 4161613172 | ||||
| $ crc32 --unsigned ~/Downloads/IE8.Win7.For.Windows.VMware.zip | ||||
| 1891069052 | ||||
| ``` | ||||
| 
 | ||||
| ## Performance | ||||
| 
 | ||||
| `make perf` will run algorithmic performance tests (which should justify certain | ||||
|  | ||||
| @ -68,11 +68,17 @@ for(var i = 0; i < args.length; ++i) { | ||||
| if(!process.stdin.isTTY) filename = filename || "-"; | ||||
| if(filename.length===0) die("crc32: must specify a filename ('-' for stdin)",1); | ||||
| 
 | ||||
| function process_data(data/*:Buffer*/) { | ||||
| 	var out/*:CRC32Type*/ = X.buf(data, seed); | ||||
| 	return console.log(fmt === "" ? out : require("printj").sprintf(fmt, out)); | ||||
| } | ||||
| var crc32 = seed; | ||||
| var writable = require('stream').Writable(); | ||||
| writable._write = function(chunk, e, cb) { crc32 = X.buf(chunk, crc32); cb(); }; | ||||
| writable._writev = function(chunks, cb) { | ||||
| 	chunks.forEach(function(c) { crc32 = X.buf(c.chunk, crc32);}); | ||||
| 	cb(); | ||||
| }; | ||||
| writable.on('finish', function() { | ||||
| 	console.log(fmt === "" ? crc32 : require("printj").sprintf(fmt, crc32)); | ||||
| }); | ||||
| 
 | ||||
| if(filename === "-") process.stdin.pipe(require('concat-stream')(process_data)); | ||||
| else if(fs.existsSync(filename)) process_data(fs.readFileSync(filename)); | ||||
| if(filename === "-") process.stdin.pipe(writable); | ||||
| else if(fs.existsSync(filename)) fs.createReadStream(filename).pipe(writable); | ||||
| else die("crc32: " + filename + ": No such file or directory", 2); | ||||
|  | ||||
| @ -1 +1 @@ | ||||
| CRC32.version = '1.0.1'; | ||||
| CRC32.version = '1.0.2'; | ||||
|  | ||||
| @ -23,7 +23,7 @@ var CRC32; | ||||
| 	} | ||||
| 	/*jshint ignore:end */ | ||||
| }(function(CRC32) { | ||||
| CRC32.version = '1.0.1'; | ||||
| CRC32.version = '1.0.2'; | ||||
| /*:: | ||||
| type CRC32Type = number; | ||||
| type ABuf = Array<number> | Buffer; | ||||
|  | ||||
							
								
								
									
										2
									
								
								crc32.js
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								crc32.js
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ var CRC32; | ||||
| 	} | ||||
| 	/*jshint ignore:end */ | ||||
| }(function(CRC32) { | ||||
| CRC32.version = '1.0.1'; | ||||
| CRC32.version = '1.0.2'; | ||||
| /* see perf/crc32table.js */ | ||||
| /*global Int32Array */ | ||||
| function signed_crc_table() { | ||||
|  | ||||
| @ -21,7 +21,7 @@ var CRC32; | ||||
| 	} | ||||
| 	/*jshint ignore:end */ | ||||
| }(function(CRC32) { | ||||
| CRC32.version = '1.0.1'; | ||||
| CRC32.version = '1.0.2'; | ||||
| /* see perf/crc32table.js */ | ||||
| /*global Int32Array */ | ||||
| function signed_crc_table() { | ||||
|  | ||||
							
								
								
									
										28
									
								
								demo/work.js
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										28
									
								
								demo/work.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | ||||
| /* js-crc32 (C) 2014-present  SheetJS -- http://sheetjs.com */ | ||||
| /*:: declare var CRC32: CRC32Module; */ | ||||
| /*:: declare var self: DedicatedWorkerGlobalScope; */ | ||||
| importScripts('/crc32.js'); | ||||
| /*::self.*/postMessage({t:"ready"}); | ||||
| 
 | ||||
| var recrc = function(f, crc, l) { | ||||
| 	/*::self.*/postMessage({t:"iter", f:f, crc:crc, l:l, sz:f.size}); | ||||
| 	if(l >= f.size) return /*::self.*/postMessage({t:"done"}); | ||||
| 	var sz = 0x100000; if(l + sz > f.size) sz = f.size - l; | ||||
| 	var d = f.slice(l, l + sz); | ||||
| 	var r = new FileReader(); | ||||
| 	r.onload = function(e) { | ||||
| 		var b = new Uint8Array(e.target.result); | ||||
| 		var newcrc = CRC32.buf(b, crc); | ||||
| 		/*::self.*/postMessage({t:"data", crc:newcrc, bytes:l+sz}); | ||||
| 		recrc(f, newcrc, l + sz); | ||||
| 	}; | ||||
| 	r.readAsArrayBuffer(d); | ||||
| }; | ||||
| 
 | ||||
| onmessage = function (oEvent) { | ||||
| 	/*::self.*/postMessage({t:"start"}); | ||||
| 	var f/*:File*/ = oEvent.data; | ||||
|   var seed = 0; | ||||
| 	recrc(f, seed, 0); | ||||
| }; | ||||
| 
 | ||||
							
								
								
									
										58
									
								
								demo/worker.flow.js
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										58
									
								
								demo/worker.flow.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | ||||
| /*jshint browser:true */ | ||||
| 
 | ||||
| function lpad(s/*:string*/, len/*:number*/, chr/*:?string*/)/*:string*/{ | ||||
| 	var L/*:number*/ = len - s.length, C/*:string*/ = chr || " "; | ||||
| 	if(L <= 0) return s; | ||||
| 	return new Array(L+1).join(C) + s; | ||||
| } | ||||
| 
 | ||||
| function is_defined(val/*:any*/, keys/*:Array<string>*/)/*:boolean*/ { | ||||
| 	if(typeof val === "undefined") return false; | ||||
| 	return keys.length === 0 || is_defined(val[keys[0]], keys.slice(1)); | ||||
| } | ||||
| 
 | ||||
| /*## Process Result */ | ||||
| /*:: declare class HTMLPreElement extends HTMLElement { innerText?:string; } */ | ||||
| function process_value(val/*:CRC32Type*/, progress/*:number*/) { | ||||
| 	var output = []; | ||||
| 	output[0] = "Progress  : %" + lpad(progress.toFixed(2), 6, " "); | ||||
| 	output[1] = "Signed    : " + val; | ||||
| 	output[2] = "Unsigned  : " + (val>>>0); | ||||
| 	output[3] = "Hex value : " + lpad((val>>>0).toString(16),8,'0'); | ||||
| 
 | ||||
| 	var out/*:HTMLPreElement*/ = (document.getElementById('out')/*:any*/); | ||||
| 	var o = output.join("\n"); | ||||
| 	if(typeof out.innerText == "undefined") out.textContent = o; | ||||
| 	else out.innerText = o; | ||||
| } | ||||
| 
 | ||||
| /*# Drag and Drop File */ | ||||
| var handle_drop/*:EventHandler*/ = (function(e/*:DragEvent*/) { | ||||
| 	e.stopPropagation(); | ||||
| 	e.preventDefault(); | ||||
| 	if(!e.dataTransfer) return; | ||||
| 	var files/*:FileList*/ = e.dataTransfer.files; | ||||
| 	var f/*:File*/ = files[0]; | ||||
| 
 | ||||
| 	var worker = new Worker("/demo/work.js"); | ||||
| 	worker.postMessage(f); | ||||
| 	worker.onmessage = function(M) { var m = M.data; switch(m.t) { | ||||
| 		case 'ready': break; | ||||
| 		case 'start': break; | ||||
| 		case 'data': process_value(m.crc, 100 * m.bytes / f.size); break; | ||||
| 		case 'done': break; | ||||
| 	} }; | ||||
| }/*:any*/); | ||||
| 
 | ||||
| var handle_drag/*:EventHandler*/ = (function (e/*:DragEvent*/) { | ||||
| 	e.stopPropagation(); | ||||
| 	e.preventDefault(); | ||||
| 	if(e.dataTransfer) e.dataTransfer.dropEffect = 'copy'; | ||||
| }/*:any*/); | ||||
| 
 | ||||
| var drop/*:HTMLDivElement*/ = (document.getElementById('drop')/*:any*/); | ||||
| if(drop.addEventListener) { | ||||
| 	drop.addEventListener('dragenter', handle_drag, false); | ||||
| 	drop.addEventListener('dragover',  handle_drag, false); | ||||
| 	drop.addEventListener('drop',      handle_drop, false); | ||||
| } | ||||
							
								
								
									
										25
									
								
								index.html
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										25
									
								
								index.html
									
									
									
									
									
								
							| @ -1,5 +1,5 @@ | ||||
| <!DOCTYPE html> | ||||
| <!-- crc32.js (C) 2014-present SheetJS http://sheetjs.com --> | ||||
| <!-- crc32.js (C) 2014-present  SheetJS http://sheetjs.com --> | ||||
| <!-- vim: set ts=2: --> | ||||
| <html> | ||||
| <head> | ||||
| @ -18,20 +18,27 @@ | ||||
| #rawdata{ | ||||
| 	width:100%; | ||||
| } | ||||
| a { text-decoration: none } | ||||
| </style> | ||||
| </head> | ||||
| <body> | ||||
| <b>JS-CRC32 Live Demo</b><br /> | ||||
| <a href="https://git.io/crc32">Source Code Repo</a><br /> | ||||
| <a href="https://git.io/crc32_issues">Issues?  Something look weird?  Click here and report an issue</a><br /> | ||||
| <pre> | ||||
| <b><a href="http://sheetjs.com/bits">SheetJS JS-CRC32 Live Demo</a></b> | ||||
| (text works back to IE6; drag and drop works back to IE10) | ||||
| (<b>This demo loads the entire file at once!</b>  For newer browsers, <a href="large.html">try the large file demo</a>) | ||||
| 
 | ||||
| <a href="https://github.com/SheetJS/js-crc32">Source Code Repo</a> | ||||
| <a href="https://github.com/SheetJS/js-crc32/issues">Issues?  Something look weird?  Click here and report an issue</a> | ||||
| <br /> | ||||
| <div id="drop">Drop a text file to compute the CRC-32 checksum</div> | ||||
| <p><input type="file" name="xlfile" id="xlf" /> ... or click here to select a file</p> | ||||
| <textarea id="rawdata">... or paste text here ......</textarea> | ||||
| <input type="file" name="xlfile" id="xlf" /> ... or click here to select a file | ||||
| 
 | ||||
| <textarea id="rawdata">... or paste text here</textarea> | ||||
| <input type="button" id="dotext" value="Click here to process the text"/><br /> | ||||
| Advanced Demo Options: <br /> | ||||
| Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked><br /> | ||||
| <pre id="out">.</pre> | ||||
| <b>Advanced Demo Options:</b> | ||||
| Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked> | ||||
| </pre> | ||||
| <pre id="out"></pre> | ||||
| <br /> | ||||
| <script type="text/javascript">/* jshint browser: true */</script> | ||||
| <script src="shim.js"></script> | ||||
|  | ||||
							
								
								
									
										49
									
								
								large.html
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										49
									
								
								large.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,49 @@ | ||||
| <!DOCTYPE html> | ||||
| <!-- crc32.js (C) 2014-present  SheetJS http://sheetjs.com --> | ||||
| <!-- vim: set ts=2: --> | ||||
| <html> | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <title>JS-CRC32 Live Demo</title> | ||||
| <style> | ||||
| #drop{ | ||||
| 	border:2px dashed #bbb; | ||||
| 	-moz-border-radius:5px; | ||||
| 	-webkit-border-radius:5px; | ||||
| 	border-radius:5px; | ||||
| 	padding:25px; | ||||
| 	text-align:center; | ||||
| 	font:20pt bold,"Vollkorn";color:#bbb | ||||
| } | ||||
| a { text-decoration: none } | ||||
| </style> | ||||
| </head> | ||||
| <body> | ||||
| <pre> | ||||
| <b><a href="http://sheetjs.com/bits">SheetJS JS-CRC32 Live Demo</a></b> | ||||
| (text works back to IE6; drag and drop works back to IE10) | ||||
| 
 | ||||
| <a href="https://github.com/SheetJS/js-crc32">Source Code Repo</a> | ||||
| <a href="https://github.com/SheetJS/js-crc32/issues">Issues?  Something look weird?  Click here and report an issue</a> | ||||
| <br /> | ||||
| <div id="drop">Drop a text file to compute the CRC-32 checksum</div> | ||||
| 
 | ||||
| <pre id="out"></pre> | ||||
| <br /> | ||||
| <script type="text/javascript">/* jshint browser: true */</script> | ||||
| <script src="shim.js"></script> | ||||
| <script src="crc32.js"></script> | ||||
| <script src="demo/worker.flow.js"></script> | ||||
| <script type="text/javascript"> | ||||
| 	var _gaq = _gaq || []; | ||||
| 	_gaq.push(['_setAccount', 'UA-36810333-1']); | ||||
| 	_gaq.push(['_trackPageview']); | ||||
| 
 | ||||
| 	(function() { | ||||
| 		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | ||||
| 		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | ||||
| 		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | ||||
| 	})(); | ||||
| </script> | ||||
| </body> | ||||
| </html> | ||||
| @ -1,6 +1,6 @@ | ||||
| { | ||||
| 	"name": "crc-32", | ||||
| 	"version": "1.0.1", | ||||
| 	"version": "1.0.2", | ||||
| 	"author": "sheetjs", | ||||
| 	"description": "Pure-JS CRC-32", | ||||
| 	"keywords": [ "crc32", "checksum", "crc" ], | ||||
| @ -9,7 +9,6 @@ | ||||
| 	}, | ||||
| 	"main": "./crc32", | ||||
| 	"dependencies": { | ||||
| 		"concat-stream":"", | ||||
| 		"printj":"", | ||||
| 		"exit-on-epipe":"" | ||||
| 	}, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user