yoshihitoh / zstd-codec

Zstandard codec for Node.js and Web, powered by Emscripten
MIT License
183 stars 28 forks source link

RangeError: WebAssembly.Memory(): could not allocate memory #213

Open varyzheng opened 2 years ago

varyzheng commented 2 years ago

I'm using zstd-codec v0.1.2 in nodejs, and after decompressed about 100 times, it will throw this exception. Maybe there is a memory leap in my code, but I don't know the reason.

const ZstdCodec = require('zstd-codec').ZstdCodec;
export const decompress = (buffer: Buffer): Promise<Buffer> => {
  return new Promise((resolve) => {
    ZstdCodec.run((zstd) => {
      const simple = new zstd.Simple();
      const data = simple.decompress(buffer);
      resolve(data);
    });
  });
};

And I call this function in other module like this:

import { decompress } from './util';
async function dec (buffer) {
  const afterDecompress =  await decompress(buffer);
  return afterDecompress;
}