-
Notifications
You must be signed in to change notification settings - Fork 0
compression
Angeal185 edited this page Jun 19, 2020
·
2 revisions
sicarii has built in support for gzip, brotli and deflate compression.
- automatic compression can be enabled/disabled individually for your render/static/upload/download/cache data.
-
config.compression.gzip.enablewill enable/disable gzip compression -
config.compression.gzip.settingswill enable you to configure gzip compression -
config.compression.gzip.settingsaccepts all nodejs gzip settings -
config.compression.gzip.prezippedwill enable you to load/serve already compressed files - with
config.compression.gzip.prezippedenabled, you do not have to store an uncompressed copy of the data -
config.compression.gzip.extwill set the default gzip file extension
gzip compression can also be used anywhere via the app.gzip method:
/**
* @app.gzip(data, method, options, callback)
*
* @param {Buffer/TypedArray/DataView/ArrayBuffer/string} data
* @param {boolean} method ~ true = compress | false = decompress
* @param {object} options ~ optional | fallback to config.compression.gzip.settings
* @param {function} callback ~ function(err,res) | optional | no callback for sync
**/
let str = 'test'
//gzipSync
str = app.gzip(str, true);
//gunzipSync
str = app.gzip(str, false);
console.log(str.toString())
// test
//gzip
app.gzip(str, true, function(err,res){
//gunzip
app.gzip(res, false, function(err,str){
console.log(str.toString())
// test
})
})-
config.compression.brotli.enablewill enable/disable brotli compression -
config.compression.brotli.settingswill enable you to configure brotli compression -
config.compression.brotli.settingsaccepts all nodejs brotli settings -
config.compression.brotli.prezippedwill enable you to load/serve already compressed files - with
config.compression.brotli.prezippedenabled, you do not have to store an uncompressed copy of the data -
config.compression.brotli.extwill set the default brotli file extension
brotli compression can also be used anywhere via the app.brotli method:
/**
* @app.brotli(data, method, options, callback)
*
* @param {Buffer/TypedArray/DataView/ArrayBuffer/string} data
* @param {boolean} method ~ true = compress | false = decompress
* @param {object} options ~ optional | fallback to config.compression.brotli.settings
* @param {function} callback ~ function(err,res) | optional | no callback for sync
**/
let str = 'test'
//brotliCompressSync
str = app.brotli(str, true);
//brotliDecompressSync
str = app.brotli(str, false);
console.log(str.toString())
// test
//brotliCompress
app.brotli(str, true, function(err,res){
//brotliDecompress
app.brotli(res, false, function(err,str){
console.log(str.toString())
// test
})
})-
config.compression.deflate.enablewill enable/disable deflate compression -
config.compression.deflate.settingswill enable you to configure deflate compression -
config.compression.deflate.settingsaccepts all nodejs deflate settings -
config.compression.deflate.prezippedwill enable you to load/serve already compressed files - with
config.compression.deflate.prezippedenabled, you do not have to store an uncompressed copy of the data -
config.compression.deflate.extwill set the default deflate file extension
deflate compression can also be used anywhere via the app.deflate method:
/**
* @app.deflate(data, method, options, callback)
*
* @param {Buffer/TypedArray/DataView/ArrayBuffer/string} data
* @param {boolean} method ~ true = compress | false = decompress
* @param {object} options ~ optional | fallback to config.compression.deflate.settings
* @param {function} callback ~ function(err,res) | optional | no callback for sync
**/
let str = 'test'
//deflateSync
str = app.deflate(str, true);
//inflateSync
str = app.deflate(str, false);
console.log(str.toString())
// test
//deflate
app.deflate(str, true, function(err,res){
//inflate
app.deflate(res, false, function(err,str){
console.log(str.toString())
// test
})
})