const fs = require("fs") , util = require("util") , EventEmitter = require("events").EventEmitter , {eviocgrab, eviocgid} = require("bindings")("ioctl.node") , events = require("./events"); const arch = (process.arch.indexOf("64")>=0)?64:32; function Device(path) { this.grabbed = false; if (path) this.open(path); } util.inherits(Device, EventEmitter); Device.prototype.open = function(path) { this.stream = fs .createReadStream(path, {flags: "r", autoClose: true}) .on("error", e => this.emit("error", e)) .on("open", fd => { this.fd = fd; try { this.id = eviocgid(fd); } catch(e) { this.emit("error", new Error("Reader eviocgid error:"+e)); } if (this.grabbed) eviocgrab(this.fd, 1); this.emit("open", fd); }) .on("data", buf => { var i, j, chunk = (arch===64)?24:16; for (i=0, j=buf.length; i