summaryrefslogtreecommitdiff
path: root/core/bind
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2017-06-19 13:28:00 -0300
committerGeorge Marques <george@gmarqu.es>2017-06-19 16:38:37 -0300
commit5c779c574a472d5c70316d7bbdef04e21f00b9be (patch)
treeab2e9dcb3a754e2304099d15f14f764c78bed21c /core/bind
parentaf7d5902062546e961a24e133c09f8ea49ae42db (diff)
Add compression support for File object
Diffstat (limited to 'core/bind')
-rw-r--r--core/bind/core_bind.cpp24
-rw-r--r--core/bind/core_bind.h8
2 files changed, 32 insertions, 0 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index d81ccf0265..095f058ed9 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -31,6 +31,7 @@
#include "core/global_config.h"
#include "geometry.h"
+#include "io/file_access_compressed.h"
#include "io/file_access_encrypted.h"
#include "io/marshalls.h"
#include "os/keyboard.h"
@@ -1395,6 +1396,24 @@ Error _File::open_encrypted_pass(const String &p_path, int p_mode_flags, const S
return OK;
}
+Error _File::open_compressed(const String &p_path, int p_mode_flags, int p_compress_mode) {
+
+ FileAccessCompressed *fac = memnew(FileAccessCompressed);
+ Error err = OK;
+
+ fac->configure("GCPF", (Compression::Mode)p_compress_mode);
+
+ err = fac->_open(p_path, p_mode_flags);
+
+ if (err) {
+ memdelete(fac);
+ return err;
+ }
+
+ f = fac;
+ return OK;
+}
+
Error _File::open(const String &p_path, int p_mode_flags) {
close();
@@ -1700,6 +1719,7 @@ void _File::_bind_methods() {
ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted);
ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass);
+ ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0));
ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open);
ClassDB::bind_method(D_METHOD("close"), &_File::close);
@@ -1749,6 +1769,10 @@ void _File::_bind_methods() {
BIND_CONSTANT(WRITE);
BIND_CONSTANT(READ_WRITE);
BIND_CONSTANT(WRITE_READ);
+
+ BIND_CONSTANT(COMPRESSION_FASTLZ);
+ BIND_CONSTANT(COMPRESSION_DEFLATE);
+ BIND_CONSTANT(COMPRESSION_ZSTD);
}
_File::_File() {
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index a2fb6c966c..87d84c0732 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -31,6 +31,7 @@
#define CORE_BIND_H
#include "image.h"
+#include "io/compression.h"
#include "io/resource_loader.h"
#include "io/resource_saver.h"
#include "os/dir_access.h"
@@ -366,8 +367,15 @@ public:
WRITE_READ = 7,
};
+ enum CompressionMode {
+ COMPRESSION_FASTLZ = Compression::MODE_FASTLZ,
+ COMPRESSION_DEFLATE = Compression::MODE_DEFLATE,
+ COMPRESSION_ZSTD = Compression::MODE_ZSTD
+ };
+
Error open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key);
Error open_encrypted_pass(const String &p_path, int p_mode_flags, const String &p_pass);
+ Error open_compressed(const String &p_path, int p_mode_flags, int p_compress_mode = 0);
Error open(const String &p_path, int p_mode_flags); ///< open a file
void close(); ///< close a file