comparison files.pde @ 200:dffdbdb4ded6

Split mpSaveBinaryFile() into mpSaveBinaryBlob() for saving JavaScript Blobs, which is what mpSaveBinaryFile() converts given byte array into.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 29 Aug 2018 14:06:55 +0300
parents b36cfb497223
children c6c1dd769566
comparison
equal deleted inserted replaced
199:475a6ab70cd1 200:dffdbdb4ded6
109 109
110 // 110 //
111 // "Save" a byte array to file. Basically creates a blob URI 111 // "Save" a byte array to file. Basically creates a blob URI
112 // and dumps it in the DOM, giving user a download. 112 // and dumps it in the DOM, giving user a download.
113 // 113 //
114 boolean mpSaveBinaryFile(String name, byte[] data) 114 boolean mpSaveBinaryBlob(String name, void blob)
115 { 115 {
116 var blob = mpMakeBinaryBlob(data);
117 if (blob == null)
118 {
119 console.log("Could not create BLOB from data.");
120 return false;
121 }
122
123 var url = window.URL.createObjectURL(blob); 116 var url = window.URL.createObjectURL(blob);
124 if (url == null) 117 if (url == null)
125 { 118 {
126 console.log("Could not create URL from BLOB object."); 119 console.log("Could not create URL from BLOB object.");
127 return false; 120 return false;
137 alink.download = name; 130 alink.download = name;
138 alink.click(); 131 alink.click();
139 132
140 window.URL.revokeObjectURL(url); 133 window.URL.revokeObjectURL(url);
141 return true; 134 return true;
135 }
136
137
138 boolean mpSaveBinaryFile(String name, byte[] data)
139 {
140 var blob = mpMakeBinaryBlob(data);
141 if (blob == null)
142 {
143 console.log("Could not create BLOB from data.");
144 return false;
145 }
146
147 return mpSaveBinaryBlob(name, blob);
142 } 148 }
143 149
144 150
145 // bordh/v = 64, 32, omag = 1 151 // bordh/v = 64, 32, omag = 1
146 void mpSavePNGImage(String name, int fmt, boolean border, int bordh, int bordv, int omag) 152 void mpSavePNGImage(String name, int fmt, boolean border, int bordh, int bordv, int omag)