OneIdentity/zstd-js

Error: ZSTD_ERROR: Src size is incorrect, error code: -72

Opened this issue · 1 comments

any suggestions what might be causing this?

@oneidentity_zstd-js_wasm.js?v=3ee57d37:1228 Uncaught (in promise) Error: ZSTD_ERROR: Src size is incorrect,  error code: -72
    at A2.checkError (@oneidentity_zstd-js_wasm.js?v=3ee57d37:1228:13)
    at g2.compress (@oneidentity_zstd-js_wasm.js?v=3ee57d37:1261:13)

source:

import { ZstdInit, ZstdStream, ZstdCodec } from '@oneidentity/zstd-js/wasm';
....
const compressionLevel = 20;
const doCheckSum = true;

ZstdInit().then(({ ZstdStream }: ZstdCodec) => {
    const data: Uint8Array = new TextEncoder().encode(js)
    const compressedStreamData: Uint8Array = ZstdStream.compress(data, compressionLevel, doCheckSum);
    let base64: string = bytesToBase64(compressedStreamData);
    let slconfig: string = prefix + base64
    console.log(slconfig)
    let svg = qrcodeAsSVG({
         value: slconfig,
        length: ((window.innerWidth > 0) ? window.innerWidth : screen.width) / 2
    })
    ....
});

I can call this code twice succefully - fails at the third call

maybe some state initialisation I'm missing?

thanks in advance
Michael

Hi @mhaberler.
I solved it by declaring only once and reusing it. Seems that multiple initialization is causing issues. Here's my version of code. Hope it helps you!

var streamVar;
ZstdInit().then(({ ZstdStream }: ZstdCodec) => {
    streamVar = ZstdStream;
});
myfunc = ()=>{
const data: Uint8Array = new TextEncoder().encode(js)
    const compressedStreamData: Uint8Array = streamVar.compress(data, compressionLevel, doCheckSum);
    let base64: string = bytesToBase64(compressedStreamData);
    let slconfig: string = prefix + base64
    console.log(slconfig)
    let svg = qrcodeAsSVG({
         value: slconfig,
        length: ((window.innerWidth > 0) ? window.innerWidth : screen.width) / 2
    })
});
}

With this, you will be able to use it as many times you want. It won't fail.