[solved] packing an entry with Zip::Builder stores a different file


#1

I have a file that i'm trying to pack in a zip package with the juce::ZipFile::Builder class. But the original file is different from the one it is stored in the zip archive (don't know why): if i read it back with juce::ZipFile (or extract it with a third party archiver application) and compare the bytes, i get different bytes only at the start of the files... don't know where to look !

Original file in a memory block i pack with zero compression with:

    ZipFile::Builder pack;

    pack.addEntry(new MemoryInputStream(memoryBlock, false), 0, "testfile.bin", now);

    pack.writeToStream(os, nullptr);

0000000 285e f49b d40f 6401 2cc7 8132 a588 42d9
0000010 4c1f e1d2 9785 16c2 d84e b750 587e 3cdd
0000020 5cce 289d 9d10 0e50 3f57 16a6 a827 22d6
0000030 309a 5c81 7c95 c3db 1642 e3ba 31af 71ba
0000040 18de 34e3 3cd9 535e 6395 d57b 57e8 701e
0000050 9b41 69e6 40c5 c232 fb86 cfb7 d6c4 29eb
...

This is the unpacked file (with juce or an external archiver):

    ZipFile pack(is, false);

    pack.createStreamForEntry(pack.getIndexOfFileName("testfile.bin")->readIntoMemoryBlock(memoryBlock);

0000000 285e f49b 0000 2200 0010 0010 0700 006a
0000010 940e c40a f040 0200 ff1b 6648 0eb2 d3de
0000020 37b9 6f13 d91f 775c 6689 16a6 a827 22d6
0000030 309a 5c81 7c95 c3db 1642 e3ba 31af 71ba
0000040 18de 34e3 3cd9 535e 6395 d57b 57e8 701e
0000050 9b41 69e6 40c5 c232 fb86 cfb7 d6c4 29eb
...

The rest of the file is equal.

I never experienced something like this... any ideas ?

 


#2

Does it only happen with a specific file? If it happened to all files then I'd have thought everyone else would have complained loudly by now!

Are you sure you're closing/flushing/deleting your objects properly? That's normally the cause when files seem to be written incorrectly.


#3

don't mind. seems i have found that doing a memory input stream keeping a copy of the data from the memory block make it work.

sorry for the fuss !