ntfstool
Version:
A tool package for ntfs file system
72 lines (67 loc) • 2.38 kB
JavaScript
/**
* @author service@ntfstool.com
* Copyright (c) 2020 ntfstool.com
* Copyright (c) 2020 alfw.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the MIT General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MIT General Public License for more details.
*
* You should have received a copy of the MIT General Public License
* along with this program (in the main directory of the NTFS Tool
* distribution in the file COPYING); if not, write to the service@ntfstool.com
*/
var exec = require('child_process').exec;
var plist = require('plist');
const path = require("path")
if (process.platform === "darwin") {
exports.ntfstool_bin = path.join(__dirname, "mac", "ntfs-tool").replace('app.asar', 'app.asar.unpacked').replace(/(\s+)/g, '\\$1')
exports.fuse_pkg = path.join(__dirname, "mac", "osxfuse.dmg").replace('app.asar', 'app.asar.unpacked');
} else {
exports.ntfstool_bin = "Not currently supported"
exports.fuse_pkg = "Not currently supported"
}
/**
* get the system info
* @param opts
* @param cb
*/
exports.getAspInfo = function (opts, cb) {
var dataTypes = [];
if (opts && Array.isArray(opts.dataTypes)) {
dataTypes = opts.dataTypes
}
exec('/usr/sbin/system_profiler -xml ' + dataTypes.join(' '), function (err, stdout) {
if (err) throw err;
parse_system_profiler(stdout, (err, out) => {
if (err) {
cb(err, out);
return;
}
var ret_obj = {};
for(var i in out){
if(typeof out[i].name != "undefined" && out[i].name){
ret_obj[out[i].name] = {...out[i].items};
}
}
cb(null, ret_obj);
})
});
}
function parse_system_profiler(buf, sub_cb) {
var data = plist.parse(buf.toString());
var out = data.reduce(function (acc, sec) {
return acc.concat({
name: sec._dataType,
items: sec._items[0]
});
}, []);
sub_cb(null, out);
}