Open sangaman opened 1 year ago
If anyone came to this issue, a workaround is to use this helper function to store buffer in a bytea column as a UTF-8 compliant buffer:
const convertBufferToUtf8CompatibleBytea = (buffer: Buffer): Buffer => {
const base64String = buffer.toString('base64');
return Buffer.from(base64String, 'utf8');
};
This is a function to convert back:
const convertUtf8CompatibleByteaToBuffer = (
base64EncodedData: string,
): Buffer => {
return Buffer.from(base64EncodedData, 'base64');
};
Describe the bug
Pg-mem returns
bytea
types with utf8 encoding, when it should use hex encoding, as per https://www.postgresql.org/docs/current/datatype-binary.htmlI think the offending code is here: https://github.com/oguimbal/pg-mem/blob/master/src/datatypes/datatypes.ts#L218 - it's calling
bufToString
which returns a utf8 encoded string.To Reproduce
Query data from a
bytea
field.pg-mem version
2.6.13