1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-24 22:33:16 +00:00

Improve the base64 encode/decode utility functions (#4053)

Make good use of "$:/core/modules/utils/base64-utf8/base64-utf8.module.js"
* Add a new base64Encode()
* Both of base64Encode and base64Decode work for Nodejs and Browsers
This commit is contained in:
Bram Chen 2019-07-04 00:39:32 +08:00 committed by Jeremy Ruston
parent f42351e235
commit 958b3e7b7c

View File

@ -12,6 +12,8 @@ Various static utility functions.
/*global $tw: false */ /*global $tw: false */
"use strict"; "use strict";
var base64utf8 = require("$:/core/modules/utils/base64-utf8/base64-utf8.module.js");
/* /*
Display a message, in colour if we're on a terminal Display a message, in colour if we're on a terminal
*/ */
@ -683,12 +685,14 @@ exports.hashString = function(str) {
Decode a base64 string Decode a base64 string
*/ */
exports.base64Decode = function(string64) { exports.base64Decode = function(string64) {
if($tw.browser) { return base64utf8.base64.decode.call(base64utf8,string64);
// TODO };
throw "$tw.utils.base64Decode() doesn't work in the browser";
} else { /*
return Buffer.from(string64,"base64").toString(); Encode a string to base64
} */
exports.base64Encode = function(string64) {
return base64utf8.base64.encode.call(base64utf8,string64);
}; };
/* /*