diff --git a/AUTHORS b/AUTHORS index 847c7b44b27b4..ae34469f73cea 100644 --- a/AUTHORS +++ b/AUTHORS @@ -572,3 +572,4 @@ a license to everyone to use it as detailed in LICENSE.) * Camillo Lugaresi (copyright owned by Google LLC) * Chris Craig * Le Yao (copyright owned by Intel Corporation) +* José Cadete diff --git a/src/jsifier.js b/src/jsifier.js index 1d5c3175ac009..caea400382356 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -398,7 +398,7 @@ function JSify(functionsOnly) { print(preprocess(read('arrayUtils.js'))); } - if (SUPPORT_BASE64_EMBEDDING && !MINIMAL_RUNTIME) { + if ((SUPPORT_BASE64_EMBEDDING || FORCE_FILESYSTEM) && !MINIMAL_RUNTIME) { print(preprocess(read('base64Utils.js'))); } diff --git a/tools/file_packager.py b/tools/file_packager.py index bc1cdc8ca249c..b455d7e2fa907 100755 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -57,6 +57,7 @@ subdir\file, in JS it will be subdir/file. For simplicity we treat the web platform as a *NIX. """ +import base64 import os import sys import shutil @@ -95,6 +96,11 @@ new_data_files = [] +def base64_encode(b): + b64 = base64.b64encode(b) + return b64.decode('ascii') + + def has_hidden_attribute(filepath): """Win32 code to test whether the given file has the hidden property set.""" @@ -464,18 +470,9 @@ def was_seen(name): basename = os.path.basename(filename) if file_['mode'] == 'embed': # Embed - data = list(bytearray(utils.read_binary(file_['srcpath']))) - code += '''var fileData%d = [];\n''' % counter - if data: - parts = [] - chunk_size = 10240 - start = 0 - while start < len(data): - parts.append('''fileData%d.push.apply(fileData%d, %s);\n''' - % (counter, counter, str(data[start:start + chunk_size]))) - start += chunk_size - code += ''.join(parts) - code += ('''Module['FS_createDataFile']('%s', '%s', fileData%d, true, true, false);\n''' + data = base64_encode(utils.read_binary(file_['srcpath'])) + code += '''var fileData%d = '%s';\n''' % (counter, data) + code += ('''Module['FS_createDataFile']('%s', '%s', decodeBase64(fileData%d), true, true, false);\n''' % (dirname, basename, counter)) counter += 1 elif file_['mode'] == 'preload':