welsonjs/lib/base64.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-07-07 17:06:38 +00:00
////////////////////////////////////////////////////////////////////////
// Base64 API
////////////////////////////////////////////////////////////////////////
2020-11-05 03:04:50 +00:00
var XML = require("lib/xml");
exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
exports.global = global;
exports.require = require;
2020-07-07 17:06:38 +00:00
2020-10-20 02:41:26 +00:00
var getStream_StringToBinary = function(dText) {
2020-07-23 06:16:01 +00:00
var adTypeText = 2;
var adTypeBinary = 1;
2020-10-20 02:41:26 +00:00
var BinaryStream = CreateObject("ADODB.Stream");
2020-07-23 06:16:01 +00:00
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
BinaryStream.Open();
BinaryStream.WriteText(dText);
BinaryStream.Position = 0;
BinaryStream.Type = adTypeBinary;
BinaryStream.Position = 0;
return BinaryStream.Read();
2020-07-07 17:06:38 +00:00
};
2020-10-20 02:41:26 +00:00
var getStream_BinaryToString = function(dBinary) {
2020-07-23 06:16:01 +00:00
var adTypeText = 2;
var adTypeBinary = 1;
2020-10-20 02:41:26 +00:00
var BinaryStream = CreateObject("ADODB.Stream");
2020-07-23 06:16:01 +00:00
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.Write(dBinary);
BinaryStream.Position = 0;
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
return BinaryStream.ReadText();
2020-07-07 17:06:38 +00:00
};
exports.encode = function(sText) {
2020-11-05 03:04:50 +00:00
var oXML = XML.createXMLObject();
2020-07-23 06:16:01 +00:00
var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64";
2020-10-20 02:41:26 +00:00
oNode.nodeTypedValue = getStream_StringToBinary(sText);
2020-07-23 06:16:01 +00:00
return oNode.text;
2020-07-07 17:06:38 +00:00
};
exports.decode = function(vCode) {
2020-11-05 03:04:50 +00:00
var oXML = XML.createXMLObject();
2020-07-23 06:16:01 +00:00
var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64";
oNode.text = vCode;
2020-10-20 02:41:26 +00:00
return getStream_BinaryToString(oNode.nodeTypedValue);
2020-07-07 17:06:38 +00:00
};