ZipFile is really slow


#1

ZipFile is really slow, especially when ready from cd/dvd since it does so much seeking back and forth

This makes it much better:

39a40
> #include "../io/streams/juce_MemoryInputStream.h"
65a67,76
> 		char buffer[30];
> 
> 		file.source->setPosition(zei.streamOffset);
> 		if (file.source->read (buffer, 30) == 30
> 			&& littleEndianInt (buffer) == 0x04034b50)
> 		{
> 			headerSize = 30
> 				+ littleEndianShort (buffer + 26)
> 				+ littleEndianShort (buffer + 28);
> 		}
83c94
<         file.source->setPosition (pos + zipEntryInfo.streamOffset);
---
>         file.source->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
111a123
> 	int headerSize;
218c230,237
<         int pos = findEndOfZipEntryTable();
---
>         int pos  = findEndOfZipEntryTable();
> 		int size = int(source->getTotalLength() - pos);
> 
> 		MemoryBlock mb(0);
> 		source->setPosition(pos);
> 		source->readIntoMemoryBlock(mb, size);
> 
> 		MemoryInputStream memSource(mb.getData(), mb.getSize(), false);
219a239
> 		pos = 0;
222c242
<             source->setPosition (pos);
---
>             memSource.setPosition (pos);
225c245
<             if (source->read (buffer, 46) != 46)
---
>             if (memSource.read (buffer, 46) != 46)
230c250
<             if (source->read (buffer + 46, fileNameLen) == fileNameLen)
---
>             if (memSource.read (buffer + 46, fileNameLen) == fileNameLen)
258,273c278,279
<                 source->setPosition (localHeaderOffset);
< 
<                 if (source->read (buffer, 30) == 30
<                      && littleEndianInt (buffer) == 0x04034b50)
<                 {
<                     zei->streamOffset = localHeaderOffset
<                                          + 30
<                                          + littleEndianShort (buffer + 26)
<                                          + littleEndianShort (buffer + 28);
< 
<                     entries.add (zei);
<                 }
<                 else
<                 {
<                     delete zei;
<                 }
---
> 				zei->streamOffset = localHeaderOffset;
>                 entries.add (zei);

#2

Have you tried just passing it a BufferedInputStream instead of a raw FileInputStream, though? I’d have though that’d probably be just as effective.


#3

Yes, I tried that, but if the zip file is bigger than the buffer, the buffer is always getting cleared.

As you wrote it, in Init(), for each file in the zip file, it seeks to the end of the zip file, and then it seeks to the file in the zip file. Two seeks for each file in the zip.


#4

Ok, fair point.


#5