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, ' ')
|
||||
}
|
||||
|
||||
let lastLine = ''
|
||||
let repeat = false
|
||||
|
||||
while (offset < total) {
|
||||
const values = [offset.toString(16).padStart(8, '0')]
|
||||
const offsetStr = offset.toString(16).padStart(8, '0')
|
||||
const values = []
|
||||
const asciiValues: string[] = []
|
||||
let cnt = 0
|
||||
while (offset < total && cnt < 16) {
|
||||
@ -31,7 +35,7 @@ const hexDump = computed(() => {
|
||||
values.push(byte.toString(16).padStart(2, '0'))
|
||||
|
||||
const char = String.fromCharCode(byte)
|
||||
if (char > ' ' && char <= 'a') {
|
||||
if (char >= ' ' && char <= '~') {
|
||||
asciiValues.push(char)
|
||||
} else {
|
||||
asciiValues.push('.')
|
||||
@ -60,7 +64,21 @@ const hexDump = computed(() => {
|
||||
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, ' '))
|
||||
return lines.join('\n')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user