Update pipe-ipc.js

This commit is contained in:
Namhyeon Go 2023-09-20 12:25:52 +09:00 committed by GitHub
parent a035304803
commit b60ef15c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,13 +147,15 @@ function PipeIPC() {
this.tmpfile = this.savefile + ".tmp";
// read a text from save file
var isExistsSaveFile = createFSO().FileExists(this.savefile);
if (isExistsSaveFile) {
var isExistsTmpFile = createFSO().FileExists(this.tmpfile);
if (!isExistsTmpFile) {
var handler = createFSO().OpenTextFile(this.tmpfile, ForWriting, true, TristateTrue);
handler.Write(this.readTextFromFile(filename));
handler.Write(this.readTextFromFile(this.savefile));
handler.Close();
}
// with iomode (default: ForAppending)
var iomode = (iomode !== "undefined" ? ForAppending : iomode);
this.openRecorder(iomode);
};
@ -181,7 +183,10 @@ function PipeIPC() {
this.writer.Write(message + this.delimiter);
};
this.write = function(message) {
this.write = function(message, iomode) {
// with iomode (default: ForAppending)
var iomode = (iomode !== "undefined" ? ForAppending : iomode);
if (this.savefile != null) {
this.record(message);
}
@ -190,7 +195,7 @@ function PipeIPC() {
while (!isWritten) {
try {
this.flush();
this.openWriter(ForAppending);
this.openWriter(iomode);
this._write(message);
this.closeWriter();
isWritten = true;
@ -345,23 +350,23 @@ function PipeIPC() {
};
this.readTextFromFile = function(filename) {
this.readTextFromFile = function(filename, charset) {
var text = '';
var isLoaded = false;
var isFileExists = createFSO().FileExists(filename);
if (isFileExists) {
//console.info("File", filename, "exists");
while (!isLoaded) {
var isRead = false;
while (!isRead) {
try {
var ado = createADO();
ado.CharSet = this.charset;
ado.CharSet = charset;
ado.Open();
ado.LoadFromFile(filename);
text += ado.ReadText();
ado.Close();
isLoaded = true;
isRead = true;
} catch (e) {
isLoaded = false;
isRead = false;
}
}
} else {
@ -372,8 +377,8 @@ function PipeIPC() {
};
this.loadFromFile = function(filename) {
this.write(this.readTextFromFile(filename));
this.loadFromFile = function(filename, charset) {
this.write(this.readTextFromFile(filename, charset), ForWriting);
};
}
@ -401,7 +406,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist;
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
exports.adModeReadWrite = adModeReadWrite;
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.8";
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.9";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = require;