diff --git a/source/core/utility/basics.h b/source/core/utility/basics.h index 2f1ba5966..2c5fb6f98 100644 --- a/source/core/utility/basics.h +++ b/source/core/utility/basics.h @@ -1,13 +1,28 @@ #ifndef __BASICS_H #define __BASICS_H -#ifndef MAKE_ID -#ifndef __BIG_ENDIAN__ -#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24))) -#else -#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24))) -#endif -#endif +#include +#include + +// +// fixed point, 32bit as 16.16. +// +#define FRACBITS 16 +#define FRACUNIT (1<&& TakeBuffer() { return std::move(mBuffer); } }; -class CompressedFileWriter : public FileWriter -{ - FileWriter *target; - struct z_stream_s *zipstream; - uint8_t outbuf[1024]; - size_t compressedSize; - bool ownsWriter; - - size_t WriteBlock(const void *buffer, size_t bytes); - -public: - CompressedFileWriter(FileWriter *wr, bool transfer = false); - CompressedFileWriter(FILE *wr); - ~CompressedFileWriter() { Close(); } - virtual size_t Write(const void *buffer, size_t len) override; - virtual void Close() override; - -}; #endif diff --git a/source/core/utility/files_decompress.cpp b/source/core/utility/files_decompress.cpp index 8617f575b..c14079b63 100644 --- a/source/core/utility/files_decompress.cpp +++ b/source/core/utility/files_decompress.cpp @@ -651,116 +651,3 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b } } - - -//========================================================================== -// -// -// -//========================================================================== - -CompressedFileWriter::CompressedFileWriter(FileWriter *targ, bool transfer) -{ - target = targ; - zipstream = new z_stream; - - compressedSize = 0; - zipstream->next_in = Z_NULL; - zipstream->avail_in = 0; - zipstream->zalloc = Z_NULL; - zipstream->zfree = Z_NULL; - int err = deflateInit2 (zipstream, Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY); - if (err != Z_OK) - { - delete zipstream; - zipstream = nullptr; - return; - } - zipstream->next_out = outbuf; - zipstream->avail_out = sizeof(outbuf); - ownsWriter = transfer; -} - -//========================================================================== -// -// -// -//========================================================================== - -CompressedFileWriter::CompressedFileWriter(FILE *targ) - : CompressedFileWriter(new FileWriter(targ), true) -{ -} - -//========================================================================== -// -// -// -//========================================================================== - -size_t CompressedFileWriter::Write(const void *buffer, size_t bytes) -{ - size_t wrote = 0; - size_t towrite = bytes; - - zipstream->next_in = (Bytef *)buffer; - while (towrite > 0) - { - auto chunk = std::min(towrite, (size_t)0x40000000); - zipstream->avail_in = chunk; - buffer = ((char*)buffer) + chunk; - towrite -= chunk; - - while (zipstream->avail_in != 0) - { - if (zipstream->avail_out == 0) - { - zipstream->next_out = outbuf; - zipstream->avail_out = 1024; - wrote += 1024; - target->Write(outbuf, 1024); - } - deflate (zipstream, Z_NO_FLUSH); - } - } - compressedSize += wrote; - return bytes; -} - -//========================================================================== -// -// -// -//========================================================================== - -void CompressedFileWriter::Close() -{ - if (!zipstream) return; - // Flush the zlib stream buffer. - - for (bool done = false;;) - { - auto len = sizeof(outbuf) - zipstream->avail_out; - if (len != 0) - { - compressedSize += len; - - target->Write(outbuf, len); - zipstream->next_out = outbuf; - zipstream->avail_out = sizeof(outbuf); - } - if (done) - { - break; - } - auto err = deflate (zipstream, Z_FINISH); - done = zipstream->avail_out != 0 || err == Z_STREAM_END; - if (err != Z_STREAM_END && err != Z_OK) - { - break; - } - } - deflateEnd (zipstream); - delete zipstream; - zipstream = nullptr; -}