> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# crypt.lz4compress

Compresses `plaintext` into the LZ4 Block format and returns the compressed bytes as a string.

```luau theme={null}
crypt.lz4compress(plaintext: string): string
```

There is no header, no checksum, and no trailing size marker, so you have to remember (or store separately) the original byte length to decompress later.

Most commonly used to shrink a large JSON dump or serialized table before writing it to disk with `writefile` or sending it over `request` + `base64encode`.

## Parameters

| Parameter   | Type     | Description           |
| ----------- | -------- | --------------------- |
| `plaintext` | `string` | The data to compress. |

Note: any byte value is allowed, including embedded zeros.

## Returns

`string` - the compressed payload.

## Aliases

* `lz4compress`

## Example

In a chat-event-based Roblox game, stream Bad Apple as ASCII video over a remote at 30fps. <br /> Reason: storing >1800 frames and parsing them would be a lot more easier if you compress the data beforehand.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  local lz4compress = crypt.lz4compress("Hello, world!")
  =======
  -- crypt.lz4compress(plaintext: string): string
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  -- Example script; will not do anything

  local headerParts, blobs = {}, {}
  for _, frame in ipairs(asciiFrames) do
      local packed = crypt.lz4compress(frame)
      table.insert(headerParts, `{#packed}:{#frame}`)
      table.insert(blobs, packed)
  end

  writefile("bad_apple/chunk_0001.txt", `{table.concat(headerParts, ",")}\n{table.concat(blobs)}`)
  ```
</CodeGroup>

<Tip>
  Useful when saving large configs or sending massive data payloads.
</Tip>
