pgcodec7

August 1, 2019 · View on GitHub

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.
makeclean<br/>make clean<br /> 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.
selectfrompgencode7(7,/tmp/sample.jpg);<br/>orfor6bitsgroupingselect * from pgencode7(7, '/tmp/sample.jpg');<br /> 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:

selectpgdecode7(7,....<encodedtext>);<br/>orselect pgdecode7(7, '....<encoded text>');<br /> or select pgdecode7(6, '....');
And you will have byte array back.