Mercurial > hg > forks > multipaint-js
changeset 103:7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Jul 2018 05:28:15 +0300 |
parents | 287892b5eff8 |
children | 73a8773466ae |
files | multipaint.pde |
diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/multipaint.pde Fri Jul 06 05:27:49 2018 +0300 +++ b/multipaint.pde Fri Jul 06 05:28:15 2018 +0300 @@ -300,19 +300,29 @@ } +Blob mpMakeBinaryBlob(byte[] data) +{ + var blob = null; + if (data == null) + return null; + + if (typeof(data) == "string") + blob = new Blob([data], {type: "application/octet-stream"}); + else + if (typeof(data) == "object") + blob = new Blob([new Uint8Array(data)], {type: "application/octet-stream"}); + + return blob; +} + + // // "Save" a byte array to file. Basically creates a blob URI // and dumps it in the DOM, giving user a download. // bool mpSaveBinaryFile(String name, byte[] data) { - var blob = null; - if (typeof(data) == "string") - blob = new Blob([data], {type: "application/octet-stream"}); - else - if (typeof(data) == "object") - blob = new Blob([new Uint8Array(data)], {type: "application/octet-stream"}); - + var blob = mpMakeBinaryBlob(data); if (blob == null) { console.log("Could not create BLOB from data.");