Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/scanner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readdir, readFile, stat } from "node:fs/promises";
import { open, readdir } from "node:fs/promises";
import { join, relative } from "node:path";
import { scanFileWithRules } from "./rules.js";
import type { Finding, ScanFile, ScanResult, ScanTargetInput } from "./types.js";
Expand Down Expand Up @@ -84,13 +84,16 @@ async function walk(root: string, current: string, files: ScanFile[], excludePat
continue;
}

const fileStat = await stat(absolutePath);
if (fileStat.size > MAX_FILE_BYTES) {
continue;
const file = await open(absolutePath, "r");
try {
const fileStat = await file.stat();
if (fileStat.size <= MAX_FILE_BYTES) {
const content = await file.readFile("utf8");
files.push({ path: relativePath, content });
}
} finally {
await file.close();
}

const content = await readFile(absolutePath, "utf8");
files.push({ path: relativePath, content });
}
}

Expand Down