Skip to content

Fix for --preload-file + --embed-file #17457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,11 +1554,13 @@ def test_export_from_archive(self):

@parameterized({
'embed': (['--embed-file', 'somefile.txt'],),
'embed-twice': (['--embed-file', 'somefile.txt', '--embed-file', 'somefile.txt'],),
'preload': (['--preload-file', 'somefile.txt'],)
'embed_twice': (['--embed-file', 'somefile.txt', '--embed-file', 'somefile.txt'],),
'preload': (['--preload-file', 'somefile.txt'],),
'preload_and_embed': (['--preload-file', 'somefile.txt', '--embed-file', 'hello.txt'],)
})
def test_include_file(self, args):
create_file('somefile.txt', 'hello from a file with lots of data and stuff in it thank you very much')
create_file('hello.txt', 'hello world')
create_file('main.c', r'''
#include <assert.h>
#include <stdio.h>
Expand Down
13 changes: 7 additions & 6 deletions tools/file_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,13 @@ def generate_js(data_target, data_files, metadata):
dirname = os.path.dirname(filename)
basename = os.path.basename(filename)
if file_.mode == 'embed':
# Embed
data = base64_encode(utils.read_binary(file_.srcpath))
code += " var fileData%d = '%s';\n" % (counter, data)
# canOwn this data in the filesystem (i.e. there is no need to create a copy in the FS layer).
code += (" Module['FS_createDataFile']('%s', '%s', decodeBase64(fileData%d), true, true, true);\n"
% (dirname, basename, counter))
if not options.obj_output:
# Embed (only needed when not generating object file output)
data = base64_encode(utils.read_binary(file_.srcpath))
code += " var fileData%d = '%s';\n" % (counter, data)
# canOwn this data in the filesystem (i.e. there is no need to create a copy in the FS layer).
code += (" Module['FS_createDataFile']('%s', '%s', decodeBase64(fileData%d), true, true, true);\n"
% (dirname, basename, counter))
elif file_.mode == 'preload':
# Preload
metadata_el = {
Expand Down