DevTrends开发者趋势
主题色

pompelmi /

pompelmi

工具简介 pompelmi 是一个极简的 Node.js 开源库(ISC 协议),对 ClamAV 进行了封装。 调用 scan() 扫描任意文件,返回一个类型化的 Symbol 结果: Verdict.Clean、Verdict.Malicious 或 Verdict.ScanError。 无需守护进程,无需云服务,无需原生绑定,零运行时依赖。 工作原理 1. 验证 — 检查参数是否为字符串,文件是否存在 2. 扫描 — 以子进程方式…

DT数据与运维DT安全与测试DT命令行工具DT库 / SDKDTLinuxDTmacOSDT终端

关于

工具简介 pompelmi 是一个极简的 Node.js 开源库(ISC 协议),对 ClamAV 进行了封装。 调用 scan() 扫描任意文件,返回一个类型化的 Symbol 结果: Verdict.Clean、Verdict.Malicious 或 Verdict.ScanError。 无需守护进程,无需云服务,无需原生绑定,零运行时依赖。 工作原理 1. 验证 — 检查参数是否为字符串,文件是否存在 2. 扫描 — 以子进程方式执行 clamscan --no-summary <filePath>,读取退出码 3. 映射 — 将退出码直接映射为结果 Symbol 不解析 stdout,不用正则,没有意外。 基本用法 js const { scan, Verdict } = require('pompelmi'); const result = await scan('/path/to/upload.zip'); if (result === Verdict.Malicious) { throw new Error('文件被拒绝:检测到恶意软件'); } 扫描结果说明 | 结果 | ClamAV 退出码 | 含义 | |---|:---:|---| | Verdict.Clean | 0 | 未发现威胁 | | Verdict.Malicious | 1 | 匹配到已知病毒或恶意软件签名 | | Verdict.ScanError | 2 | 扫描失败(I/O 错误、加密压缩包等),状态未知,建议视为不可信 | 每个 Verdict Symbol 都有 .description 属性,方便日志输出: js console.log(Verdict.Clean.description); // => 'Clean' 错误处理示例 js const { scan, Verdict } = require('pompelmi'); const path = require('path'); async function safeScan(filePath) { try { const result = await scan(path.resolve(filePath)); if (result === Verdict.ScanError) { console.warn('扫描未完成,作为预防措施拒绝该文件。'); return null; } return result; // Verdict.Clean 或 Verdict.Malicious } catch (err) { console.error('扫描失败:', err.message); return null; } } Docker / 远程扫描 如果 ClamAV 运行在 Docker 容器或远程服务器上,只需传入 host 和 port,其他不变: js const result = await pompelmi.scan('/path/to/upload.zip', { host: '127.0.0.1', port: 3310, }); 支持平台 | 系统 | ClamAV 安装命令 | |---|---| | macOS | brew install clamav && freshclam | | Linux | sudo apt-get install -y clamav clamav-daemon && sudo freshclam | | Windows | choco install clamav -y | 项目信息

收录记录

  1. Show HN

    2025年9月6日 – 2026年2月10日 · 3 次收录

  2. 阮一峰周刊·用户投稿

    2026年4月26日 · 1 次收录

讨论这个产品