Update pipe-ipc.js

This commit is contained in:
Namhyeon Go 2023-09-21 15:08:03 +09:00 committed by GitHub
parent cbac701e7e
commit f22364b2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,7 +109,7 @@ function AdoConvertToStream(ado, position) {
function PipeIPC() { function PipeIPC() {
this.path = "data\\.pipe_:pipename"; this.path = "data\\.pipe_:pipename";
this.delimiter = "\r\n"; this.delimiter = '\r\n';
this.reader = null; this.reader = null;
this.writer = null; this.writer = null;
this.recorder = null; this.recorder = null;
@ -181,6 +181,8 @@ function PipeIPC() {
}; };
this.startRecorder = function(filename, iomode) { this.startRecorder = function(filename, iomode) {
iomode = (iomode !== "undefined" ? ForAppending : iomode); // default: ForAppending
this.savefile = filename; this.savefile = filename;
this.tmpfile = this.savefile + ".tmp"; this.tmpfile = this.savefile + ".tmp";
@ -198,8 +200,7 @@ function PipeIPC() {
} }
} }
// with iomode (default: ForAppending) // open a recorder
iomode = (iomode !== "undefined" ? ForAppending : iomode);
this.openRecorder(iomode); this.openRecorder(iomode);
}; };
@ -224,16 +225,11 @@ function PipeIPC() {
}; };
this._write = function(message) { this._write = function(message) {
this.writer.Write(message + this.delimiter); this.writer.Write(message);
}; };
this.write = function(message, iomode) { this.write = function(message, iomode) {
// with iomode (default: ForAppending) iomode = (iomode !== "undefined" ? ForAppending : iomode); // default: ForAppending
iomode = (iomode !== "undefined" ? ForAppending : iomode);
if (this.savefile != null) {
this.record(message);
}
var isWritten = false; var isWritten = false;
while (!isWritten) { while (!isWritten) {
@ -250,6 +246,11 @@ function PipeIPC() {
} }
} }
// record the last message
if (isWritten && this.savefile != null) {
this.record(message);
}
return isWritten; return isWritten;
}; };
@ -355,7 +356,7 @@ function PipeIPC() {
this.read = function() { this.read = function() {
var isRead = false; var isRead = false;
var text = ""; var text = '';
while (!isRead) { while (!isRead) {
try { try {
@ -380,7 +381,6 @@ function PipeIPC() {
this.destroy = function() { this.destroy = function() {
this.close(); this.close();
createFSO().DeleteFile(this.path); createFSO().DeleteFile(this.path);
}; };
this.readTextFromFile = function(filename, charset) { this.readTextFromFile = function(filename, charset) {
@ -413,6 +413,11 @@ function PipeIPC() {
this.loadFromFile = function(filename, charset) { this.loadFromFile = function(filename, charset) {
this.write(this.readTextFromFile(filename, charset), ForWriting); this.write(this.readTextFromFile(filename, charset), ForWriting);
}; };
this.reload = function(charset) {
charset = (typeof charset !== "undefined" ? this.charset : charset);
this.loadFromFile(this.path, charset);
};
} }
exports.create = function() { exports.create = function() {
@ -440,7 +445,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.11"; exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.12";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = require; exports.require = require;