Skip to content

Commit 8024889

Browse files
committed
optimize --embed-file
1 parent daa1662 commit 8024889

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/file_packager.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,13 @@ def was_seen(name):
416416
data = map(ord, open(file_['srcpath'], 'rb').read())
417417
code += '''fileData%d = [];\n''' % counter
418418
if data:
419+
parts = []
419420
chunk_size = 10240
420-
while len(data) > 0:
421-
code += '''fileData%d.push.apply(fileData%d, %s);\n''' % (counter, counter, str(data[:chunk_size]))
422-
data = data[chunk_size:]
421+
start = 0
422+
while start < len(data):
423+
parts.append('''fileData%d.push.apply(fileData%d, %s);\n''' % (counter, counter, str(data[start:start+chunk_size])))
424+
start += chunk_size
425+
code += ''.join(parts)
423426
code += '''Module['FS_createDataFile']('%s', '%s', fileData%d, true, true);\n''' % (dirname, basename, counter)
424427
counter += 1
425428
elif file_['mode'] == 'preload':

0 commit comments

Comments
 (0)