MCPcopy Create free account
hub / github.com/ImageEngine/cortex / openStream

Method openStream

src/IECore/StreamIndexedIO.cpp:1654–1746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1652}
1653
1654void StreamIndexedIO::Index::openStream()
1655{
1656 if ( m_stream->openMode() & (IndexedIO::Append|IndexedIO::Read) )
1657 {
1658 StreamIndexedIO::StreamFile &f = *m_stream;
1659
1660 m_hasChanged = false;
1661
1662 f.seekg( 0, std::ios::end );
1663 uint64_t fileLen;
1664 uint64_t end = fileLen = f.tellg();
1665 f.seekg( end-1*sizeof(uint64_t), std::ios::beg );
1666
1667 uint64_t magicNumber = 0;
1668 readLittleEndian( f, magicNumber );
1669
1670 if ( magicNumber == g_versionedMagicNumber )
1671 {
1672 end -= 3*sizeof(uint64_t);
1673 f.seekg( end, std::ios::beg );
1674 readLittleEndian( f, m_offset );
1675 readLittleEndian( f, m_version );
1676 }
1677 else if (magicNumber == g_unversionedMagicNumber )
1678 {
1679 m_version = 0;
1680 end -= 2*sizeof(uint64_t);
1681 f.seekg( end, std::ios::beg );
1682 readLittleEndian( f, m_offset );
1683 }
1684 else
1685 {
1686 throw IOException("Not a StreamIndexedIO file");
1687 }
1688
1689 if (m_version >= 6)
1690 {
1691 end -= 2 * sizeof(int);
1692 f.seekg( end, std::ios::beg );
1693
1694 int compressorCode;
1695 readLittleEndian( f, compressorCode );
1696 readLittleEndian( f, m_compressionLevel );
1697 m_compressor = getCompressor( compressorCode );
1698 }
1699
1700 f.seekg( m_offset, std::ios::beg );
1701
1702 if (m_version >= 2 )
1703 {
1704 // construct a memory stream source from the decompressed index data
1705 io::filtering_istream indexInStream;
1706
1707 if( m_version >= 7 )
1708 {
1709 // read the compressed Index
1710 uint64_t indexCompressedSize = end - m_offset;
1711 std::vector<char> compressedIndex( indexCompressedSize );

Callers 1

openMethod · 0.80

Calls 11

readLittleEndianFunction · 0.85
IOExceptionFunction · 0.85
getCompressorFunction · 0.85
decompressFunction · 0.85
readFunction · 0.85
seekgMethod · 0.80
tellgMethod · 0.80
pushMethod · 0.80
openModeMethod · 0.45
readMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected