From 30830e843165e5e72e3167dc4b2db61a67653b9a Mon Sep 17 00:00:00 2001 From: kovacsv Date: Thu, 16 Sep 2021 07:45:11 +0200 Subject: [PATCH] Handle multiple zip files. --- source/import/importer.js | 3 ++- .../zip/cube_with_materials_notexture.zip | Bin 0 -> 625 bytes test/tests/importer_test.js | 21 +++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/testfiles/zip/cube_with_materials_notexture.zip diff --git a/source/import/importer.js b/source/import/importer.js index 0db9051..128f753 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -225,7 +225,8 @@ OV.Importer = class } OV.LoadExternalLibrary ('loaders/fflate.min.js').then (() => { for (let i = 0; i < archives.length; i++) { - const archiveBuffer = new Uint8Array (archives[0].content); + const archiveFile = archives[i]; + const archiveBuffer = new Uint8Array (archiveFile.content); const decompressed = fflate.unzipSync (archiveBuffer); for (const fileName in decompressed) { if (Object.prototype.hasOwnProperty.call (decompressed, fileName)) { diff --git a/test/testfiles/zip/cube_with_materials_notexture.zip b/test/testfiles/zip/cube_with_materials_notexture.zip new file mode 100644 index 0000000000000000000000000000000000000000..f1a1ee2daefe78f50dbe3a633792a908ee0906fd GIT binary patch literal 625 zcmWIWW@Zs#U|`^22x&YOWbS)kqY%h5XJTLw2hz!)2pbO!~0 z?%2$u*OjLIahm1RDa$5hh|fuMTon6Ia;BH_oJuwUcD6UMeOLY4Nbe%08SLP>WrB1NUKWxC$QqK5`pT)}B`cVhZm~MP zY-Rr!#`5`h{#F*4ZxH%8ck#>j?WcS#YdlZwo#Hv|`=|Y;=T8}FpU#<= zq5K|BEO^5x$E literal 0 HcmV?d00001 diff --git a/test/tests/importer_test.js b/test/tests/importer_test.js index 7769225..ccf224e 100644 --- a/test/tests/importer_test.js +++ b/test/tests/importer_test.js @@ -302,5 +302,24 @@ describe ('Importer Test', function () { assert.fail (); } }); - }); + }); + + it ('Multiple Zip Files', function (done) { + let files = [ + new FileObject ('zip', 'cube_with_materials_notexture.zip'), + new FileObject ('zip', 'textures.zip') + ]; + ImportFiles (files, { + success : function (importer, importResult) { + assert (!OV.IsModelEmpty (importResult.model)); + console.log (importResult.usedFiles); + assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); + assert.deepStrictEqual (importResult.missingFiles, []); + done (); + }, + error : function (importer, importError) { + assert.fail (); + } + }); + }); });