mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update pipe-ipc.js
This commit is contained in:
parent
e28f346447
commit
f40a45c5f1
|
@ -61,6 +61,14 @@ function createUUIDv4() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createFSO() {
|
||||||
|
return CreateObject("Scripting.FileSystemObject");
|
||||||
|
}
|
||||||
|
|
||||||
|
function createADO() {
|
||||||
|
return CreateObject("ADODB.Stream");
|
||||||
|
}
|
||||||
|
|
||||||
function PipeIPC() {
|
function PipeIPC() {
|
||||||
this.path = "data\\.pipe_:pipename";
|
this.path = "data\\.pipe_:pipename";
|
||||||
this.delimiter = "\r\n";
|
this.delimiter = "\r\n";
|
||||||
|
@ -107,7 +115,7 @@ function PipeIPC() {
|
||||||
this.openWriter = function(iomode) {
|
this.openWriter = function(iomode) {
|
||||||
while (this.writer == null) {
|
while (this.writer == null) {
|
||||||
try {
|
try {
|
||||||
this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, iomode, true, TristateTrue);
|
this.writer = createFSO().OpenTextFile(this.path, iomode, true, TristateTrue);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -122,7 +130,7 @@ function PipeIPC() {
|
||||||
this.openReader = function() {
|
this.openReader = function() {
|
||||||
while (this.reader == null) {
|
while (this.reader == null) {
|
||||||
try {
|
try {
|
||||||
this.reader = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, ForReading, true, TristateTrue);
|
this.reader = createFSO().OpenTextFile(this.path, ForReading, true, TristateTrue);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -148,7 +156,7 @@ function PipeIPC() {
|
||||||
this.openRecorder = function(iomode) {
|
this.openRecorder = function(iomode) {
|
||||||
while (this.recorder == null) {
|
while (this.recorder == null) {
|
||||||
try {
|
try {
|
||||||
this.recorder = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.tmpfile, iomode, true, TristateTrue);
|
this.recorder = createFSO().OpenTextFile(this.tmpfile, iomode, true, TristateTrue);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -217,7 +225,7 @@ function PipeIPC() {
|
||||||
|
|
||||||
// define functions
|
// define functions
|
||||||
var StripAdoBOM = function(adoObj) {
|
var StripAdoBOM = function(adoObj) {
|
||||||
var newAdoObj = CreateObject("ADODB.Stream");
|
var newAdoObj = createADO();
|
||||||
newAdoObj.Type = adTypeBinary;
|
newAdoObj.Type = adTypeBinary;
|
||||||
newAdoObj.Mode = adModeReadWrite;
|
newAdoObj.Mode = adModeReadWrite;
|
||||||
newAdoObj.Open();
|
newAdoObj.Open();
|
||||||
|
@ -231,7 +239,7 @@ function PipeIPC() {
|
||||||
while (!isCommited) {
|
while (!isCommited) {
|
||||||
try {
|
try {
|
||||||
// Open a temporary file
|
// Open a temporary file
|
||||||
var fso = CreateObject("Scripting.FileSystemObject").OpenTextFile(src, ForReading, true, TristateTrue);
|
var fso = createFSO().OpenTextFile(src, ForReading, true, TristateTrue);
|
||||||
var text = fso.ReadAll();
|
var text = fso.ReadAll();
|
||||||
var sentences = text.split(this.delimiter);
|
var sentences = text.split(this.delimiter);
|
||||||
var newSentences = [], str = '';
|
var newSentences = [], str = '';
|
||||||
|
@ -247,7 +255,7 @@ function PipeIPC() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert UTF-16 BOM to UTF-8
|
// Convert UTF-16 BOM to UTF-8
|
||||||
var ado = CreateObject("ADODB.Stream");
|
var ado = createADO();
|
||||||
ado.Type = adTypeText;
|
ado.Type = adTypeText;
|
||||||
ado.Charset = charset;
|
ado.Charset = charset;
|
||||||
ado.Open();
|
ado.Open();
|
||||||
|
@ -257,12 +265,12 @@ function PipeIPC() {
|
||||||
ado.Close();
|
ado.Close();
|
||||||
|
|
||||||
// Write a new temporary file
|
// Write a new temporary file
|
||||||
/*
|
if (this.maxSentences > 0) {
|
||||||
var _fso = CreateObject("Scripting.FileSystemObject").OpenTextFile(src, ForWriting, true, TristateTrue);
|
var handler = createFSO().OpenTextFile(src, ForWriting, true, TristateTrue);
|
||||||
_fso.Write(str);
|
handler.Write(str);
|
||||||
_fso.Close();
|
handler.Close();
|
||||||
*/
|
}
|
||||||
|
|
||||||
// Close the temporary file
|
// Close the temporary file
|
||||||
fso.Close();
|
fso.Close();
|
||||||
|
|
||||||
|
@ -324,19 +332,19 @@ function PipeIPC() {
|
||||||
|
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
this.close();
|
this.close();
|
||||||
CreateObject("Scripting.FileSystemObject").DeleteFile(this.path);
|
createFSO().DeleteFile(this.path);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.readTextFromFile = function(filename) {
|
this.readTextFromFile = function(filename) {
|
||||||
var text = '';
|
var text = '';
|
||||||
var isLoaded = false;
|
var isLoaded = false;
|
||||||
var isFileExists = CreateObject("Scripting.FileSystemObject").FileExists(filename);
|
var isFileExists = createFSO().FileExists(filename);
|
||||||
if (isFileExists) {
|
if (isFileExists) {
|
||||||
//console.info("File", filename, "exists");
|
//console.info("File", filename, "exists");
|
||||||
while (!isLoaded) {
|
while (!isLoaded) {
|
||||||
try {
|
try {
|
||||||
var ado = CreateObject("ADODB.Stream");
|
var ado = createADO();
|
||||||
ado.CharSet = this.charset;
|
ado.CharSet = this.charset;
|
||||||
ado.Open();
|
ado.Open();
|
||||||
ado.LoadFromFile(filename);
|
ado.LoadFromFile(filename);
|
||||||
|
@ -384,7 +392,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.7";
|
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.6";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user