{"id":13645856,"url":"https://github.com/thealetheia/broccoli","last_synced_at":"2025-04-21T17:31:30.018Z","repository":{"id":45745042,"uuid":"255390600","full_name":"thealetheia/broccoli","owner":"thealetheia","description":"Using brotli compression to embed static files in Go.","archived":false,"fork":false,"pushed_at":"2021-08-20T10:56:50.000Z","size":185,"stargazers_count":530,"open_issues_count":6,"forks_count":18,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-29T01:01:59.393Z","etag":null,"topics":[],"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/thealetheia.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}},"created_at":"2020-04-13T17:04:37.000Z","updated_at":"2025-03-17T17:38:50.000Z","dependencies_parsed_at":"2022-09-02T00:10:56.020Z","dependency_job_id":null,"html_url":"https://github.com/thealetheia/broccoli","commit_stats":null,"previous_names":["aletheia-icu/broccoli"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thealetheia%2Fbroccoli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thealetheia%2Fbroccoli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thealetheia%2Fbroccoli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thealetheia%2Fbroccoli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thealetheia","download_url":"https://codeload.github.com/thealetheia/broccoli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250100435,"owners_count":21374937,"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":[],"created_at":"2024-08-02T01:02:43.601Z","updated_at":"2025-04-21T17:31:29.699Z","avatar_url":"https://github.com/thealetheia.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# 🥦 Broccoli\n\u003e `go get -u aletheia.icu/broccoli`\n\n[![GoDoc](https://godoc.org/aletheia.icu/broccoli/fs?status.svg)](https://godoc.org/aletheia.icu/broccoli/fs)\n[![Travis](https://travis-ci.org/aletheia-icu/broccoli.svg)](https://travis-ci.org/aletheia-icu/broccoli)\n[![Go Report Card](https://goreportcard.com/badge/aletheia.icu/broccoli/fs)](https://goreportcard.com/report/aletheia.icu/broccoli/fs)\n[![codecov.io](https://codecov.io/gh/aletheia-icu/broccoli/coverage.svg)](https://codecov.io/gh/aletheia-icu/broccoli)\n\nBroccoli uses [brotli](https://github.com/google/brotli) compression to embed a\nvirtual file system of static files inside Go executables.\n\nA few reasons to pick broccoli over the alternatives:\n\n- ⚡️ The average is 13-25% smaller binary size due to use of superior\ncompression algorithm, [brotli](https://github.com/google/brotli).\n- 💾 Broccoli supports bundling of multiple source directories, only relies on\n`go generate` command-line interface and doesn't require configuration files.\n- 🔑 Optional decompression is something you may want; when it's enabled, files\nare decompressed only when they are read the first time.\n- 🚙 You might want to target `wasm/js` architecture.\n- 📰 There is `-gitignore` option to ignore files, already ignored by your\nexisting .gitignore files.\n\n### Performance\nAdmittedly, there are already many packages providing similar functionality out\nthere in the wild. Tim Shannon did an overall pretty good overview of them in\n[Choosing A Library to Embed Static Assets in Go](https://tech.townsourced.com/post/embedding-static-files-in-go/),\nbut it should be outdated by at least two years, so although we subscribe to the\nanalysis, we cannot guarantee whether if it's up–to–date. Most if not all of the\npackages mentioned in the article, rely on gzip compression and most of them,\nunfortunately are not compatible with `wasm/js` architecture, due to some quirk\nthat has to do with their use of `http` package. This, among other things, was\nthe driving force behind the creation of broccoli.\n\nThe most feature-complete library from the comparison table seems to be\n[fileb0x](https://github.com/UnnoTed/fileb0x).\n\n#### How does broccoli compare to fileb0x?\nFeature                               | fileb0x             | broccoli\n---------------------                 | -----------         | ------------------\ncompression                           | gzip                | brotli (-20% avg.)\noptional decompression                | yes                 | yes\ncompression levels                    | yes                 | yes (1-11)\ndifferent build tags for each file    | yes                 | no\nexclude / ignore files                | glob                | glob\nunexported vars/funcs                 | optional            | optional\nvirtual memory file system            | yes                 | yes\nhttp file system                      | yes                 | yes\nreplace text in files                 | yes                 | no\nglob support                          | yes                 | yes\nregex support                         | no                  | no\nconfig file                           | yes                 | no\nupdate files remotely                 | yes                 | no\n.gitignore support                    | no                  | yes\n\n#### How does it compare to others?\n![](https://i.imgur.com/vB9Miae.png)\n\nBroccoli seems to outperform the existing solutions.\n\nWe did [benchmarks](https://vcs.aletheia.icu/lads/broccoli-bench), please feel\nfree to review them and correct us whenever our methodology could be flawed.\n\n### Usage\n```\n$ broccoli\nUsage: broccoli [options]\n\nBroccoli uses brotli compression to embed a virtual file system in Go executables.\n\nOptions:\n\t-src folder[,file,file2]\n\t\tThe input files and directories, \"public\" by default.\n\t-o\n\t\tName of the generated file, follows input by default.\n\t-var=br\n\t\tName of the exposed variable, \"br\" by default.\n\t-include *.html,*.css\n\t\tWildcard for the files to include, no default.\n\t-exclude *.wasm\n\t\tWildcard for the files to exclude, no default.\n\t-opt\n\t\tOptional decompression: if enabled, files will only be decompressed\n\t\ton the first time they are read.\n\t-gitignore\n\t\tEnables .gitignore rules parsing in each directory, disabled by default.\n\t-quality [level]\n\t\tBrotli compression level (1-11), the highest by default.\n\nGenerate a broccoli.gen.go file with the variable broccoli:\n\t//go:generate broccoli -src assets -o broccoli -var broccoli\n\nGenerate a regular public.gen.go file, but include all *.wasm files:\n\t//go:generate broccoli -src public -include=\"*.wasm\"\n```\n\nHow broccoli is used in the user code:\n```go\n//go:generate broccoli -src=public,others -o assets\n\nfunc init() {\n    br.Walk(\"public\", func(path string, info os.FileInfo, err error) error {\n        // walk...\n        return nil\n    })\n}\n\nfunc main() {\n    http.ListenAndServe(\":8080\", br.Serve(\"public\"))\n}\n```\n\n### Credits\nLicense: [MIT](https://vcs.aletheia.icu/lads/broccoli/src/branch/master/LICENSE)\n\nWe would like to thank brotli development team from Google and Andy Balholm, for\nhis c2go pure-Go port of the library. Broccoli itself is an effort of a mentoring\nexperiment, lead by [@tucnak](https://github.com/tucnak) on the foundation of\n[Aletheia](https://aletheia.icu).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthealetheia%2Fbroccoli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthealetheia%2Fbroccoli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthealetheia%2Fbroccoli/lists"}