---
layout: doc
title: general / compress
---
# compress

### NAME

    compress() - compress a string or buffer into a zlib buffer

### SYNOPSIS

    buffer compress( string | buffer data );

### DESCRIPTION

    Compresses data using zlib and returns the compressed bytes in a buffer.
    The argument may be either a string or a buffer.

    This efun performs in-memory zlib compression.  It does not create a
    gzip file header and does not write to the filesystem.  Use
    compress_file() to gzip a file on disk.

    If data is not a string or buffer, undefined is returned.

### SEE ALSO

    uncompress(3), compress_file(3), uncompress_file(3),
    allocate_buffer(3), read_buffer(3), write_buffer(3)
