Update pipe-ipc.js

This commit is contained in:
Namhyeon Go 2023-09-21 20:46:56 +09:00 committed by GitHub
parent d4214f7f34
commit 9b0e67a12a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,6 +105,14 @@ function deleteFile(filename) {
if (checkFileExists(filename)) createFSO().DeleteFile(filename);
}
function getFileSize(filename) {
try {
return createFSO().GetFile(filename).Size;
} catch (e) {
return -1;
}
}
function AdoConvertToStream(ado, position) {
position = (position !== "undefined" ? position : 0);
@ -254,11 +262,12 @@ function PipeIPC() {
isWritten = true;
this.lastWriteTime = this.getCurrentTime();
} catch (e) {
//console.log(e.message);
this.closeWriter();
isWritten = false;
}
}
// record the last message
if (isWritten && this.savefile != null) {
this.record(message);
@ -299,13 +308,13 @@ function PipeIPC() {
try {
// Open a temporary file
var fso = openTextFile(src, ForReading);
var text = fso.ReadAll();
fso.Close(); // close the file immediately
var text = this._read(fso);
fso.Close(); // close the file immediately
var sentences = text.split(this.delimiter);
var newSentences = [], str = '';
// if enabled "maxSentences" feature
if (this.maxSentences > 0) {
if (text.length > 0 && this.maxSentences > 0) {
while (sentences.length > 0 && newSentences.length < this.maxSentences) {
newSentences.push(sentences.pop());
}
@ -326,7 +335,7 @@ function PipeIPC() {
} else {
str = text;
}
// Convert UTF-16 BOM to a character set
var ado = createADO();
ado.Type = adTypeText;
@ -340,6 +349,7 @@ function PipeIPC() {
// Set a result
isCommited = true;
} catch (e) {
//console.log(e.message);
isCommited = false;
}
}
@ -365,10 +375,14 @@ function PipeIPC() {
return isFlushed;
};
this._read = function() {
return (function(s) {
return s.length > 1 ? s.substring(1) : '';
})(this.reader.ReadAll());
this._read = function(fh) {
try {
return (function(s) {
return s.length > 1 ? s.substring(1) : '';
})(fh.ReadAll());
} catch (e) {
return '';
}
};
this.read = function() {
@ -377,7 +391,7 @@ function PipeIPC() {
while (!isRead) {
try {
text += this._read();
text += this._read(this.reader);
isRead = true;
this.lastReadTime = this.getCurrentTime();
} catch (e) {
@ -462,7 +476,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist;
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
exports.adModeReadWrite = adModeReadWrite;
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.14";
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.15";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = require;