move hexdump to function

This commit is contained in:
AJ ONeal 2017-02-17 18:47:21 -07:00
parent b4f0cdee78
commit 0834ae0ad0
1 changed files with 24 additions and 19 deletions

View File

@ -26,6 +26,10 @@
var ui8 = new Uint8Array(ab); var ui8 = new Uint8Array(ab);
//console.log(ui8); //console.log(ui8);
var bytecount = 0; var bytecount = 0;
function hexdump() {
var head = ' 0 1 2 3 4 5 6 7 8 9 A B C D E F';
var trail;
var str = [].slice.call(ui8).map(function (i) { var str = [].slice.call(ui8).map(function (i) {
var h = i.toString(16); var h = i.toString(16);
if (h.length < 2) { if (h.length < 2) {
@ -42,17 +46,18 @@
return lead + ' ' + str; return lead + ' ' + str;
}).join('\n'); }).join('\n');
var trail = ab.byteLength.toString(16); trail = ab.byteLength.toString(16);
while (trail.length < 7) { while (trail.length < 7) {
trail = '0' + trail; trail = '0' + trail;
} }
return head + '\n' + str + '\n' + trail
}
console.log(''); console.log('');
console.log('DEBUG with hexdump: '); console.log('DEBUG with hexdump: ');
console.log('hexdump ' + onefile.replace(/\.[^\.]*$/, '.bin')); console.log('hexdump ' + onefile.replace(/\.[^\.]*$/, '.bin'));
console.log(''); console.log('');
console.log(' 0 1 2 3 4 5 6 7 8 9 A B C D E F'); console.log(hexdump(ui8));
console.log(str + '\n' + trail);
console.log(''); console.log('');
console.error(''); console.error('');