Compression infer_compression()

in src/mlio/data_stores/detail/util.cc [24:46]


Compression infer_compression(std::string_view path) noexcept
{
    std::size_t len = path.size();

    if (len > 3 && path[len - 3] == '.') {
        if (path[len - 2] == 'g' && path[len - 1] == 'z') {
            return Compression::gzip;
        }
        return Compression::none;
    }

    if (len > 4 && path[len - 4] == '.') {
        if (path[len - 3] == 'b' && path[len - 2] == 'z' && path[len - 1] == '2') {
            return Compression::bzip2;
        }

        if (path[len - 3] == 'z' && path[len - 2] == 'i' && path[len - 1] == 'p') {
            return Compression::zip;
        }
    }

    return Compression::none;
}