improve BinaryInput
This commit is contained in:
@@ -162,13 +162,7 @@ const textDecoder = new TextDecoder("utf-8", { fatal: true })
|
||||
export const bytesToString = (value: Binary) => {
|
||||
try {
|
||||
const bytes = value.asBytes()
|
||||
const nullPos = bytes.indexOf(0)
|
||||
// if there's a null character (except at the end of the text) we want hex
|
||||
if (
|
||||
bytes.length === 0 ||
|
||||
(nullPos !== -1 && (bytes.length === 1 || nullPos !== bytes.length - 1))
|
||||
)
|
||||
throw null
|
||||
if (bytes.slice(0, 5).every((b) => b < 32)) throw null
|
||||
return textDecoder.decode(bytes)
|
||||
} catch (_) {
|
||||
return value.asHex()
|
||||
|
||||
Reference in New Issue
Block a user