TagSpaces is an offline, open source, document manager with tagging support
introduce saveTextFilePromise and saveBinaryFilePromise
Borislav Sapundzhiev3f58a72970b8
diff --git a/data/chromium/chrome.api.js b/data/chromium/chrome.api.jsindex 6ac62b427..af5b33627 100644--- a/data/chromium/chrome.api.js+++ b/data/chromium/chrome.api.js@@ -272,13 +272,16 @@ define(function(require, exports, module) {}- function saveFilePromise(filePath, content, mode) {+ function saveFilePromise(filePath, content, overwrite) {console.log("Saving binary file: " + filePath);return new Promise(function(resolve, reject) {- var blob = new Blob([content], {- type: "text/plain;charset=utf-8"- });- saveAs(blob, TSCORE.TagUtils.extractFileName(filePath));+ overwrite = overwrite || true;+ if(overwrite) {+ var blob = new Blob([content], {+ type: "text/plain;charset=utf-8"+ });+ saveAs(blob, TSCORE.TagUtils.extractFileName(filePath));+ }resolve();});}@@ -441,6 +444,8 @@ define(function(require, exports, module) {exports.getFileContent = getFileContent; /** @deprecated */exports.saveFilePromise = saveFilePromise;+ exports.saveTextFilePromise = saveFilePromise;+ exports.saveBinaryFilePromise = saveFilePromise;exports.saveTextFile = saveTextFile; /** @deprecated */exports.saveBinaryFile = saveBinaryFile; /** @deprecated */diff --git a/data/cordova/cordova.api.js b/data/cordova/cordova.api.jsindex f988012d4..01386d78b 100644--- a/data/cordova/cordova.api.js+++ b/data/cordova/cordova.api.js@@ -811,6 +811,24 @@ define(function(require, exports, module) {});}+ function saveTextFilePromise(filePath, content, overWrite) {+ console.log("Saving file: " + filePath);+ // Handling the UTF8 support for text files+ var UTF8_BOM = "\ufeff";+ if (content.indexOf(UTF8_BOM) === 0) {+ console.log("Content beging with a UTF8 bom");+ } else {+ content = UTF8_BOM + content;+ }+ return saveFilePromise(filePath, content, overWrite);+ }++ function saveBinaryFilePromise(filePath, content, overWrite) {+ console.log("Saveing binary file: " + filePath);+ var dataView = new Int8Array(content);+ return saveFilePromise(filePath, content, overWrite);+ }+function saveTextFile(filePath, content, overWrite, silentMode) {console.log("Saving file: " + filePath);TSCORE.showLoadingAnimation();@@ -1178,6 +1196,8 @@ define(function(require, exports, module) {exports.getFileContentPromise = getFileContentPromise;exports.saveFilePromise = saveFilePromise;+ exports.saveTextFilePromise = saveTextFilePromise;+ exports.saveBinaryFilePromise = saveBinaryFilePromise;exports.saveTextFile = saveTextFile; /** @deprecated */exports.saveBinaryFile = saveBinaryFile; /** @deprecated */diff --git a/data/mozilla/mozilla.api.js b/data/mozilla/mozilla.api.jsindex 0f1a021ce..6d5055e61 100644--- a/data/mozilla/mozilla.api.js+++ b/data/mozilla/mozilla.api.js@@ -611,6 +611,8 @@ define(function(require, exports, module) {exports.getFileContent = getFileContent;exports.saveFilePromise = saveFilePromise;+ exports.saveTextFilePromise = saveFilePromise;+ exports.saveBinaryFilePromise = saveBinaryFilePromise;exports.saveTextFile = saveTextFile; /** @deprecated */exports.saveBinaryFile = saveBinaryFile; /** @deprecated */diff --git a/data/web/web.api.js b/data/web/web.api.jsindex 699e47783..231cae1aa 100644--- a/data/web/web.api.js+++ b/data/web/web.api.js@@ -275,7 +275,7 @@ define(function(require, exports, module) {}- function saveFilePromise(filePath, content, overWrite, silentMod, mode) {+ function saveFilePromise(filePath, content, overWrite, mode) {return new Promise(function(resolve, reject) {var isNewFile = false;davClient.propfind(encodeURI(filePath), function(status, data) {@@ -304,9 +304,19 @@ define(function(require, exports, module) {});}+ function saveTextFilePromise(filePath, content, overWrite) {+ console.log("Saving text file: " + filePath);+ return saveFilePromise(filePath, content, overWrite, "text");+ }++ function saveBinaryFilePromise(filePath, content, overWrite) {+ console.log("Saving binary file: " + filePath);+ return saveFilePromise(filePath, content, overWrite);+ }+function saveTextFile(filePath, content, overWrite, silentMode) {console.log("Saving file: " + filePath); //+" content: "+content);- saveFilePromise(filePath, content, overWrite, silentMode, "text").then(function(isNewFile) {+ saveFilePromise(filePath, content, overWrite, "text").then(function(isNewFile) {if (silentMode !== true) {TSPOSTIO.saveTextFile(filePath, isNewFile);}@@ -558,6 +568,8 @@ define(function(require, exports, module) {exports.getFileContentPromise = getFileContentPromise;exports.saveFilePromise = saveFilePromise;+ exports.saveTextFilePromise = saveTextFilePromise;+ exports.saveBinaryFilePromise = saveBinaryFilePromise;exports.saveTextFile = saveTextFile; /** @deprecated */exports.saveBinaryFile = saveBinaryFile; /** @deprecated */