MCPcopy Create free account
hub / github.com/cinder/Cinder / loadStreamBuffer

Function loadStreamBuffer

src/cinder/Stream.cpp:733–765  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

731}
732
733BufferRef loadStreamBuffer( IStreamRef is )
734{
735 // prevent crash if stream is not valid
736 if( ! is )
737 throw StreamExc();
738
739 off_t fileSize = is->size();
740 if( fileSize > std::numeric_limits<off_t>::max() )
741 throw StreamExcOutOfMemory();
742
743 if( fileSize ) { // sometimes fileSize will be zero for a stream that doesn't know how big it is
744 auto result = std::make_shared<Buffer>( fileSize );
745 is->readDataAvailable( result->getData(), static_cast<size_t>( fileSize ) );
746
747 return result;
748 }
749 else {
750 const size_t bufferSize = 4096;
751 size_t offset = 0;
752 auto result = std::make_shared<Buffer>( bufferSize );
753
754 while( ! is->isEof() ) {
755 if( offset + bufferSize > result->getAllocatedSize() )
756 result->resize( std::max( (size_t)( result->getAllocatedSize() * 1.5f ), offset + bufferSize ) );
757
758 size_t bytesRead = is->readDataAvailable( reinterpret_cast<uint8_t*>( result->getData() ) + offset, bufferSize );
759 offset += bytesRead;
760 result->setSize( offset );
761 }
762
763 return result;
764 }
765}
766
767#if defined( CINDER_ANDROID )
768IStreamAndroidAssetRef loadAndroidAssetStream( const fs::path &path )

Callers 1

createBufferMethod · 0.85

Calls 8

getAllocatedSizeMethod · 0.80
maxFunction · 0.50
sizeMethod · 0.45
readDataAvailableMethod · 0.45
getDataMethod · 0.45
isEofMethod · 0.45
resizeMethod · 0.45
setSizeMethod · 0.45

Tested by

no test coverage detected