Skip to content

Commit c0b2a6c

Browse files
committed
refactor: use existing strip-bom package instead of custom bomUtils
- Remove src/utils/bomUtils.ts and its test file - Update imports in extract-text.ts to use strip-bom package - Update imports in read-lines.ts to use strip-bom package - Keep the empty file detection logic in readFileTool.ts unchanged This eliminates code duplication by using the existing strip-bom package that is already used in DiffViewProvider.ts and CustomModesManager.ts.
1 parent 5063f31 commit c0b2a6c

File tree

4 files changed

+4
-127
lines changed

4 files changed

+4
-127
lines changed

src/integrations/misc/extract-text.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mammoth from "mammoth"
55
import fs from "fs/promises"
66
import { isBinaryFile } from "isbinaryfile"
77
import { extractTextFromXLSX } from "./extract-text-from-xlsx"
8-
import { stripBOM } from "../../utils/bomUtils"
8+
import stripBom from "strip-bom"
99

1010
async function extractTextFromPDF(filePath: string): Promise<string> {
1111
const dataBuffer = await fs.readFile(filePath)
@@ -70,7 +70,7 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
7070
if (!isBinary) {
7171
const content = await fs.readFile(filePath, "utf8")
7272
// Strip BOM if present before adding line numbers
73-
return addLineNumbers(stripBOM(content))
73+
return addLineNumbers(stripBom(content))
7474
} else {
7575
throw new Error(`Cannot read text for file type: ${fileExtension}`)
7676
}

src/integrations/misc/read-lines.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Now you can read a range of lines from a file
88
*/
99
import { createReadStream } from "fs"
10-
import { stripBOM } from "../../utils/bomUtils"
10+
import stripBom from "strip-bom"
1111

1212
const outOfRangeError = (filepath: string, n: number) => {
1313
return new RangeError(`Line with index ${n} does not exist in '${filepath}'. Note that line indexing is zero-based`)
@@ -70,7 +70,7 @@ export function readLines(filepath: string, endLine?: number, startLine?: number
7070

7171
// Strip BOM from the first chunk if present
7272
if (isFirstChunk) {
73-
chunkStr = stripBOM(chunkStr)
73+
chunkStr = stripBom(chunkStr)
7474
isFirstChunk = false
7575
}
7676

src/utils/__tests__/bomUtils.test.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/utils/bomUtils.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)