使用node.js中的zlib使用字典压缩数据

使用node.js中的zlib使用字典压缩数据,node.js,zlib,Node.js,Zlib,如果我想对字符串s放气,我可以这样做 var d = zlib.deflateSync(s); 我在字典里注意到我可以设置字典,但我不知道如何使用它 如何使用dictionary对字符串进行放气?对于Nodejs中的用法,您需要传递一个类缓冲区实例作为您希望zlib与之比较的数据的dictionary 请参考此示例: 根据这一点,您可以执行以下操作: var zlib = require('zlib'); var input = 'The dictionary should consi

如果我想对字符串
s
放气,我可以这样做

var d = zlib.deflateSync(s);
我在字典里注意到我可以设置字典,但我不知道如何使用它


如何使用dictionary对字符串进行放气?

对于Nodejs中的用法,您需要传递一个类缓冲区实例作为您希望zlib与之比较的数据的dictionary

请参考此示例:

根据这一点,您可以执行以下操作:

 var zlib = require('zlib');
 var input = 'The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be      compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to    be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.';
 var dictionary = Buffer.from('rdsusedusefulwhencanismostofstringscompresseddatatowithdictionarybethe', 'utf8');
 var result = zlib.deflateSync(input, {dictionary: dictionary});
 console.log(result);

你能给我一个如何使用dictionary进行deflate的代码示例吗?该链接解释了如何生成dictionary及其原因,因此我不明白在这里复制它的原因,而且还有一个实际生成它的示例,这就是为什么我使用他们示例中相同的缓冲区
 var zlib = require('zlib');
 var input = 'The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be      compressed, with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data to    be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.';
 var dictionary = Buffer.from('rdsusedusefulwhencanismostofstringscompresseddatatowithdictionarybethe', 'utf8');
 var result = zlib.deflateSync(input, {dictionary: dictionary});
 console.log(result);