Squeeze hex dump to get rid of duplicate lines
This commit is contained in:
parent
98ad0d4dfe
commit
6d79a35ce5
@ -14,8 +14,12 @@ const hexDump = computed(() => {
|
|||||||
return ''.padEnd(80, ' ')
|
return ''.padEnd(80, ' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastLine = ''
|
||||||
|
let repeat = false
|
||||||
|
|
||||||
while (offset < total) {
|
while (offset < total) {
|
||||||
const values = [offset.toString(16).padStart(8, '0')]
|
const offsetStr = offset.toString(16).padStart(8, '0')
|
||||||
|
const values = []
|
||||||
const asciiValues: string[] = []
|
const asciiValues: string[] = []
|
||||||
let cnt = 0
|
let cnt = 0
|
||||||
while (offset < total && cnt < 16) {
|
while (offset < total && cnt < 16) {
|
||||||
@ -31,7 +35,7 @@ const hexDump = computed(() => {
|
|||||||
values.push(byte.toString(16).padStart(2, '0'))
|
values.push(byte.toString(16).padStart(2, '0'))
|
||||||
|
|
||||||
const char = String.fromCharCode(byte)
|
const char = String.fromCharCode(byte)
|
||||||
if (char > ' ' && char <= 'a') {
|
if (char >= ' ' && char <= '~') {
|
||||||
asciiValues.push(char)
|
asciiValues.push(char)
|
||||||
} else {
|
} else {
|
||||||
asciiValues.push('.')
|
asciiValues.push('.')
|
||||||
@ -60,7 +64,21 @@ const hexDump = computed(() => {
|
|||||||
asciiValues.push('|')
|
asciiValues.push('|')
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.push(values.join(' ') + asciiValues.join(''))
|
const line = values.join(' ')
|
||||||
|
if (line !== lastLine) {
|
||||||
|
if (repeat) {
|
||||||
|
lines.push('*'.padEnd(80, ' '))
|
||||||
|
}
|
||||||
|
repeat = false
|
||||||
|
|
||||||
|
lines.push([offsetStr, line].join(' ') + asciiValues.join(''))
|
||||||
|
lastLine = line
|
||||||
|
} else {
|
||||||
|
repeat = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (repeat) {
|
||||||
|
lines.push('*'.padEnd(80, ' '))
|
||||||
}
|
}
|
||||||
lines.push(offset.toString(16).padStart(8, '0').padEnd(80, ' '))
|
lines.push(offset.toString(16).padStart(8, '0').padEnd(80, ' '))
|
||||||
return lines.join('\n')
|
return lines.join('\n')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user