function saveLibrary(lib, saveLocation, NVPArgs)

    arguments
        lib(1,1) bioinfo.pipeline.library.Library
        saveLocation(1,1) string {mustBeFolder} = pwd
        NVPArgs.Overwrite(1,1) logical = false
    end

    libFile = fullfile(saveLocation, sprintf("%s.mat", lib.Name));

    if isfile(libFile) && ~NVPArgs.Overwrite
        error(message("bioinfo:Library:saveLibrary:LibraryExists", lib.Name));
    end

    % Will overwrite lib in libFile if it exists
    save(libFile, "lib", "-mat");

end
% Copyright 2023 The MathWorks, Inc.

