Skip to content

Instantly share code, notes, and snippets.

@iron9light
Created September 3, 2011 16:07
Show Gist options
  • Save iron9light/1191400 to your computer and use it in GitHub Desktop.
Save iron9light/1191400 to your computer and use it in GitHub Desktop.
Windows jscript base64 encoder. Drag and drop files you wanna encode to this .js file.
var fsDoOverwrite = true // Overwrite file with base64 code
var fsAsASCII = false // Create base64 code file as ASCII file
var adTypeBinary = 1 // Binary file is encoded
function encode(from, to) {
var inputStream = WScript.CreateObject("ADODB.Stream");
inputStream.Type = adTypeBinary
inputStream.Open();
inputStream.LoadFromFile(from);
var xml = WScript.CreateObject("MSXml2.DOMDocument");
var element = xml.createElement("Base64Data");
element.dataType = "bin.base64";
element.nodeTypedValue = inputStream.Read();
inputStream.Close();
var fileSystem = WScript.CreateObject("Scripting.FileSystemObject");
var outputStream = fileSystem.CreateTextFile(to, fsDoOverwrite, fsAsASCII);
outputStream.Write(element.text.replace(/\n/g, ""));
outputStream.Close();
}
function getTxtName(name) {
return name + ".txt";
}
function main() {
var args = WScript.Arguments;
for(i = 0; i < args.length; ++i) {
encode(args(i), getTxtName(args(i)));
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment