---
source: https://iinventedlight.com/library/notes/go-compress-zlib.md
title: "Go compress/zlib: read and write zlib compressed data"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go); BSD-3-Clause (Go); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go, compress/zlib package reference; Go, compress/zlib source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-compress-zlib"
tags: [go, zlib, compress, flate, io]
client: Librarian
sources:
  - id: S1
    title: "compress/zlib package reference"
    publisher: Go
    url: https://pkg.go.dev/compress/zlib
    accessed: 2026-11-24
    license: "BSD-3-Clause"
  - id: S2
    title: "compress/zlib source"
    publisher: Go
    url: https://go.dev/src/compress/zlib/reader.go
    accessed: 2026-11-24
    license: "BSD-3-Clause"
---
# Go compress/zlib: read and write zlib compressed data
**Answer:** This package reads and writes compressed data in the zlib format from RFC 1950.

## Readers and writers

A filter uncompresses bytes during reading.

A separate filter compresses bytes during writing.

NewWriter sends zlib data to a buffer.

NewReader is how you read that data back.

NewWriterLevel picks the compression level.

## Errors and extras

ErrChecksum is returned when reading ZLIB data that has an invalid checksum.

NewReaderDict takes a reader and a dict.

The reader source imports flate and adler32.

## See also

- [go-compress-gzip](https://iinventedlight.com/library/notes/go-compress-gzip/)
- [go-archive-zip](https://iinventedlight.com/library/notes/go-archive-zip/)
- [go-io](https://iinventedlight.com/library/notes/go-io/)

## Claims

- id: C1
  claim: The package reads and writes zlib format compressed data.
  source: S1
  evidence: "reading and writing of zlib format compressed data"

- id: C2
  claim: The format is specified in RFC 1950.
  source: S1
  evidence: "as specified in RFC 1950"

- id: C3
  claim: ErrChecksum is returned for an invalid checksum.
  source: S2
  evidence: "invalid checksum"

- id: C4
  claim: The format is specified in RFC 1950.
  source: S2
  evidence: "as specified in RFC 1950"

## Sources

- [S1] compress/zlib package reference. Go. https://pkg.go.dev/compress/zlib . License: BSD-3-Clause. Accessed 2026-11-24.

- [S2] compress/zlib source. Go. https://go.dev/src/compress/zlib/reader.go . License: BSD-3-Clause. Accessed 2026-11-24.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, compress/zlib package reference; Go, compress/zlib source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
