var _init;
var instance;
var heap;
var IMPORT_OBJECT = {
  env: {
    emscripten_notify_memory_growth: function emscripten_notify_memory_growth(index) {
      heap = new Uint8Array(instance.exports.memory.buffer);
    }
  }
};
/**
 * ZSTD (Zstandard) decoder.
 */
var ZSTDDecoder = /*#__PURE__*/function () {
  function ZSTDDecoder() {}
  var _proto = ZSTDDecoder.prototype;
  _proto.init = function init() {
    if (_init) return _init;
    if (typeof fetch !== 'undefined') {
      // Web.
      _init = fetch('data:application/wasm;base64,' + wasm).then(function (response) {
        return response.arrayBuffer();
      }).then(function (arrayBuffer) {
        return WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT);
      }).then(this._init);
    } else {
      // Node.js.
      _init = WebAssembly.instantiate(Buffer.from(wasm, 'base64'), IMPORT_OBJECT).then(this._init);
    }
    return _init;
  };
  _proto._init = function _init(result) {
    instance = result.instance;
    IMPORT_OBJECT.env.emscripten_notify_memory_growth(0); // initialize heap.
  };
  _proto.decode = function decode(array, uncompressedSize) {
    if (uncompressedSize === void 0) {
      uncompressedSize = 0;
    }
    if (!instance) throw new Error("ZSTDDecoder: Await .init() before decoding.");
    // Write compressed data into WASM memory.
    var compressedSize = array.byteLength;
    var compressedPtr = instance.exports.malloc(compressedSize);
    heap.set(array, compressedPtr);
    // Decompress into WASM memory.
    uncompressedSize = uncompressedSize || Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));
    var uncompressedPtr = instance.exports.malloc(uncompressedSize);
    var actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);
    // Read decompressed data and free WASM memory.
    var dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);
    instance.exports.free(compressedPtr);
    instance.exports.free(uncompressedPtr);
    return dec;
  };
  return ZSTDDecoder;
}();
/**
 * BSD License
 *
 * For Zstandard software
 *
 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 *  * Neither the name Facebook nor the names of its contributors may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
// wasm:begin
var wasm = '[encoded data, 38976 characters]';
// wasm:end

export { ZSTDDecoder };
//# sourceMappingURL=zstddec.esm.js.map
