"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._withString = exports._withNativeString = exports._createString = void 0;
const image_magick_1 = require("../../image-magick");
function _createString(instance) {
    if (instance === 0)
        return null;
    return image_magick_1.ImageMagick._api.UTF8ToString(instance);
}
exports._createString = _createString;
function _withNativeString(native, str, func) {
    const length = native.lengthBytesUTF8(str) + 1;
    const instance = native._malloc(length);
    try {
        native.stringToUTF8(str, instance, length);
        return func(instance);
    }
    finally {
        native._free(instance);
    }
}
exports._withNativeString = _withNativeString;
function _withString(str, func) {
    return _withNativeString(image_magick_1.ImageMagick._api, str, func);
}
exports._withString = _withString;
