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,33 +26,38 @@
var ui8 = new Uint8Array(ab); var ui8 = new Uint8Array(ab);
//console.log(ui8); //console.log(ui8);
var bytecount = 0; var bytecount = 0;
var str = [].slice.call(ui8).map(function (i) {
var h = i.toString(16);
if (h.length < 2) {
h = '0' + h;
}
return h;
}).join('').match(/.{1,2}/g).join(' ').match(/.{1,48}/g).map(function (str) {
var lead = bytecount.toString(16);
bytecount += 16;
while (lead.length < 7) { function hexdump() {
lead = '0' + lead; 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 h = i.toString(16);
if (h.length < 2) {
h = '0' + h;
}
return h;
}).join('').match(/.{1,2}/g).join(' ').match(/.{1,48}/g).map(function (str) {
var lead = bytecount.toString(16);
bytecount += 16;
return lead + ' ' + str; while (lead.length < 7) {
}).join('\n'); lead = '0' + lead;
var trail = ab.byteLength.toString(16); }
while (trail.length < 7) {
trail = '0' + trail; return lead + ' ' + str;
}).join('\n');
trail = ab.byteLength.toString(16);
while (trail.length < 7) {
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('');