Function detectFormatFromExt

Synopsis

#include <src/bitinputarchive.cpp>

const BitInFormat & detectFormatFromExt(const wstring &in_file)

Description

No description yet.

Source

Lines 490-514 in src/bitformat.cpp. Line 40 in src/bitinputarchive.cpp.

const BitInFormat& detectFormatFromExt( const wstring& in_file ) {
    wstring ext = filesystem::fsutil::extension( in_file );
    if ( ext.empty() ) {
        throw BitException( "Cannot detect the archive format from the extension" );
    }
    std::transform( ext.cbegin(), ext.cend(), ext.begin(), std::towlower );
    // Detecting archives with common file extensions
    auto it = common_extensions.find( ext );
    if ( it != common_extensions.end() ) { //extension found in map
        return it->second;
    }
    // Detecting multivolume archives extension
    if ( ( ext[ 0 ] == L'r' || ext[ 0 ] == L'z' ) &&
            ( ext.size() == 3 && iswdigit( ext[ 1 ] ) != 0 && iswdigit( ext[ 2 ] ) != 0 ) ) {
        // Extension follows the format zXX or rXX, where X is a number in range [0-9]
        return ext[ 0 ] == L'r' ? Rar : Zip;
    }
    // Note: iso, img and ima extensions can be associated with different formats -> detect by signature
    // The extension did not match any known format extension, delegating the decision to the client
    return Auto;
}





Add Discussion as Guest

Log in