Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/fileops.c')
-rw-r--r--source/blender/blenlib/intern/fileops.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 3299752646b..6b125435b31 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -52,6 +52,8 @@
#include <sys/param.h>
#endif
+#include "MEM_guardedalloc.h"
+
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
@@ -104,6 +106,45 @@ int BLI_gzip(const char *from, const char *to) {
return rval;
}
+/* gzip the file in from_file and write it to memery to_mem, at most size bytes.
+ return the unziped size
+ */
+char *BLI_ungzip_to_mem(const char *from_file, int *size_r)
+{
+ gzFile gzfile;
+ int readsize, size, alloc_size=0;
+ char *mem= NULL;
+ const int chunk_size= 512*1024;
+
+ size= 0;
+
+ gzfile = gzopen( from_file, "rb" );
+
+ for(;;) {
+ if(mem==NULL) {
+ mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem");
+ alloc_size= chunk_size;
+ } else {
+ mem= MEM_reallocN(mem, size+chunk_size);
+ alloc_size+= chunk_size;
+ }
+
+ readsize= gzread(gzfile, mem+size, chunk_size);
+ if(readsize>0) {
+ size+= readsize;
+ }
+ else break;
+ }
+
+ if(mem && alloc_size!=size)
+ mem= MEM_reallocN(mem, size);
+
+ *size_r= size;
+
+ return mem;
+}
+
+
/* return 1 when file can be written */
int BLI_is_writable(const char *filename)
{