MCPcopy Create free account
hub / github.com/ZDoom/Raze / GetCompressedOutput

Method GetCompressedOutput

source/common/engine/serializer.cpp:788–841  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

786//==========================================================================
787
788FCompressedBuffer FSerializer::GetCompressedOutput()
789{
790 if (isReading()) return{ 0,0,0,0,0,nullptr };
791 FCompressedBuffer buff;
792 WriteObjects();
793 EndObject();
794 buff.filename = nullptr;
795 buff.mSize = (unsigned)w->mOutString.GetSize();
796 buff.mCRC32 = crc32(0, (const Bytef*)w->mOutString.GetString(), buff.mSize);
797
798 uint8_t *compressbuf = new uint8_t[buff.mSize+1];
799
800 z_stream stream;
801 int err;
802
803 stream.next_in = (Bytef *)w->mOutString.GetString();
804 stream.avail_in = (unsigned)buff.mSize;
805 stream.next_out = (Bytef*)compressbuf;
806 stream.avail_out = (unsigned)buff.mSize;
807 stream.zalloc = (alloc_func)0;
808 stream.zfree = (free_func)0;
809 stream.opaque = (voidpf)0;
810
811 // create output in zip-compatible form as required by FCompressedBuffer
812 err = deflateInit2(&stream, 8, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY);
813 if (err != Z_OK)
814 {
815 goto error;
816 }
817
818 err = deflate(&stream, Z_FINISH);
819 if (err != Z_STREAM_END)
820 {
821 deflateEnd(&stream);
822 goto error;
823 }
824 buff.mCompressedSize = stream.total_out;
825
826 err = deflateEnd(&stream);
827 if (err == Z_OK)
828 {
829 buff.mBuffer = new char[buff.mCompressedSize];
830 buff.mMethod = METHOD_DEFLATE;
831 memcpy(buff.mBuffer, compressbuf, buff.mCompressedSize);
832 delete[] compressbuf;
833 return buff;
834 }
835
836error:
837 memcpy(compressbuf, w->mOutString.GetString(), buff.mSize + 1);
838 buff.mCompressedSize = buff.mSize;
839 buff.mMethod = METHOD_STORED;
840 return buff;
841}
842
843//==========================================================================
844//

Callers 1

WriteSavegameFunction · 0.80

Calls 2

GetSizeMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected