|
57 | 57 | subdir\file, in JS it will be subdir/file. For simplicity we treat the web platform as a *NIX. |
58 | 58 | """ |
59 | 59 |
|
| 60 | +import base64 |
60 | 61 | import os |
61 | 62 | import sys |
62 | 63 | import shutil |
|
95 | 96 | new_data_files = [] |
96 | 97 |
|
97 | 98 |
|
| 99 | +def base64_encode(b): |
| 100 | + b64 = base64.b64encode(b) |
| 101 | + return b64.decode('ascii') |
| 102 | + |
| 103 | + |
98 | 104 | def has_hidden_attribute(filepath): |
99 | 105 | """Win32 code to test whether the given file has the hidden property set.""" |
100 | 106 |
|
@@ -464,18 +470,9 @@ def was_seen(name): |
464 | 470 | basename = os.path.basename(filename) |
465 | 471 | if file_['mode'] == 'embed': |
466 | 472 | # Embed |
467 | | - data = list(bytearray(utils.read_binary(file_['srcpath']))) |
468 | | - code += '''var fileData%d = [];\n''' % counter |
469 | | - if data: |
470 | | - parts = [] |
471 | | - chunk_size = 10240 |
472 | | - start = 0 |
473 | | - while start < len(data): |
474 | | - parts.append('''fileData%d.push.apply(fileData%d, %s);\n''' |
475 | | - % (counter, counter, str(data[start:start + chunk_size]))) |
476 | | - start += chunk_size |
477 | | - code += ''.join(parts) |
478 | | - code += ('''Module['FS_createDataFile']('%s', '%s', fileData%d, true, true, false);\n''' |
| 473 | + data = base64_encode(utils.read_binary(file_['srcpath'])) |
| 474 | + code += '''var fileData%d = '%s';\n''' % (counter, data) |
| 475 | + code += ('''Module['FS_createDataFile']('%s', '%s', decodeBase64(fileData%d), true, true, false);\n''' |
479 | 476 | % (dirname, basename, counter)) |
480 | 477 | counter += 1 |
481 | 478 | elif file_['mode'] == 'preload': |
|
0 commit comments