If the client accepts gzip, just serve the file as a gzip-encoded plain text. If it doesn't, gunzip it first.
This was previously at https://github.com/vector-im/riot-web/blob/develop/scripts/rageshake.go, but it's not really exclusive to riot-web, and given I'm about to add some more complexity to it, I'd like for it to be in its own repo.