`wtfjs.js` 中的流分块反模式会导致 Markdown/UTF-8 数据损坏和重复的横幅
作者: codeCraft-Ritik创建于 2026年9月14日更新于 2026年9月14日
In wtfjs.js:
fs.createReadStream(translation)
.pipe(
obj(function (chunk, enc, cb) {
const message = [];
if (notifier.update) {
message.push(
`Update available: {green.bold ${notifier.update.latest}} {dim current: ${notifier.update.current}}`
);
message.push(`Run {blue npm install -g ${pkg.name}} to update.`);
this.push(boxen(message.join("\n"), boxenOpts));
}
this.push(msee.parse(chunk.toString(), mseeOpts));
cb();
})
)
.pipe(pager());fs.createReadStream emits data in 64KB chunks (highWaterMark: 64 * 1024).
README.mdis ~75KB (2 chunks).README-zh-cn.mdis ~76KB (2 chunks).README-hi.mdis ~98KB (2 chunks).README-si.mdis ~208KB (4 chunks).
- UTF-8 and Markdown Splitting: Slicing at an arbitrary 64KB byte offset can bisect a 3- or 4-byte UTF-8 character, producing replacement characters (``) or malformed glyphs. It also splits markdown constructs (e.g.
```jsfences, tables), causingmsee.parse()to render broken ANSI escapes in the terminal pager. - Banner Duplication:
if (notifier.update)executes inside the per-chunk transform handler. When an update is available,this.push(boxen(...))runs on every chunk, causing duplicate notification boxes to appear in the middle of reading the guide.
--- a/wtfjs.js
+++ b/wtfjs.js
@@ -74,19 +74,18 @@ fs.stat(translation, function (err, stats) {
- fs.createReadStream(translation)
- .pipe(
- obj(function (chunk, enc, cb) {
- const message = [];
-
- if (notifier.update) {
- message.push(
- `Update available: {green.bold ${notifier.update.latest}} {dim current: ${notifier.update.current}}`
…内容来源: denysdovhan/wtfjs