Fixed recompressing after modification
This commit is contained in:
parent
67751d9a3e
commit
8e0b135eb3
@ -171,7 +171,7 @@ class BlendFile:
|
|||||||
log.debug("recompressing modified blend file %s", self.raw_filepath)
|
log.debug("recompressing modified blend file %s", self.raw_filepath)
|
||||||
self.fileobj.seek(os.SEEK_SET, 0)
|
self.fileobj.seek(os.SEEK_SET, 0)
|
||||||
|
|
||||||
with gzip.open(self.filepath, 'wb') as gzfile:
|
with gzip.open(str(self.filepath), 'wb') as gzfile:
|
||||||
while True:
|
while True:
|
||||||
data = self.fileobj.read(FILE_BUFFER_SIZE)
|
data = self.fileobj.read(FILE_BUFFER_SIZE)
|
||||||
if not data:
|
if not data:
|
||||||
|
|||||||
BIN
tests/blendfiles/linked_cube_compressed.blend
Normal file
BIN
tests/blendfiles/linked_cube_compressed.blend
Normal file
Binary file not shown.
@ -32,3 +32,33 @@ class ModifyUncompressedTest(AbstractBlendFileTest):
|
|||||||
library = self.bf.code_index[b'LI'][0]
|
library = self.bf.code_index[b'LI'][0]
|
||||||
self.assertEqual(b'//basic_file.blend', library[b'filepath'])
|
self.assertEqual(b'//basic_file.blend', library[b'filepath'])
|
||||||
self.assertEqual(b'//basic_file.blend', library[b'name'])
|
self.assertEqual(b'//basic_file.blend', library[b'name'])
|
||||||
|
|
||||||
|
|
||||||
|
class ModifyCompressedTest(AbstractBlendFileTest):
|
||||||
|
def setUp(self):
|
||||||
|
self.orig = self.blendfiles / 'linked_cube_compressed.blend'
|
||||||
|
self.to_modify = self.orig.with_name('linked_cube_modified.blend')
|
||||||
|
|
||||||
|
copyfile(str(self.orig), str(self.to_modify)) # TODO: when requiring Python 3.6+, remove str()
|
||||||
|
self.bf = blendfile.BlendFile(self.to_modify, mode='r+b')
|
||||||
|
|
||||||
|
self.assertTrue(self.bf.is_compressed)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
if self.to_modify.exists():
|
||||||
|
self.to_modify.unlink()
|
||||||
|
|
||||||
|
def test_change_path(self):
|
||||||
|
library = self.bf.code_index[b'LI'][0]
|
||||||
|
|
||||||
|
# Change it from absolute to relative.
|
||||||
|
library[b'filepath'] = b'//basic_file.blend'
|
||||||
|
library[b'name'] = b'//basic_file.blend'
|
||||||
|
|
||||||
|
# Reload the blend file to inspect that it was written properly.
|
||||||
|
self.bf.close()
|
||||||
|
self.bf = blendfile.BlendFile(self.to_modify, mode='r+b')
|
||||||
|
|
||||||
|
library = self.bf.code_index[b'LI'][0]
|
||||||
|
self.assertEqual(b'//basic_file.blend', library[b'filepath'])
|
||||||
|
self.assertEqual(b'//basic_file.blend', library[b'name'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user