diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-05-21 17:55:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-21 17:55:36 +0200 |
commit | 8fa07eae145e1e37eb8708ce8c117188b58e3ecc (patch) | |
tree | 4d7e4cc526f209065baba845a0e3ab15d8e99f7c /platform/javascript/js/libs/library_godot_os.js | |
parent | 8c2beeea907cb39baac20df198392ae4fdf64029 (diff) | |
parent | fdf66a21f1a330595f7345f3b0024e0e7cafa28a (diff) |
Merge pull request #48881 from Faless/js/4.x_download_buffer
[HTML5] Add easy to use download API.
Diffstat (limited to 'platform/javascript/js/libs/library_godot_os.js')
-rw-r--r-- | platform/javascript/js/libs/library_godot_os.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/platform/javascript/js/libs/library_godot_os.js b/platform/javascript/js/libs/library_godot_os.js index 1d9f889bce..7414b8cc47 100644 --- a/platform/javascript/js/libs/library_godot_os.js +++ b/platform/javascript/js/libs/library_godot_os.js @@ -304,6 +304,23 @@ const GodotOS = { godot_js_os_hw_concurrency_get: function () { return navigator.hardwareConcurrency || 1; }, + + godot_js_os_download_buffer__sig: 'viiii', + godot_js_os_download_buffer: function (p_ptr, p_size, p_name, p_mime) { + const buf = GodotRuntime.heapSlice(HEAP8, p_ptr, p_size); + const name = GodotRuntime.parseString(p_name); + const mime = GodotRuntime.parseString(p_mime); + const blob = new Blob([buf], { type: mime }); + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = name; + a.style.display = 'none'; + document.body.appendChild(a); + a.click(); + a.remove(); + window.URL.revokeObjectURL(url); + }, }; autoAddDeps(GodotOS, '$GodotOS'); |