mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update lib/pipe-ipc, lib/xml
This commit is contained in:
parent
46eb8e6609
commit
14e87fbe63
|
@ -94,46 +94,73 @@ function makeProbabilityBit(p) {
|
||||||
return !( p > 0.0 ? ( (randomize() / p) > 1.0 ) : true) ? 1 : 0;
|
return !( p > 0.0 ? ( (randomize() / p) > 1.0 ) : true) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFSO() {
|
function makeInterface(i) {
|
||||||
return CreateObject("Scripting.FileSystemObject");
|
return CreateObject(["Scripting.FileSystemObject", "ADODB.Stream"][i]);
|
||||||
}
|
|
||||||
|
|
||||||
function createADO() {
|
|
||||||
return CreateObject("ADODB.Stream");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openTextFile(filename, iomode) {
|
function openTextFile(filename, iomode) {
|
||||||
return createFSO().OpenTextFile(filename, iomode, true, TristateTrue);
|
return makeInterface(0).OpenTextFile(filename, iomode, true, TristateTrue);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkFileExists(filename) {
|
function checkFileExists(filename) {
|
||||||
return createFSO().FileExists(filename);;
|
return makeInterface(0).FileExists(filename);;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteFile(filename) {
|
function deleteFile(filename) {
|
||||||
if (checkFileExists(filename)) createFSO().DeleteFile(filename);
|
if (checkFileExists(filename)) makeInterface(0).DeleteFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileSize(filename) {
|
function getFileSize(filename) {
|
||||||
try {
|
try {
|
||||||
return createFSO().GetFile(filename).Size;
|
return makeInterface(0).GetFile(filename).Size;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function AdoConvertToStream(ado, position) {
|
function Converter() {
|
||||||
position = (position !== "undefined" ? position : 0);
|
this.value = null;
|
||||||
|
|
||||||
var newAdo = createADO();
|
this.from = function(value) {
|
||||||
newAdo.Type = adTypeBinary;
|
this.value = value;
|
||||||
newAdo.Mode = adModeReadWrite;
|
};
|
||||||
newAdo.Open();
|
|
||||||
ado.Position = position;
|
this.getBinaryFromText = function() {
|
||||||
ado.CopyTo(newAdo);
|
var stream = makeInterface(1);
|
||||||
ado.Flush();
|
stream.Type = adTypeText;
|
||||||
ado.Close();
|
stream.CharSet = CdoCharset.CdoUTF_8;
|
||||||
return newAdo;
|
stream.Open();
|
||||||
|
stream.WriteText(this.value);
|
||||||
|
stream.Position = 0;
|
||||||
|
stream.Type = adTypeBinary;
|
||||||
|
return stream.Read();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getTextFromBinary = function() {
|
||||||
|
var stream = makeInterface(1);
|
||||||
|
stream.Type = adTypeBinary;
|
||||||
|
stream.Open();
|
||||||
|
stream.Write(this.value);
|
||||||
|
stream.Position = 0;
|
||||||
|
stream.Type = adTypeText;
|
||||||
|
stream.CharSet = CdoCharset.CdoUTF_8;
|
||||||
|
return stream.ReadText();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.repositionObject = function(stream, position) {
|
||||||
|
position = (position !== "number" ? 0 : position);
|
||||||
|
|
||||||
|
var _stream = makeInterface(1);
|
||||||
|
_stream.Type = adTypeBinary;
|
||||||
|
_stream.Mode = adModeReadWrite;
|
||||||
|
_stream.Open();
|
||||||
|
stream.Position = position;
|
||||||
|
stream.CopyTo(_stream);
|
||||||
|
stream.Flush();
|
||||||
|
stream.Close();
|
||||||
|
|
||||||
|
return _stream;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function PipeIPC() {
|
function PipeIPC() {
|
||||||
|
@ -368,14 +395,14 @@ function PipeIPC() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert UTF-16 BOM to a character set
|
// Convert UTF-16 BOM to a character set
|
||||||
var ado = createADO();
|
var stream = makeInterface(1);
|
||||||
ado.Type = adTypeText;
|
stream.Type = adTypeText;
|
||||||
ado.Charset = charset;
|
stream.Charset = charset;
|
||||||
ado.Open();
|
stream.Open();
|
||||||
ado.WriteText(str);
|
stream.WriteText(str);
|
||||||
ado = AdoConvertToStream(ado, 3);
|
stream = (new Converter()).repositionObject(stream, 3);
|
||||||
ado.SaveToFile(dst, adSaveCreateOverWrite);
|
stream.SaveToFile(dst, adSaveCreateOverWrite);
|
||||||
ado.Close();
|
stream.Close();
|
||||||
|
|
||||||
// Set a result
|
// Set a result
|
||||||
isCommited = true;
|
isCommited = true;
|
||||||
|
@ -463,7 +490,7 @@ function PipeIPC() {
|
||||||
var isRead = false;
|
var isRead = false;
|
||||||
while (!isRead) {
|
while (!isRead) {
|
||||||
try {
|
try {
|
||||||
var ado = createADO();
|
var ado = makeInterface(1);
|
||||||
ado.Charset = charset;
|
ado.Charset = charset;
|
||||||
ado.Open();
|
ado.Open();
|
||||||
ado.LoadFromFile(filename);
|
ado.LoadFromFile(filename);
|
||||||
|
@ -504,6 +531,7 @@ exports.connect = function(path, callback) {
|
||||||
return pipe.connect(path, callback);
|
return pipe.connect(path, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.Converter = Converter;
|
||||||
exports.UUIDv4 = UUIDv4;
|
exports.UUIDv4 = UUIDv4;
|
||||||
exports.CRC32 = CRC32;
|
exports.CRC32 = CRC32;
|
||||||
|
|
||||||
|
@ -521,7 +549,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist;
|
||||||
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
||||||
exports.adModeReadWrite = adModeReadWrite;
|
exports.adModeReadWrite = adModeReadWrite;
|
||||||
|
|
||||||
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.22";
|
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.23";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
39
lib/xml.js
39
lib/xml.js
|
@ -1,37 +1,8 @@
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// XML API
|
// XML interface
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
var FILE = require("lib/file");
|
var FILE = require("lib/file");
|
||||||
|
var PipeIPC = require("lib/pipe-ipc");
|
||||||
var adTypeText = 2;
|
|
||||||
var adTypeBinary = 1;
|
|
||||||
|
|
||||||
var StreamConvert = function(data) {
|
|
||||||
this.data = data;
|
|
||||||
|
|
||||||
this.toBinary = function() {
|
|
||||||
var BinaryStream = CreateObject("ADODB.Stream");
|
|
||||||
BinaryStream.Type = adTypeText;
|
|
||||||
BinaryStream.CharSet = FILE.CdoCharset.CdoUTF_8;
|
|
||||||
BinaryStream.Open();
|
|
||||||
BinaryStream.WriteText(this.data);
|
|
||||||
BinaryStream.Position = 0;
|
|
||||||
BinaryStream.Type = adTypeBinary;
|
|
||||||
BinaryStream.Position = 0;
|
|
||||||
return BinaryStream.Read();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.toString = function() {
|
|
||||||
var BinaryStream = CreateObject("ADODB.Stream");
|
|
||||||
BinaryStream.Type = adTypeBinary;
|
|
||||||
BinaryStream.Open();
|
|
||||||
BinaryStream.Write(this.data);
|
|
||||||
BinaryStream.Position = 0;
|
|
||||||
BinaryStream.Type = adTypeText;
|
|
||||||
BinaryStream.CharSet = FILE.CdoCharset.CdoUTF_8;
|
|
||||||
return BinaryStream.ReadText();
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var XMLObject = function(dom) {
|
var XMLObject = function(dom) {
|
||||||
this.filename = null;
|
this.filename = null;
|
||||||
|
@ -120,7 +91,7 @@ var XMLObject = function(dom) {
|
||||||
var node = dom.createElement("XMLNode");
|
var node = dom.createElement("XMLNode");
|
||||||
|
|
||||||
node.dataType = type;
|
node.dataType = type;
|
||||||
node.nodeTypedValue = (new StreamConvert(value)).toBinary();
|
node.nodeTypedValue = (new PipeIPC.Converter()).from(value).getBinaryFromText();
|
||||||
|
|
||||||
return node.text;
|
return node.text;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -136,7 +107,7 @@ var XMLObject = function(dom) {
|
||||||
node.dataType = type;
|
node.dataType = type;
|
||||||
node.text = value;
|
node.text = value;
|
||||||
|
|
||||||
return (new StreamConvert(node.nodeTypedValue)).toString();
|
return (new PipeIPC.Converter()).from(node.nodeTypedValue).getTextFromBinary();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("XMLObject->decode():", e.message);
|
console.error("XMLObject->decode():", e.message);
|
||||||
}
|
}
|
||||||
|
@ -164,6 +135,6 @@ exports.load = load;
|
||||||
exports.encode = encode;
|
exports.encode = encode;
|
||||||
exports.decode = decode;
|
exports.decode = decode;
|
||||||
|
|
||||||
exports.VERSIONINFO = "XML interface (xml.js) version 0.2.3";
|
exports.VERSIONINFO = "XML interface (xml.js) version 0.2.4";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user