{"id":16828081,"url":"https://github.com/kataras/compress","last_synced_at":"2025-06-15T12:06:58.277Z","repository":{"id":57532918,"uuid":"278760154","full_name":"kataras/compress","owner":"kataras","description":"HTTP Compression for Go","archived":false,"fork":false,"pushed_at":"2024-04-09T13:08:13.000Z","size":35,"stargazers_count":17,"open_issues_count":5,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T03:33:20.517Z","etag":null,"topics":["brotli","compression","deflate","go","golang","gzip","http","iris","snappy"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kataras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"kataras"}},"created_at":"2020-07-11T00:39:49.000Z","updated_at":"2025-03-07T07:06:17.000Z","dependencies_parsed_at":"2024-06-19T00:26:44.569Z","dependency_job_id":"57aac71e-7e11-45ab-b6c6-867c07db3a00","html_url":"https://github.com/kataras/compress","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/kataras/compress","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fcompress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fcompress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fcompress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fcompress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kataras","download_url":"https://codeload.github.com/kataras/compress/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fcompress/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259971379,"owners_count":22940012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brotli","compression","deflate","go","golang","gzip","http","iris","snappy"],"created_at":"2024-10-13T11:24:34.831Z","updated_at":"2025-06-15T12:06:58.256Z","avatar_url":"https://github.com/kataras.png","language":"Go","readme":"# Compress\r\n\r\n[![build status](https://img.shields.io/github/actions/workflow/status/kataras/compress/ci.yml?style=for-the-badge)](https://github.com/kataras/compress/actions) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/compress) [![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/compress)\r\n\r\nFast and easy-to-use compression package for Go applications.\r\n\r\n## Installation\r\n\r\nThe only requirement is the [Go Programming Language](https://go.dev/dl/).\r\n\r\n```sh\r\n$ go get github.com/kataras/compress\r\n```\r\n\r\n## Getting Started\r\n\r\nImport the package:\r\n\r\n```go\r\npackage main\r\n\r\nimport \"github.com/kataras/compress\"\r\n```\r\n\r\nWrap a handler to enable writing and reading using the best offered compression:\r\n\r\n```go\r\nimport \"net/http\"\r\n\r\nmux := http.NewServeMux()\r\n// [...]\r\nhttp.ListenAndServe(\":8080\", compress.Handler(mux))\r\n```\r\n\r\nWrap any `io.Writer` for writing data using compression with `NewWriter`:\r\n\r\n```go\r\nimport \"bytes\"\r\nimport \"encoding/json\"\r\n\r\nbuf := new(bytes.Buffer)\r\n\r\nw, err := compress.NewWriter(buf, compress.GZIP, -1)\r\nif err != nil {\r\n    panic(err)\r\n}\r\n\r\njson.NewEncoder(w).Encode(payload{Data: \"my data\"})\r\n\r\nw.Close()\r\n```\r\n\r\nWrap any `io.Reader` for reading compressed data with `NewReader`:\r\n\r\n```go\r\n// Where resp.Body is an io.Reader.\r\nr, err := compress.NewReader(resp.Body, compress.GZIP)\r\nif err != nil {\r\n    panic(err)\r\n}\r\ndefer r.Close()\r\n\r\nbody, err := ioutil.ReadAll(r)\r\n```\r\n\r\nTo retrieve the underline `http.ResponseWriter` please use `w.(*compress.ResponseWriter).ResponseWriter`.\r\n\r\nExample Code:\r\n```go\r\nimport \"net/http\"\r\n\r\nfunc handler(w http.ResponseWriter, r *http.Request) {\r\n    target := \"/your/asset.js\"\r\n\r\n\tif pusher, ok := w.(*compress.ResponseWriter).ResponseWriter.(http.Pusher); ok {\r\n\t\terr := pusher.Push(target, \u0026http.PushOptions{\r\n            Header: http.Header{\r\n                \"Accept-Encoding\": r.Header[\"Accept-Encoding\"],\r\n        }})\r\n\t\tif err != nil {\r\n\t\t\tif err == http.ErrNotSupported {\r\n\t\t\t\thttp.Error(w, \"HTTP/2 push not supported\", http.StatusHTTPVersionNotSupported)\r\n\t\t\t} else {\r\n\t\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\r\n\t\t\t}\r\n\t\t\treturn\r\n\t\t}\r\n    }\r\n    \r\n    // [...]\r\n}\r\n```\r\n\r\n\u003e The `http.CloseNotifier` is obselete by Go authors, please use `Request.Context().Done()` instead.\r\n\r\nSupported compression algorithms:\r\n\r\n- gzip\r\n- deflate\r\n- brotli\r\n- snappy\r\n\r\nPlease navigate through [_examples](_examples) directory for more.\r\n\r\n## License\r\n\r\nThis software is licensed under the [MIT License](LICENSE).\r\n","funding_links":["https://github.com/sponsors/kataras"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fcompress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkataras%2Fcompress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fcompress/lists"}