# ZipFile is really slow

**URL:** <https://forum.juce.com/t/zipfile-is-really-slow/1350>\
**Category:** General JUCE discussion\
**Created:** [January 9, 2007, 11:47pm UTC](https://forum.juce.com/t/zipfile-is-really-slow/1350 "2007-01-09T23:47:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [January 9, 2007, 11:47pm UTC](https://forum.juce.com/t/zipfile-is-really-slow/1350/1 "2007-01-09T23:47:14Z")

</div>

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

This makes it much better:

```auto
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);
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 10, 2007, 11:46am UTC](https://forum.juce.com/t/zipfile-is-really-slow/1350/2 "2007-01-10T11:46:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [January 10, 2007, 6:49pm UTC](https://forum.juce.com/t/zipfile-is-really-slow/1350/3 "2007-01-10T18:49:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 11, 2007, 11:44am UTC](https://forum.juce.com/t/zipfile-is-really-slow/1350/4 "2007-01-11T11:44:15Z")

</div>

Ok, fair point.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 8:58pm UTC](https://forum.juce.com/t/zipfile-is-really-slow/1350/5 "2017-05-12T20:58:26Z")

</div>

Closed on May 12, 2017, 8:58pm UTC


