plist.js 540 B

123456789101112131415161718192021
  1. const fs = require('fs')
  2. const plist = require('plist')
  3. const bplist = require('bplist-parser')
  4. function parseBuffer (buffer) {
  5. // Binary plists have the marker 'bplist0'
  6. if (buffer.slice(0, 7).toString('ascii') === 'bplist0') {
  7. // Parse as binary plist
  8. data = bplist.parseBuffer(buffer)[0]
  9. } else {
  10. // Parse as normal plist
  11. data = plist.parse(buffer.toString('utf8'))
  12. }
  13. return data
  14. }
  15. function parseFile (filePath) {
  16. return parseBuffer(fs.readFileSync(filePath))
  17. }
  18. module.exports = { parseBuffer, parseFile }