# uproot.compression.compress

Defined in [uproot.compression](https://github.com/scikit-hep/uproot5/blob/db953cf9827349b3d24eb6742404158c1dfd5481/src/uproot/compression.py) on [line 521](https://github.com/scikit-hep/uproot5/blob/db953cf9827349b3d24eb6742404158c1dfd5481/src/uproot/compression.py#L521).

### uproot.compression.compress(data: bytes, compression: [Compression](uproot.compression.Compression.html.md#uproot.compression.Compression)) → bytes

* **Parameters:**
  * **data** (*bytes* *,* *memoryview* *, or* *NumPy array*) – Data to compress.
  * **compression** ([uproot.compression.Compression](uproot.compression.Compression.html.md)) – Algorithm and level
    to use in compressing the data.

Compress `data` using `compression` and return a bytes object (or the
original object in some circumstances).

This function generates ROOT’s 9-byte compression headers (17 bytes for LZ4
because it includes a checksum), with multiple blocks for each 2\*\*24 - 1 bytes
of input. The return value has all blocks concatenated into a single bytes
object, and the splitting into multiple blocks is necessary because the compression
headers can only specify uncompressed and compressed sizes up to 2\*\*24 - 1.

If the compression level (`compression.level`) is zero or the compressed
output would be larger than the input, the input is returned instead, in whatever
format (bytes, memoryview, or NumPy array) it was provided.
