ataylor Posted June 20, 2016 Posted June 20, 2016 I am trying to use a Blob to compress an existing file on disk: Unigine::FilePtr fileIn = Unigine::File::create("someFile", "rb"); Unigine::FilePtr fileOut = Unigine::File::create("someOtherFile", "wb"); Unigine::BlobPtr blob=Unigine::Blob::create(fileIn->getStream()); blob->compress(fileOut->getStream(), 1); But engine crashes inside Blob::compress function. I see that there is another Blob constructor -- Blob::create(size_t size=0). If I use this function to create the Blob, there is no crash. fileOut is written successfully but of course has almost no content as the blob is empty. I assume I would need to manually read in the bytes of fileIn and write them to blob. This is OK, but if there is a way to have this done automatically I would prefer that. Documentation for Blob class only shows a single create() function, and it seems wrong: Ptr<Blob> create (const Ptr<Stream> & stream)Blob constructor. Arguments const Ptr<Stream> & stream - Size of the blob in bytes. Is there a working example of initializing a Blob from a Stream?
ded Posted June 21, 2016 Posted June 21, 2016 Hi, I'm afraid there is flaw in the API. Ptr<Blob> create (const Ptr<Stream> & stream); Really should be declared as: Ptr<Blob> create (const Ptr<Blob> & stream) It's a copy constructor for a Blob. Blob has no functionality to read all data from the another stream. You'll have to read the file contents yourself, for example like this: while (!fileIn->eof()) fileIn->readStream(blob->getStream(), BUF_SIZE); We'll fix the constructor signature, thank you for noticing the issue and sorry for the inconvenience caused.
Recommended Posts