Update pipe-ipc.js

This commit is contained in:
Namhyeon Go 2022-09-27 19:28:20 +09:00 committed by GitHub
parent c3cec2bba7
commit 590dde45c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,7 +27,7 @@ function PipeIPC() {
this.createWriter = function() {
//this.writer = CreateObject("Scripting.FileSystemObject").CreateTextFile(this.path, true, true);
this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, ForWriting, true, TristateTrue);
this.writer = CreateObject("Scripting.FileSystemObject").OpenTextFile(this.path, ForAppending, true, TristateTrue);
};
this.closeWriter = function() {
@ -46,6 +46,7 @@ function PipeIPC() {
this._write = function(message) {
this.writer.Write(message);
this.writer.Write("\r\n");
};
this.write = function(message) {
@ -55,7 +56,6 @@ function PipeIPC() {
try {
this.createWriter();
this._write(message);
sleep(1);
this.writer.Close();
isWritten = true;
} catch (e) {
@ -63,18 +63,18 @@ function PipeIPC() {
}
}
};
this._read = function() {
return this.reader.ReadAll();
return this.reader.ReadAll().split(/\r?\n/);
};
this.read = function() {
var isRead = false;
var text = "";
var messages = [];
while (!isRead) {
try {
text = this._read();
messages = this._read();
isRead = true;
} catch (e) {
this.closeReader();
@ -82,17 +82,11 @@ function PipeIPC() {
}
}
return text;
return messages;
};
this.readContinuously = function(callback) {
var isNext = true;
if (typeof callback === "function") {
while (isNext) {
isNext = callback(this, this.read()) || true;
}
}
this.readText = function() {
return this.read().join(' ');
};
this.close = function() {
@ -105,7 +99,7 @@ exports.create = function() {
return new PipeIPC();
};
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1";
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.1";
exports.AUTHOR = "Nathan Catswords <catswords@protonmail.com>";
exports.global = global;
exports.require = require;