Skip to content

Commit b5195e2

Browse files
AlcaDesignyining1023
authored andcommitted
fix: Use Blobs to save files of larger sizes (#271)
* fix: Use Blobs to save files of larger sizes fix #270 * use saveBlob() to save knn models, delete io.saveFile(), because saveBlob does the same thing and can handle big files
1 parent f8acd73 commit b5195e2

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

src/KNNClassifier/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class KNN {
139139
this.knnClassifier.dispose();
140140
}
141141

142-
save(name) {
142+
async save(name) {
143143
const dataset = this.knnClassifier.getClassifierDataset();
144144
if (this.mapStringToIndex.length > 0) {
145145
Object.keys(dataset).forEach((key) => {
@@ -159,7 +159,7 @@ class KNN {
159159
if (name) {
160160
fileName = name.endsWith('.json') ? name : `${name}.json`;
161161
}
162-
io.saveFile(fileName, JSON.stringify({ dataset, tensors }));
162+
await io.saveBlob(JSON.stringify({ dataset, tensors }), fileName, 'application/octet-stream');
163163
}
164164

165165
load(path, callback) {

src/utils/io.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
55

6-
// Save a File
7-
const saveFile = (name, data) => {
8-
const downloadElt = document.createElement('a');
9-
downloadElt.setAttribute('href', `data:text/plain;charset=utf-8,${encodeURIComponent(data)}`);
10-
downloadElt.setAttribute('download', name);
11-
downloadElt.style.display = 'none';
12-
document.body.appendChild(downloadElt);
13-
downloadElt.click();
14-
document.body.removeChild(downloadElt);
15-
};
16-
176
const saveBlob = async (data, name, type) => {
187
const link = document.createElement('a');
198
link.style.display = 'none';
@@ -37,7 +26,6 @@ const loadFile = async (path, callback) => fetch(path)
3726
});
3827

3928
export {
40-
saveFile,
4129
saveBlob,
4230
loadFile,
4331
};

0 commit comments

Comments
 (0)