| 1 |
// Copyright (C) 2024 Sumner Evans |
| 2 |
// |
| 3 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
|
| 7 |
package gnuzip |
| 8 |
|
| 9 |
import ( |
| 10 |
"bytes" |
| 11 |
"compress/gzip" |
| 12 |
) |
| 13 |
|
| 14 |
func GZip(body []byte) ([]byte, error) { |
| 15 |
var compressedBuffer bytes.Buffer |
| 16 |
writer := gzip.NewWriter(&compressedBuffer) |
| 17 |
if _, err := writer.Write(body); err != nil { |
| 18 |
return nil, err |
| 19 |
} |
| 20 |
return compressedBuffer.Bytes(), writer.Close() |
| 21 |
} |