fix: address PR review comments

- Fix Hindi translation punctuation
- Fix race condition by checking stream.destroyed
- Optimize newline counting with regex
- Performance improvements for large file handling
- Defensive programming for end parameter already in place
This commit is contained in:
Will Li 2025-08-04 10:06:22 -07:00
parent e4bac4f334
commit 8269f3a65b
2 changed files with 7 additions and 13 deletions

View file

@ -3,7 +3,7 @@
"linesRange": " (पंक्तियाँ {{start}}-{{end}})",
"definitionsOnly": " (केवल परिभाषाएँ)",
"maxLines": " (अधिकतम {{max}} पंक्तियाँ)",
"showingOnlyLines": "कुल {{total}} पंक्तियों में से केवल {{shown}} दिखा रहे हैं। यदि आपको अधिक पंक्तियाँ पढ़नी हैं तो line_range का उपयोग करें",
"showingOnlyLines": "कुल {{total}} पंक्तियों में से केवल {{shown}} दिखा रहे हैं। यदि आपको अधिक पंक्तियाँ पढ़नी हैं तो line_range का उपयोग करें।",
"imageTooLarge": "छवि फ़ाइल बहुत बड़ी है ({{size}} MB)। अधिकतम अनुमतित आकार {{max}} MB है।",
"imageWithSize": "छवि फ़ाइल ({{size}} KB)"
},

View file

@ -57,8 +57,8 @@ export async function readPartialContent(filePath: string, maxChars: number): Pr
let hasContent = false
stream.on("data", (chunk: string | Buffer) => {
// Early exit if stream was already destroyed
if (streamDestroyed) {
// Check stream state immediately
if (streamDestroyed || stream.destroyed) {
return
}
@ -95,11 +95,8 @@ export async function readPartialContent(filePath: string, maxChars: number): Pr
}
// Count newlines in the chunk we're adding
for (let i = 0; i < chunkToAdd.length; i++) {
if (chunkToAdd[i] === "\n") {
currentLine++
}
}
const newlineCount = (chunkToAdd.match(/\n/g) || []).length
currentLine += newlineCount
content += chunkToAdd
@ -114,11 +111,8 @@ export async function readPartialContent(filePath: string, maxChars: number): Pr
// Recount lines in the final content
currentLine = 1
hasContent = content.length > 0
for (let i = 0; i < content.length; i++) {
if (content[i] === "\n") {
currentLine++
}
}
const finalNewlineCount = (content.match(/\n/g) || []).length
currentLine += finalNewlineCount
}
resolve({