From 0834ae0ad0df0936930b5575c1f1f9240e0d2689 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 17 Feb 2017 18:47:21 -0700 Subject: [PATCH] move hexdump to function --- test/packer.js | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/test/packer.js b/test/packer.js index fb3457c..401f9c0 100644 --- a/test/packer.js +++ b/test/packer.js @@ -26,33 +26,38 @@ var ui8 = new Uint8Array(ab); //console.log(ui8); 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) { - lead = '0' + lead; - } + 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 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; - }).join('\n'); - var trail = ab.byteLength.toString(16); - while (trail.length < 7) { - trail = '0' + trail; + while (lead.length < 7) { + lead = '0' + lead; + } + + 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('DEBUG with hexdump: '); console.log('hexdump ' + onefile.replace(/\.[^\.]*$/, '.bin')); console.log(''); - console.log(' 0 1 2 3 4 5 6 7 8 9 A B C D E F'); - console.log(str + '\n' + trail); + console.log(hexdump(ui8)); console.log(''); console.error('');