codesnap-analyzer
Version:
Create comprehensive snapshots of your codebase with token counting for LLMs
33 lines (32 loc) • 1.13 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileUtils = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
class FileUtils {
static async isTextFile(filePath) {
try {
const buffer = await fs_extra_1.default.readFile(filePath);
const sample = buffer.slice(0, 1024);
for (const byte of sample) {
if (byte === 0 || (byte < 32 && ![9, 10, 13].includes(byte))) {
return false;
}
}
return true;
}
catch (error) {
console.error(`Error checking if file is text: ${error}`);
return false;
}
}
static async readFileContent(filePath) {
return fs_extra_1.default.readFile(filePath, "utf-8");
}
static async writeOutput(filePath, content) {
await fs_extra_1.default.writeFile(filePath, content, "utf-8");
}
}
exports.FileUtils = FileUtils;
;