{"id":18673171,"url":"https://github.com/vicanso/elton-compress","last_synced_at":"2025-11-06T23:30:33.805Z","repository":{"id":57486430,"uuid":"172069763","full_name":"vicanso/elton-compress","owner":"vicanso","description":"Compress middleware for elton.","archived":false,"fork":false,"pushed_at":"2023-03-05T06:10:50.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-27T19:45:11.468Z","etag":null,"topics":["compress","elton","lz4","middleware","snappy","zstandard"],"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/vicanso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-02-22T13:19:53.000Z","updated_at":"2022-03-18T02:13:52.000Z","dependencies_parsed_at":"2023-02-08T04:31:43.089Z","dependency_job_id":"fd4cb3cb-2cf7-4d16-aef3-9d9aa64075bc","html_url":"https://github.com/vicanso/elton-compress","commit_stats":null,"previous_names":["vicanso/cod-compress"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Felton-compress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Felton-compress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Felton-compress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Felton-compress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicanso","download_url":"https://codeload.github.com/vicanso/elton-compress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239513383,"owners_count":19651323,"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":["compress","elton","lz4","middleware","snappy","zstandard"],"created_at":"2024-11-07T09:14:12.086Z","updated_at":"2025-11-06T23:30:33.765Z","avatar_url":"https://github.com/vicanso.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elton-compress\n\n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vicanso/elton-compress/blob/master/LICENSE)\n[![Build Status](https://github.com/vicanso/elton-compress/workflows/Test/badge.svg)](https://github.com/vicanso/elton-compress/actions)\n\nMore compressor for elton compress middleware.\n\n- `SnappyCompressor` Snappy compression algorithm is fast, but not aim for maximum compression. It's useful for Intranet. Not support compress level.\n- `ZstdCompressor` Zstandard is a real-time compression algorithm, providing high compression ratios. Compress level is 1-2, default 0(2).\n- `Lz4Compressor` LZ4 is lossless compression algorithm, providing compression speed \u003e 500 MB/s per core, scalable with multi-cores CPU. Compress level higher is better, use 0 for fastest compression.\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\n\t\"github.com/vicanso/elton\"\n\tcompress \"github.com/vicanso/elton-compress\"\n\t\"github.com/vicanso/elton/middleware\"\n)\n\nfunc main() {\n\te := elton.New()\n\t// 需要注意添加的顺序，压缩是按添加的选择顺序选择适合的压缩方式\n\t// 此处只是示例所有的压缩器，正常使用时，按需使用1，2个压缩方式则可\n\tconfig := middleware.NewCompressConfig(\n\t\t\u0026middleware.BrCompressor{\n\t\t\tMinLength: 1024,\n\t\t},\n\t\tnew(middleware.GzipCompressor),\n\t\tnew(compress.SnappyCompressor),\n\t\tnew(compress.ZstdCompressor),\n\t\tnew(compress.S2Compressor),\n\t\t\u0026compress.Lz4Compressor{\n\t\t\tMinLength: 10 * 1024,\n\t\t},\n\t)\n\te.Use(middleware.NewCompress(config))\n\n\te.GET(\"/\", func(c *elton.Context) (err error) {\n\t\tresp, err := http.Get(\"https://code.jquery.com/jquery-3.4.1.min.js\")\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tdefer resp.Body.Close()\n\t\tbuf, err := ioutil.ReadAll(resp.Body)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tc.SetContentTypeByExt(\".js\")\n\t\tc.BodyBuffer = bytes.NewBuffer(buf)\n\t\treturn\n\t})\n\terr := e.ListenAndServe(\":3000\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n## Example\n\n[middleware example](./example/main.go)\n\njquery-3.4.1.min.js(88145 bytes)\n\ncompression | size | ratio | level\n:-:|:-:|:-:|:-:\ngzip | 30827 | 2.859 | 6 \nbr | 29897 | 2.948 | 6\nsnappy | 47709 | 1.847 | - \nzstd | 32816 | 2.686 | 2\nlz4 | 39434 | 2.235 | 6\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Felton-compress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicanso%2Felton-compress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Felton-compress/lists"}