mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #48651 from tavurth/3.x
Port HTTPRequest gzip compression to 3.4
This commit is contained in:
commit
c7f27f1d9d
7 changed files with 279 additions and 12 deletions
|
@ -645,6 +645,24 @@ struct _VariantCall {
|
|||
r_ret = decompressed;
|
||||
}
|
||||
|
||||
static void _call_PoolByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||
PoolByteArray *decompressed = memnew(PoolByteArray);
|
||||
int max_output_size = (int)(*p_args[0]);
|
||||
Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]);
|
||||
|
||||
decompressed->resize(1024);
|
||||
int result = Compression::decompress_dynamic(decompressed, max_output_size, ba->read().ptr(), ba->size(), mode);
|
||||
|
||||
if (result == OK) {
|
||||
r_ret = decompressed;
|
||||
} else {
|
||||
decompressed->resize(0);
|
||||
r_ret = decompressed;
|
||||
ERR_FAIL_MSG("Decompression failed.");
|
||||
}
|
||||
}
|
||||
|
||||
static void _call_PoolByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||
if (ba->size() == 0) {
|
||||
|
@ -1896,6 +1914,7 @@ void register_variant_methods() {
|
|||
ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, hex_encode, varray());
|
||||
ADDFUNC1R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, compress, INT, "compression_mode", varray(0));
|
||||
ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0));
|
||||
ADDFUNC2R(POOL_BYTE_ARRAY, POOL_BYTE_ARRAY, PoolByteArray, decompress_dynamic, INT, "max_output_size", INT, "compression_mode", varray(0));
|
||||
|
||||
ADDFUNC0R(POOL_INT_ARRAY, INT, PoolIntArray, size, varray());
|
||||
ADDFUNC0R(POOL_INT_ARRAY, BOOL, PoolIntArray, empty, varray());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue