Permalink
Browse files

Fix issue #862: Do not compress data in memory but directly to file.

All basic and library tests which passed before are still passing.
  • Loading branch information...
1 parent a77b871 commit 86207fec1aed6a0c2272c693d2d6c7a1bbf5c045 @htgoebel htgoebel committed Feb 24, 2014
Showing with 35 additions and 10 deletions.
  1. +35 −10 PyInstaller/loader/pyi_carchive.py
@@ -16,6 +16,7 @@
import struct
import sys
import zlib
+import os
import pyi_archive
@@ -317,31 +318,55 @@ def add(self, entry):
# Version 5 - allow type 'o' = runtime option.
try:
if typcd in ('o', 'd'):
- s = ''
+ fh = None
+ ulen = 0
+ postfix = ''
flag = 0
elif typcd == 's':
# If it's a source code file, add \0 terminator as it will be
# executed as-is by the bootloader.
- s = open(pathnm, 'rU').read()
- s = s + '\n\0'
+ fh = open(pathnm, 'rU')
+ postfix = '\n\0'
+ ulen = os.fstat(fh.fileno()).st_size + len(postfix)
else:
- s = open(pathnm, 'rb').read()
+ fh = open(pathnm, 'rb')
+ postfix = ''
+ ulen = os.fstat(fh.fileno()).st_size
except IOError:
print "Cannot find ('%s', '%s', %s, '%s')" % (nm, pathnm, flag, typcd)
raise
- ulen = len(s)
- assert flag in range(3)
- if flag == 1:
- s = zlib.compress(s, self.LEVEL)
- dlen = len(s)
where = self.lib.tell()
+ assert flag in range(3)
+ if not fh:
+ # no need to write anything
+ pass
+ elif flag == 1:
+ assert fh
+ comprobj = zlib.compressobj(self.LEVEL)
+ while 1:
+ buf = fh.read(16*1024)
+ if not buf:
+ break
+ self.lib.write(comprobj.compress(buf))
+ self.lib.write(comprobj.compress(postfix))
+ self.lib.write(comprobj.flush())
+ else:
+ assert fh
+ while 1:
+ buf = fh.read(16*1024)
+ if not buf:
+ break
+ self.lib.write(buf)
+ self.lib.write(postfix)
+
+ dlen = self.lib.tell() - where
if typcd == 'm':
if pathnm.find('.__init__.py') > -1:
typcd = 'M'
self.toc.add(where, dlen, ulen, flag, typcd, nm)
- self.lib.write(s)
+
def save_toc(self, tocpos):
"""

0 comments on commit 86207fe

Please sign in to comment.