修改ai文件

80 阅读1分钟
const fs = require('fs');
const readline = require('readline');

module.exports = function (filePath) {
  try {
    return new Promise(resolve => {
      // 创建逐行读取的接口
      const rl = readline.createInterface({
        input: fs.createReadStream(filePath),
        output: process.stdout,
        terminal: false
      });
  
      let fontNameList = [];
      // 逐行读取文件内容并处理
      rl.on('line', (line) => {
        // 判断是否包含 <stFnt:fontName> 标签
        if (line.includes('<stFnt:fontName>')) {
          // 提取标签中的内容
          const fontName = line.replace(/<\/?stFnt:fontName>/g, '').trim();
          fontNameList.push(fontName);
        }
      });
  
      // 处理读取完成事件
      rl.on('close', () => {
        console.log('文件读取完成');
        resolve(fontNameList);
      });
    })
  } catch(e) {
    return false
  }
}