Files
duckdb-ui/ts/pkgs/duckdb-data-values/src/conversion/stringFromBlob.ts
Jeff Raymakers 0edb52054a add duckdb-ui-client & other ts pkgs (#10)
* add duckdb-ui-client & other ts pkgs

* workflow fixes

* fix working dir

* no sparse checkout; specify package.json path

* path to pnpm-lock.yaml

* add check & build test

* workflow step descriptions

* use comments & names

* one more naming tweak
2025-06-13 09:16:05 -07:00

18 lines
472 B
TypeScript

/** Matches BLOB-to-VARCHAR conversion behavior of DuckDB. */
export function stringFromBlob(bytes: Uint8Array): string {
let result = '';
for (const byte of bytes) {
if (
byte <= 0x1f ||
byte === 0x22 /* single quote */ ||
byte === 0x27 /* double quote */ ||
byte >= 0x7f
) {
result += `\\x${byte.toString(16).toUpperCase().padStart(2, '0')}`;
} else {
result += String.fromCharCode(byte);
}
}
return result;
}