Skip to content

Commit

Permalink
Add readme content
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Nov 4, 2019
1 parent 24d2613 commit 82f6aa9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Expand Up @@ -14,8 +14,8 @@ insert_final_newline = true
[*.{c,h}]
indent_style = tab

# YAML files want space indentation
[*.{yml}]
# YAML, MD files want space indentation
[*.{yml,md}]
indent_style = space
indent_size = 4

7 changes: 5 additions & 2 deletions Makefile
@@ -1,7 +1,10 @@

# Where are include/zlib.h and lib/libz.so installed?
ZLIB_PATH = /usr
ZLIB_INC_PATH = $(ZLIB_PATH)/include
ZLIB_LIB_PATH = $(ZLIB_PATH)/lib

# This should not require modification
MODULE_big = gzip
OBJS = pg_gzip.o
EXTENSION = gzip
Expand All @@ -12,8 +15,8 @@ EXTRA_CLEAN =
CURL_CONFIG = curl-config
PG_CONFIG = pg_config

CFLAGS += -I$(ZLIB_PATH)/include
LIBS += -L$(ZLIB_PATH)/lib -lz
CFLAGS += -I$(ZLIB_INC_PATH)/include
LIBS += -L$(ZLIB_LIB_PATH)/lib -lz
SHLIB_LINK := $(LIBS)

ifdef DEBUG
Expand Down
43 changes: 42 additions & 1 deletion README.md
@@ -1 +1,42 @@
# pgsql-gzip
# PostgreSQL GZIP/GUNZIP Functions

[![Build Status](https://api.travis-ci.org/pramsey/pgsql-gzip.svg?branch=master)](https://travis-ci.org/pramsey/pgsql-gzip)

## Motivation

Sometimes you just need to compress your `bytea` object before you return it to the client.

Sometimes you receive a compressed binary object from the client, and you have to uncompress it to do something useful.

This extension is for that.

## Examples

> SELECT gzip('this is my this is my this is my this is my text');

gzip
--------------------------------------------------
\x789c2bc9c82c5600a2dc4a851282ccd48a1200a382112e


> SELECT encode(gunzip('\x789c2bc9c82c5600a2dc4a851282ccd48a1200a382112e'), 'escape')

encode
--------------------------------------------------
this is my this is my this is my this is my text
(1 row)


## Functions

* `gzip(uncompressed BYTEA, [compression_level INTEGER])` returns `BYTEA`
* `gunzip(compressed BYTEA)` returns `BYTEA`


## Installation

### UNIX

If you have PostgreSQL devel packages and zlib installed, you should have `pg_config` on your path, so you should be able to just run `make`, then `make install`, then in your database `CREATE EXTENSION gzip`.

If your `libz` is installed in a non-standard location, you may need to edit `ZLIB_PATH`.
3 changes: 3 additions & 0 deletions pg_gzip.c
Expand Up @@ -85,6 +85,9 @@ Datum pg_gzip(PG_FUNCTION_ARGS)
uint8 out[ZCHUNK];
bytea *compressed;

if (compression_level < -1 || compression_level > 9)
elog(ERROR, "invalid compression level: %d", compression_level);

initStringInfo(&si);

/* Prepare the z_stream state */
Expand Down

0 comments on commit 82f6aa9

Please sign in to comment.