improve BinaryInput

This commit is contained in:
Josep M Sobrepere
2024-11-19 15:06:18 +01:00
parent 4e577e8b2c
commit 2f77d62242
+1 -7
View File
@@ -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()