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