| 1556 | /////////////////////////////////////////////// |
| 1557 | |
| 1558 | StreamIndexedIO::Index::Index( StreamIndexedIO::StreamFilePtr stream, const CompoundData *options ) |
| 1559 | : m_root( nullptr ), |
| 1560 | m_version( g_currentVersion ), |
| 1561 | m_hasChanged( false ), |
| 1562 | m_offset( 0 ), |
| 1563 | m_next( 0 ), |
| 1564 | m_stream( stream ), m_compressionLevel( 0 ), |
| 1565 | m_compressionThreadCount(1), |
| 1566 | m_decompressionThreadCount(1), m_compressor( "lz4" ) |
| 1567 | |
| 1568 | { |
| 1569 | m_stringCache.add(IndexedIO::rootName); |
| 1570 | |
| 1571 | const char *compressionLevelEnvVar = getenv( "IECORE_STREAMINDEXEDIO_COMPRESSION" ); |
| 1572 | if ( compressionLevelEnvVar ) |
| 1573 | { |
| 1574 | char buffer[1024]; |
| 1575 | if ( sscanf( compressionLevelEnvVar, "%s %i %i %i", &buffer[0], &m_compressionLevel, &m_compressionThreadCount, &m_decompressionThreadCount ) == 4 ) |
| 1576 | { |
| 1577 | m_compressor = std::string( buffer ); |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | if ( options ) |
| 1582 | { |
| 1583 | if ( const StringData* compressor = options->member<StringData>("compressor", false) ) |
| 1584 | { |
| 1585 | m_compressor = compressor->readable(); |
| 1586 | } |
| 1587 | |
| 1588 | if ( const IntData* compressionLevel = options->member<IntData>("compressionLevel", false) ) |
| 1589 | { |
| 1590 | m_compressionLevel = compressionLevel->readable(); |
| 1591 | } |
| 1592 | |
| 1593 | if ( const IntData* compressionThreadCount = options->member<IntData>("compressionThreadCount", false) ) |
| 1594 | { |
| 1595 | m_compressionThreadCount = compressionThreadCount->readable(); |
| 1596 | } |
| 1597 | |
| 1598 | if ( const IntData* decompressionThreadCount = options->member<IntData>("decompressionThreadCount", false) ) |
| 1599 | { |
| 1600 | m_decompressionThreadCount = decompressionThreadCount->readable(); |
| 1601 | } |
| 1602 | |
| 1603 | if ( const UIntData* maxCompressedBlockSize = options->member<UIntData>("maxCompressedBlockSize", false) ) |
| 1604 | { |
| 1605 | m_maxCompressedBlockSize = maxCompressedBlockSize->readable(); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | // validate our parameters |
| 1610 | m_compressionLevel = std::min( std::max( 0, m_compressionLevel ), 9 ); // todo replace with std::clamp in C++17 |
| 1611 | m_compressionThreadCount = std::min( std::max( 1, m_compressionThreadCount ), 32 ); |
| 1612 | m_decompressionThreadCount = std::min( std::max( 1, m_decompressionThreadCount ), 32 ); |
| 1613 | |
| 1614 | if ( getCompressionCode( m_compressor ) == -1) |
| 1615 | { |
nothing calls this directly
no test coverage detected