diff --git a/src/i18n/locales/hi/tools.json b/src/i18n/locales/hi/tools.json index 7840a55d63..7970b36474 100644 --- a/src/i18n/locales/hi/tools.json +++ b/src/i18n/locales/hi/tools.json @@ -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)" }, diff --git a/src/integrations/misc/read-partial-content.ts b/src/integrations/misc/read-partial-content.ts index e8db809982..34f3585f48 100644 --- a/src/integrations/misc/read-partial-content.ts +++ b/src/integrations/misc/read-partial-content.ts @@ -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({