diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-10 15:35:09 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-10 15:35:51 +0300 |
commit | fbc12e6cc5ea72215ade0ac3405c50ca7c89e29c (patch) | |
tree | a539a6bc166e7e4ae5207b697459d5e1bdcf8f27 /source/blender/blenkernel/intern/packedFile.c | |
parent | 4a82d792b03b61baed6d70bed288291c72f1e3b8 (diff) |
Cleanup: extract functions for PackedFile .blend I/O
Diffstat (limited to 'source/blender/blenkernel/intern/packedFile.c')
-rw-r--r-- | source/blender/blenkernel/intern/packedFile.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 6793f5e1169..ac3686a021b 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -51,6 +51,8 @@ #include "BKE_sound.h" #include "BKE_volume.h" +#include "BLO_read_write.h" + int BKE_packedfile_seek(PackedFile *pf, int offset, int whence) { int oldseek = -1, seek = 0; @@ -852,3 +854,29 @@ void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, enum ePF break; } } + +void BKE_packedfile_blend_write(BlendWriter *writer, PackedFile *pf) +{ + if (pf == NULL) { + return; + } + BLO_write_struct(writer, PackedFile, pf); + BLO_write_raw(writer, pf->size, pf->data); +} + +void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p) +{ + BLO_read_packed_address(reader, pf_p); + PackedFile *pf = *pf_p; + if (pf == NULL) { + return; + } + + BLO_read_packed_address(reader, &pf->data); + if (pf->data == NULL) { + /* We cannot allow a PackedFile with a NULL data field, + * the whole code assumes this is not possible. See T70315. */ + printf("%s: NULL packedfile data, cleaning up...\n", __func__); + MEM_SAFE_FREE(pf); + } +} |