/pgcodec7

Encode byte array into ascii character by 7 bits grouping which is less bytes than hexadecimal 4-bits-encoding.

Primary LanguageC

pgcodec7

When encoding byte array into text, one usually group them into 4 resulting hexadecimal character. The encoded size will be twice byte array size. By grouping into 7 or 6 bits, we well have less encoded size.

This project is compiled in Linux against PostgreSQL version 11.
$ make clean
$ make
$ make install

On successful compilation, install this extension in PostgreSQL environment
$ create extension pgcodec7

Let us encode byte array from file -let us say- '/tmp/sample.jpg' with 7 bits grouping.
$ select * from pgencode7(7, '/tmp/sample.jpg');
or for 6 bits grouping $ select * from pgencode7(6, '/tmp/sample.jpg');
You will have set of text. Due to limitted buffer size of 1024, the text result is separated into one or more lines. To decode, concatenate the text lines then supply it to pgdecode7:

$ select pgdecode7(7, '....');
or $ select pgdecode7(6, '....');
And you will have byte array back.