Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-6586

Compression Levels Don't Work for @mongodb-js/zstd v1.2.2

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      Reproducible Environment:

      • Apple M1 Mac ie Darwin arm 64 
      • Linux x64

       

      Generated zstd function during build does not include level parameter in node_modules/@mongodb-js/zstd/index.js:

      // NB: If you update any type signatures to diverge from bindings itself, make// sure to update how index.d.ts is generated (napi build --dts ...)
      
      const { compress: _compress, decompress: _decompress } =require('./bindings');
      
      // Error objects created via napi don't have JS stacks; wrap them so .stack is present// https://github.com/nodejs/node/issues/25318#issuecomment-451068073
      exports.compress = async function compress(data) {  try {    return await _compress(data);  } catch (e) {    throw new Error(`zstd: ${e.message}`);  }};exports.decompress = async function decompress(data) {  try {    return await _decompress(data);  } catch (e) {    throw new Error(`zstd: ${e.message}`);  }};
       

      I had to create a patch to add in level and get the compression level parameter working:

       diff --git a/node_modules/@mongodb-js/zstd/index.js b/node_modules/@mongodb-js/zstd/index.js
       index 422ca93..cd119a0 100644
       --- a/node_modules/@mongodb-js/zstd/index.js
       +++ b/node_modules/@mongodb-js/zstd/index.js
       @@ -6,9 +6,9 @@ const { compress: _compress, decompress: _decompress } = require('./bindings');
        // Error objects created via napi don't have JS stacks; wrap them so .stack is present
        // https://github.com/nodejs/node/issues/25318#issuecomment-451068073
        
       -exports.compress = async function compress(data) {
       +exports.compress = async function compress(data, level) {
          try {
       -    return await _compress(data);
       +    return await _compress(data, level);
          } catch (e) {
            throw new Error(`zstd: ${e.message}`);
          } 

            Assignee:
            Unassigned Unassigned
            Reporter:
            myn8m3iswinton@gmail.com Winton Chen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: