UnZstd#
The To install the module, use one of the following packages: Angie: Angie PRO: The module provides the following directives: To use the module, it must be loaded in the Let's compress the test file If the client supports Zstandard, it receives the compressed file unchanged: If the client does not support Zstandard, the The file Version: 658990e Detailed documentation and source code are available at:
HanadaLee/ngx_http_unzstd_filter_moduleunzstd module decompresses backend responses compressed with
Zstandard (Content-Encoding: zstd) for clients that do not accept this
encoding. The backend can then store its data compressed, saving disk space and
I/O, while every client still receives a response it can read.Installation#
angie-module-unzstdangie-pro-module-unzstdDirectives#
unzstd — similar to gunzipunzstd_buffers — similar to gunzip_buffersunzstd_force — decompresses responses even for clients that accept
Zstandardunzstd_dict_file — sets the dictionary file for responses compressed
with a Zstandard dictionary; allowed only in the http contextLoading the Module#
main{} context:load_module modules/ngx_http_unzstd_filter_module.so;
Configuration Example#
server {
listen 80 default_server;
location / {
root /usr/share/angie/html;
index index.html;
}
location /storage {
unzstd on;
proxy_pass http://127.0.0.1:8080;
}
}
# Backend
server {
listen 8080;
location /storage {
root /usr/share/angie;
rewrite ^(.*)$ $1.zst break; # Return the compressed file with .zst suffix
add_header Content-Encoding zstd; # Indicate Zstandard compression in the response header
}
}
Demonstration#
sample.txt with the zstd
utility and place the result where the backend serves it from:$ zstd -19 sample.txt -o sample.txt.zst
sample.txt : 24.11% ( 1.43 MiB => 353 KiB, sample.txt.zst)
$ sudo mkdir -p /usr/share/angie/storage
$ sudo cp sample.txt.zst /usr/share/angie/storage/
$ wc -c /usr/share/angie/storage/sample.txt.zst
361662 /usr/share/angie/storage/sample.txt.zst
$ curl -s -H 'Accept-Encoding: zstd' -o received.zst localhost/storage/sample.txt
$ wc -c received.zst
361662 received.zst
unzstd module decompresses
the file before sending it:$ curl -s -o received.txt localhost/storage/sample.txt
$ wc -c received.txt
1500092 received.txt
received.txt holds the original 1500092-byte text, identical
to sample.txt, rather than the 361662-byte compressed data.Additional Information#