Skip to content

Commit f343c50

Browse files
committed
fix(check-html-links): read and parse with the same increased highWaterMark
1 parent a7b0dbb commit f343c50

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.changeset/curly-poets-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'check-html-links': patch
3+
---
4+
5+
When reading bigger files, especially bigger files with all content on one line it could mean a read chunk is in the middle of a character. This can lead to strange symbols in the resulting string. The `hightWaterMark` is now increased from the node default of 16KB to 256KB. Additionally, the `hightWaterMark` is now synced for reading and parsing.

packages/check-html-links/src/validateFolder.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import path from 'path';
1515
const require = createRequire(import.meta.url);
1616
const { SaxEventType, SAXParser } = saxWasm;
1717

18+
const streamOptions = { highWaterMark: 256 * 1024 };
19+
1820
const saxPath = require.resolve('sax-wasm/lib/sax-wasm.wasm');
1921
const saxWasmBuffer = fs.readFileSync(saxPath);
20-
const parserReferences = new SAXParser(SaxEventType.Attribute);
21-
const parserIds = new SAXParser(SaxEventType.Attribute /*, { highWaterMark: 256 * 1024 } */);
22+
const parserReferences = new SAXParser(SaxEventType.Attribute, streamOptions);
23+
const parserIds = new SAXParser(SaxEventType.Attribute, streamOptions);
2224

2325
/** @type {Error[]} */
2426
let checkLocalFiles = [];
@@ -76,7 +78,7 @@ function extractReferences(htmlFilePath) {
7678
};
7779

7880
return new Promise(resolve => {
79-
const readable = fs.createReadStream(htmlFilePath);
81+
const readable = fs.createReadStream(htmlFilePath, streamOptions);
8082
readable.on('data', chunk => {
8183
// @ts-expect-error
8284
parserReferences.write(chunk);
@@ -112,7 +114,7 @@ function idExists(filePath, id) {
112114
};
113115

114116
return new Promise(resolve => {
115-
const readable = fs.createReadStream(filePath);
117+
const readable = fs.createReadStream(filePath, streamOptions);
116118
readable.on('data', chunk => {
117119
// @ts-expect-error
118120
parserIds.write(chunk);

0 commit comments

Comments
 (0)