From 8d546341fbf8fc45543cf33e40097bae994cdfd5 Mon Sep 17 00:00:00 2001
From: lyg <1543117173@qq.com>
Date: 星期五, 14 六月 2024 01:33:31 +0800
Subject: [PATCH] 清理文本栈溢出异常处理

---
 config.json  |    4 ++--
 src/main.mjs |   15 ++++++++++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/config.json b/config.json
index 3a54ac3..762e30b 100644
--- a/config.json
+++ b/config.json
@@ -3,10 +3,10 @@
   "startRow": 1,
   
   "//缁撴潫琛屽彿锛屼粠0寮�濮嬶紝涓嶅寘鍚琛�": "//",
-  "endRow": 2001,
+  "endRow": 200,
 
   "//绾跨▼鏁�": "//",
-  "threadSize": 4,
+  "threadSize": 10,
 
   "//瀹氭椂缁撴潫鏃堕棿锛屽崟浣嶅垎閽燂紝0琛ㄧず涓嶈缃畾鏃剁粨鏉熸椂闂�": "//",
   "endOfTime": 0,
diff --git a/src/main.mjs b/src/main.mjs
index ce09c61..20703fd 100644
--- a/src/main.mjs
+++ b/src/main.mjs
@@ -351,7 +351,17 @@
               text = /(.|\n)*<pre>((.|\n)*)<\/pre>(.|\n)*/g.exec(text)[2];
               fs.writeFileSync(filepath, text, 'utf-8');
             }
-            fs.writeFileSync(filepath + '.result.txt', cleanText(text), 'utf-8');
+            try {
+              fs.writeFileSync(filepath + '.result.txt', cleanText(text), 'utf-8');
+            } catch (e) {
+              reject(e);
+              try {
+                out.close();
+                fs.unlink(filepath, (e) => console.error(e));
+              } catch (e) {
+                console.error(e);
+              }
+            }
           }, 1000);
           resolve(true);
         });
@@ -588,3 +598,6 @@
   main();
 }
 
+// const filepath = "D:\\projects\\book-crawler\\downloads\\10231261 978-1-331-76167-9.txt";
+// const text = fs.readFileSync(filepath, 'utf8');
+// fs.writeFileSync(filepath + '.result.txt', cleanText(text), 'utf-8');
\ No newline at end of file

--
Gitblit v1.9.1