var interpolateConfigVars = function (str) { if (typeof str === 'string') { // Special str = str.replace(/%default_ip%/g, "0.0.0.0"); // OS variables str = str.replace(/%os\.endianness%/g, os.endianness()); str = str.replace(/%os\.hostname%/g, os.hostname()); str = str.replace(/%os\.tmpdir%/g, os.tmpdir()); str = str.replace(/%os\.type%/g, os.type()); str = str.replace(/%os\.platform%/g, os.platform()); str = str.replace(/%os\.arch%/g, os.arch()); str = str.replace(/%os\.release%/g, os.release()); str = str.replace(/%os\.uptime%/g, os.uptime()); str = str.replace(/%os\.loadavg%/g, os.loadavg().join(' ')); str = str.replace(/%os\.totalmem%/g, os.totalmem()); str = str.replace(/%os\.freemem%/g, os.freemem()); // Package variables str = str.replace(/%pkg\.name%/g, pkg.name); str = str.replace(/%pkg\.version%/g, pkg.version); } else if (typeof str === 'object') { for (var prop in str) { str[prop] = interpolateConfigVars(str[prop]); } } return str; };
.then(function() { if (log.metric()) { runtimeMetricInterval = setInterval(function() { reportMetrics(); }, settings.runtimeMetricInterval||15000); } console.log("\n\n"+log._("runtime.welcome")+"\n===================\n"); if (settings.version) { log.info(log._("runtime.version",{component:"Node-RED",version:"v"+settings.version})); } log.info(log._("runtime.version",{component:"Node.js ",version:process.version})); log.info(os.type()+" "+os.release()+" "+os.arch()+" "+os.endianness()); log.info(log._("server.loading")); return redNodes.load().then(function() { var i; var nodeErrors = redNodes.getNodeList(function(n) { return n.err!=null;}); var nodeMissing = redNodes.getNodeList(function(n) { return n.module && n.enabled && !n.loaded && !n.err;}); if (nodeErrors.length > 0) { log.warn("------------------------------------------------------"); for (i=0;i<nodeErrors.length;i+=1) { log.warn("["+nodeErrors[i].name+"] "+nodeErrors[i].err); } log.warn("------------------------------------------------------"); } if (nodeMissing.length > 0) { log.warn(log._("server.missing-modules")); var missingModules = {}; for (i=0;i<nodeMissing.length;i++) { var missing = nodeMissing[i]; missingModules[missing.module] = (missingModules[missing.module]||[]).concat(missing.types); } var promises = []; for (i in missingModules) { if (missingModules.hasOwnProperty(i)) { log.warn(" - "+i+": "+missingModules[i].join(", ")); if (settings.autoInstallModules && i != "node-red") { redNodes.installModule(i).otherwise(function(err) { // Error already reported. Need the otherwise handler // to stop the error propagating any further }); } } } if (!settings.autoInstallModules) { log.info(log._("server.removing-modules")); redNodes.cleanModuleList(); } } if (settings.settingsFile) { log.info(log._("runtime.paths.settings",{path:settings.settingsFile})); } redNodes.loadFlows().then(redNodes.startFlows); started = true; }).otherwise(function(err) { console.log(err); }); });
return Buffer.concat(buffers.map((typedArray) => { const buf = Buffer.from(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); if (os.endianness() === 'LE') { if (typedArray.BYTES_PER_ELEMENT === 2) buf.swap16(); if (typedArray.BYTES_PER_ELEMENT === 4) buf.swap32(); } return buf; }));
function getOS() { $scope.system = { arch: nodeos.arch(), // 处理器架构 endianness: nodeos.endianness(), // 字节顺序 高位优先返回BE,低位优先的返回LE freemen: nodeos.freemem(), // 空闲内存字节 totalmem: nodeos.totalmem(), // 系统总内存 platform: nodeos.platform(), // 操作系统类型 release: nodeos.release(), // 操作系统版本 type: nodeos.type(), // 操作系统名称 uptime: nodeos.uptime() // 计算机正常运行时间 }; }
E.info = function(){ var info = {type: os.type(), endianness: os.endianness(), hostname: os.hostname(), arch: os.arch()}; var m; if (info.type=='Linux') { info.issue = file.read_line('/etc/issue'); if (info.issue && (m = info.issue.match(/^Ubuntu ([0-9.]+) /))) info.ubuntu = m[1]; } return info; };
objects.getObject(id, function (err, oldObj) { var newObj = { _id: id, type: 'host', common: { name: id, // process: process.title, // actually not required, because there is type now title: ioPackage.common.title, installedVersion: version, platform: ioPackage.common.platform, cmd: process.argv[0] + ' ' + process.execArgv.join(' ') + ' ' + process.argv.slice(1).join(' '), hostname: hostname, address: ipArr, children: [ id + '.alive', id + '.load', id + '.mem' ], type: ioPackage.common.name }, native: { process: { title: process.title, pid: process.pid, versions: process.versions, env: process.env }, os: { hostname: hostname, type: os.type(), platform: os.platform(), arch: os.arch(), release: os.release(), uptime: os.uptime(), endianness: os.endianness(), tmpdir: os.tmpdir() }, hardware: { cpus: os.cpus(), totalmem: os.totalmem(), networkInterfaces: os.networkInterfaces() } } }; if (oldObj) { if (oldObj.common && oldObj.common.children) oldObj.common.children = []; if (oldObj.native && oldObj.native.hardware && oldObj.native.hardware.networkInterfaces) oldObj.native.hardware.networkInterfaces = []; newObj = require('node.extend')(true, oldObj, newObj); } objects.setObject(id, newObj); });
node.on("input", function(msg) { msg.payload = { hostname: os.hostname(), type: os.type(), platform: os.platform(), arch: os.arch(), release: os.release(), endianness: os.endianness(), tmpdir: os.tmpdir(), homedir: os.homedir() }; node.send(msg); });
// This is mostly accurate. Except write() won't write partial bytes to the // string while fill() blindly copies bytes into memory. To account for that an // error will be thrown if not all the data can be written, and the SIZE has // been massaged to work with the input characters. function writeToFill(string, offset, end, encoding) { if (typeof offset === 'string') { encoding = offset; offset = 0; end = buf2.length; } else if (typeof end === 'string') { encoding = end; end = buf2.length; } else if (end === undefined) { end = buf2.length; } if (offset < 0 || end > buf2.length) throw new RangeError('Out of range index'); if (end <= offset) return buf2; offset >>>= 0; end >>>= 0; assert(offset <= buf2.length); // Convert "end" to "length" (which write understands). var length = end - offset < 0 ? 0 : end - offset; var wasZero = false; do { var written = buf2.write(string, offset, length, encoding); offset += written; // Safety check in case write falls into infinite loop. if (written === 0) { if (wasZero) throw new Error('Could not write all data to Buffer'); else wasZero = true; } } while (offset < buf2.length); // Correction for UCS2 operations. if (os.endianness() === 'BE' && encoding === 'ucs2') { for (var i = 0; i < buf2.length; i += 2) { var tmp = buf2[i]; buf2[i] = buf2[i + 1]; buf2[i + 1] = tmp; } } return buf2; }
var createBitObject = module.exports = exports = function(bitmap) { var bitmapData = {}; var LE = function (offset) { return bitmap.readUInt32LE(offset); }; var BE = function (offset) { return bitmap.readUInt32BE(offset); }; // * Handle LE and BE computers with a single if statement bitmapData.headField = bitmap.toString('ascii', 0, 2); if (os.endianness() == 'LE') { bitmapData.size = LE(2); bitmapData.res1 = LE(6); bitmapData.res2 = LE(8); bitmapData.pixelArrayStart = LE(10); bitmapData.numberOfColor = LE(26); bitmapData.infoHeader = {}; bitmapData.infoHeader.biSize = LE(14); bitmapData.infoHeader.biWidth = LE(18); bitmapData.infoHeader.biHeight = LE(22); bitmapData.infoHeader.biPlanes = LE(26); bitmapData.infoHeader.biBitCount = LE(28); bitmapData.infoHeader.biCompression = LE(30); bitmapData.infoHeader.bitSizeImage = LE(34); bitmapData.infoHeader.biXPelsPerMeter = LE(38); bitmapData.infoHeader.biYPelsPerMeter = LE(42); bitmapData.infoHeader.biClrUsed = LE(46); bitmapData.infoHeader.biClrImportant = LE(50); } else { bitmapData.size = BE(2); bitmapData.res1 = BE(6); bitmapData.res2 = BE(8); bitmapData.pixelArrayStart = BE(10); bitmapData.numberOfColor = BE(26); bitmapData.infoHeader = {}; bitmapData.infoHeader.biSize = BE(14); bitmapData.infoHeader.biWidth = BE(18); bitmapData.infoHeader.biHeight = BE(22); bitmapData.infoHeader.biPlanes = BE(26); bitmapData.infoHeader.biBitCount = BE(28); bitmapData.infoHeader.biCompression = BE(30); bitmapData.infoHeader.bitSizeImage = BE(34); bitmapData.infoHeader.biXPelsPerMeter = BE(38); bitmapData.infoHeader.biYPelsPerMeter = BE(42); bitmapData.infoHeader.biClrUsed = BE(46); bitmapData.infoHeader.biClrImportant = BE(50); }; return bitmapData; };
var getHostId = function () { /* if still not present, initially determine id of host... */ if (hostid === null) { /* iterate over all network interfaces... */ var ifaces = os.networkInterfaces() var macs = {} Object.keys(ifaces).forEach(function (ifname) { /* skip some well-known virtual interfaces */ if (ifname.match(/^(?:lo|tun|tap)/i)) return /* iterate over all network sub-interfaces... */ ifaces[ifname].forEach(function (iface) { /* skip internal interfaces */ if (iface.internal) return /* remember IEEE MAC address */ if (iface.mac) macs[iface.mac] = true }) }) /* determine UUIDv5 payload */ var payload macs = Object.keys(macs) if (macs.length > 0) { /* strategy 1 (hardware): use (first) IEEE MAC address */ if (macs.length > 1) macs = macs.sort() payload = macs[0] } else { /* strategy 2 (software): use a host fingerprint */ payload = os.arch() + os.endianness() + os.platform() + os.hostname() } /* generate UUIDv5-based host id */ var uuid_ns = new UUID(5, "ns:URL", "urn:hostid") var uuid = new UUID(5, uuid_ns, payload) hostid = uuid.format() } return hostid }
function getSystemInfo(){ return { tmpdir: os.tmpdir(), endianness: os.endianness(), hostname: os.hostname(), type: os.type(), platform: os.platform(), arch: os.arch(), release: os.release(), uptime: os.uptime(), loadavg: os.loadavg(), totalmem: os.totalmem(), freemem: os.freemem(), cpus: os.cpus(), networkInterfaces: os.networkInterfaces(), EOL: os.EOL }; }
fullInfo.getRawInfo = function() { var info = {}; info.endianness = os.endianness(); info.hostname = os.hostname(); info.osname = os.type(); info.platform = os.platform(); info.architecture = os.arch(); info.release = os.release(); info.uptime = os.uptime(); info.loadaverage = os.loadavg(); info.totalmemory = os.totalmem(); info.freememory = os.freemem(); info.cpus = os.cpus(); info.network = os.networkInterfaces(); return info; }
app.get('/os', function (req, res, next) { var ret = { hostname: os.hostname(), platform: os.platform(), type: os.type(), loadAvg: os.loadavg(), totalMemory: os.totalmem() / 1024 / 1024 / 1024, freemem: os.freemem() / 1024 / 1024 / 1024, usageMem: ((os.totalmem() - os.freemem()) / 1024 / 1024 / 1024), cpus: os.cpus(), tmpdir: os.tmpdir(), networking: os.networkInterfaces(), uptime: os.uptime(), arch: os.arch(), release: os.release(), endianness: os.endianness(), status: 'ok' }; res.json(ret); });
function getWindowId(win) { var Long = require("long"); var os = require("os"); var handle = win.getNativeWindowHandle(); if (os.endianness() == "LE") { if (handle.length == 4) { handle.swap32(); } else if (handle.length == 8) { handle.swap64(); } else { console.log("Unknown Native Window Handle Format."); } } var longVal = Long.fromString(handle.toString('hex'), unsigned = true, radix = 16); return longVal.toString(); }
module.exports = exports = function readHeader(img) { const endianness = os.endianness(); const readFormat = { UInt8: 'readUInt8', UInt16: 'readUInt16' + endianness, UInt32: 'readUInt32' + endianness }; const bmpType = img.toString('ascii', 0, 2); console.log(bmpType); var header; if (bmpType === 'BM') { header = getBMHeaderInfo(img, readFormat); } else if (bmpType === 'BA') { header = getBAHeaderInfo(img, readFormat); } return header; };
exports.os = function(done) { try { var host = {}; host.arch = os.arch(); host.cpus = os.cpus(); host.endianness = os.endianness(); host.freemem = os.freemem(); // host.homedir = os.homedir(); host.hostname = os.hostname(); host.networkInterfaces = os.networkInterfaces(); host.platform = os.platform(); host.release = os.release(); host.tmpdir = os.tmpdir(); host.totalmem = os.totalmem(); host.type = os.type(); host.uptime = os.uptime(); // host.userInfo = os.userInfo(); done(null, host); } catch (e) { done(e); } };
handler: function (request, reply) { let json = { tmpdir: os.tmpdir(), endianness: os.endianness(), hostname: os.hostname(), type: os.type(), platform: os.platform(), arch: os.arch(), release: os.release(), uptime: os.uptime(), loadavg: os.loadavg(), totalmem: os.totalmem(), freemem: os.freemem(), cpus: os.cpus(), networkInterfaces: os.networkInterfaces(), eol: os.EOL } let readOptions = {encoding: 'utf8'} fs.readFile('/etc/hosts', readOptions, function(err, data) { if (err) { console.log(err) reply(JSON.stringify(err)) } json['hosts'] = data.split(os.EOL) fs.readFile('/etc/resolv.conf', readOptions, function(err, data) { if (err) { console.log(err) reply(JSON.stringify(err)) } json['resolv'] = data.split(os.EOL) reply(JSON.stringify(json)) }) }) }
function writeToFill(string, offset, end, encoding) { if (typeof offset === 'string') { encoding = offset; offset = 0; end = buf2.length; } else if (typeof end === 'string') { encoding = end; end = buf2.length; } else if (end === undefined) { end = buf2.length; } if (offset < 0 || end > buf2.length) throw new RangeError('Out of range index'); if (end <= offset) return buf2; offset >>>= 0; end >>>= 0; assert(offset <= buf2.length); var length = end - offset < 0 ? 0 : end - offset; var wasZero = false; do { var written = buf2.write(string, offset, length, encoding); offset += written; if (written === 0) { if (wasZero) throw new Error('Could not write all data to Buffer'); else wasZero = true; } } while (offset < buf2.length); if (os.endianness() === 'BE' && encoding === 'ucs2') { for (var i = 0; i < buf2.length; i += 2) { var tmp = buf2[i]; buf2[i] = buf2[i + 1]; buf2[i + 1] = tmp; } } return buf2; }
it('for static contents', function(done) { var OS = require('os'); var d = { os: { hostname: OS.hostname(), platform: OS.platform(), arch: OS.arch(), type: OS.type(), release: OS.release(), }, version: process.versions, process: { gid: process.getgid(), uid: process.getuid(), pid: process.pid, env: process.env, }, network: OS.networkInterfaces(), endianness: OS.endianness(), }; var p = 'Basic ' + new Buffer('pippo:ciao').toString('base64'); request.post('http://127.0.0.1:2999/sta/').set('Authorization', p) .set('Accept', 'application/json').end(function(err, res) { if (err) throw err; var j = JSON.parse(res.text); assert.equal(res.statusCode, 200, '200'); assert.deepEqual(j.os, d.os, 'os'); assert.deepEqual(j.version, d.version, 'version'); assert.deepEqual(j.process, d.process, 'process'); assert.deepEqual(j.process, d.process, 'process'); assert.deepEqual(j.endianness, d.endianness, 'endianness'); done(); }); });
, Cursor = require('./cursor') , AggregationCursor = require('./aggregation_cursor') , CommandCursor = require('./command_cursor') , Define = require('./metadata') , Server = require('./server') , Store = require('./topology_base').Store , MAX_JS_INT = require('./utils').MAX_JS_INT , translateOptions = require('./utils').translateOptions , filterOptions = require('./utils').filterOptions , mergeOptions = require('./utils').mergeOptions , getReadPreference = require('./utils').getReadPreference , os = require('os'); // Get package.json variable var driverVersion = require('../package.json').version; var nodejsversion = f('Node.js %s, %s', process.version, os.endianness()); var type = os.type(); var name = process.platform; var architecture = process.arch; var release = os.release(); /** * @fileOverview The **Mongos** class is a class that represents a Mongos Proxy topology and is * used to construct connections. * * **Mongos Should not be used, use MongoClient.connect** * @example * var Db = require('mongodb').Db, * Mongos = require('mongodb').Mongos, * Server = require('mongodb').Server, * test = require('assert');
'use strict'; var os = require('os'); console.log('os.-->>', os.EOL); console.log('os.-->>', os.arch()); console.log('os.-->>', os.constants); console.log('os.-->>\n', os.cpus()); console.log('os.-->>', os.endianness()); console.log('os.-->>', os.freemem()); console.log('os.-->>', os.homedir()); console.log('os.-->>', os.hostname()); console.log('os.-->>', os.loadavg()); console.log('os.-->>', os.networkInterfaces()); console.log('os.-->>', os.platform()); console.log('os.-->>', os.release()); console.log('os.-->>', os.tmpdir()); console.log('os.-->>', os.totalmem()); console.log('os.-->>', os.type()); console.log('os.-->>', os.uptime()); //console.log('os.-->>'+os.userInfo([options]));
var rates = require('sample-rate') var os = require('os') var isAudioBuffer = require('is-audio-buffer') var isBuffer = require('is-buffer') var isPlainObj = require('is-plain-obj') var pick = require('pick-by-alias') module.exports = { parse: parse, stringify: stringify, detect: detect, type: getType } var endianness = os.endianness instanceof Function ? os.endianness().toLowerCase() : 'le' var types = { 'uint': 'uint32', 'uint8': 'uint8', 'uint8_clamped': 'uint8', 'uint16': 'uint16', 'uint32': 'uint32', 'int': 'int32', 'int8': 'int8', 'int16': 'int16', 'int32': 'int32', 'float': 'float32', 'float32': 'float32', 'float64': 'float64', 'array': 'array',
testBufs('abc', 4, 'ucs2'); testBufs('abc', SIZE, 'ucs2'); testBufs('\u0222aa', 2, 'ucs2'); testBufs('\u0222aa', 8, 'ucs2'); testBufs('a\u0234b\u0235c\u0236', 4, 'ucs2'); testBufs('a\u0234b\u0235c\u0236', 12, 'ucs2'); testBufs('abc', 4, -1, 'ucs2'); testBufs('abc', 4, 1, 'ucs2'); testBufs('abc', 5, 1, 'ucs2'); testBufs('\u0222aa', 2, -1, 'ucs2'); testBufs('\u0222aa', 8, 1, 'ucs2'); testBufs('a\u0234b\u0235c\u0236', 4, -1, 'ucs2'); testBufs('a\u0234b\u0235c\u0236', 4, 1, 'ucs2'); testBufs('a\u0234b\u0235c\u0236', 12, 1, 'ucs2'); assert.equal(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0], os.endianness() === 'LE' ? 0x22 : 0x02); // HEX testBufs('616263', 'hex'); testBufs('c8a26161', 'hex'); testBufs('61c8b462c8b563c8b6', 'hex'); testBufs('616263', 4, 'hex'); testBufs('616263', 5, 'hex'); testBufs('616263', SIZE, 'hex'); testBufs('c8a26161', 2, 'hex'); testBufs('c8a26161', 8, 'hex'); testBufs('61c8b462c8b563c8b6', 4, 'hex'); testBufs('61c8b462c8b563c8b6', 12, 'hex'); testBufs('616263', 4, -1, 'hex'); testBufs('616263', 4, 1, 'hex');
/** * Created by bankeys-01 on 2016/7/28. */ var os =require("os"); //cpu的字节序 console.log("endianness :"+os.endianness()); //操作系统名 console.log("type :"+ os.type()); //操作系统名 console.log("platform :"+ os.platform()); //系统内存总量 console.log("total memory :"+os.totalmem()+"bytes."); //操作系统内空闲内存量 console.log("free memory :"+os.freemem()+"bytes.");
if (+process.env.TEST_PARALLEL) { throw new Error('common.PORT cannot be used in a parallelized test'); } return +process.env.NODE_COMMON_PORT || 12346; }, enumerable: true }); exports.isWindows = process.platform === 'win32'; exports.isWOW64 = exports.isWindows && (process.env.PROCESSOR_ARCHITEW6432 !== undefined); exports.isAIX = process.platform === 'aix'; exports.isLinuxPPCBE = (process.platform === 'linux') && (process.arch === 'ppc64') && (os.endianness() === 'BE'); exports.isSunOS = process.platform === 'sunos'; exports.isFreeBSD = process.platform === 'freebsd'; exports.isOpenBSD = process.platform === 'openbsd'; exports.isLinux = process.platform === 'linux'; exports.isOSX = process.platform === 'darwin'; exports.enoughTestMem = os.totalmem() > 0x70000000; /* 1.75 Gb */ const cpus = os.cpus(); exports.enoughTestCpu = Array.isArray(cpus) && (cpus.length > 1 || cpus[0].speed > 999); exports.rootDir = exports.isWindows ? 'c:\\' : '/'; exports.buildType = process.config.target_defaults.default_configuration;
/* Copyright 2015-present Facebook, Inc. * Licensed under the Apache License, Version 2.0 */ var EE = require('events').EventEmitter; var util = require('util'); var os = require('os'); var assert = require('assert'); var Int64 = require('node-int64'); // BSER uses the local endianness to reduce byte swapping overheads // (the protocol is expressly local IPC only). We need to tell node // to use the native endianness when reading various native values. var isBigEndian = os.endianness() == 'BE'; // Find the next power-of-2 >= size function nextPow2(size) { return Math.pow(2, Math.ceil(Math.log(size) / Math.LN2)); } // Expandable buffer that we can provide a size hint for function Accumulator(initsize) { this.buf = new Buffer(nextPow2(initsize || 8192)); this.readOffset = 0; this.writeOffset = 0; } // For testing exports.Accumulator = Accumulator // How much we can write into this buffer without allocating Accumulator.prototype.writeAvail = function() { return this.buf.length - this.writeOffset;
//file name: node_os_interface.js var os = require('os'); console.log("OS Temp Dir: " + os.tmpdir()); console.log("CPU is BigEndian(BE) or LittleEndian(LE): " + os.endianness()); console.log("OS Hostname: " + os.hostname()); console.log("OS Type: " + os.type()); console.log("OS Platform: " + os.platform()); console.log("OS CPU Architecture: " + os.arch()); console.log("OS Release: " + os.release()); console.log("OS Uptime (seconds): " + os.uptime()); console.log("OS load average (Returns 0,0,0 in windows): " + os.loadavg()); console.log("Total RAM (mb): " + (os.totalmem()/1024)/1024); console.log("Free RAM (mb): " + (os.freemem()/1024)/1024) var cpus = os.cpus(); console.log("CPU Information: " + JSON.stringify(cpus, null, 2)); console.log("Network Interfaces: " + JSON.stringify(os.networkInterfaces(), null, 2)); console.log("EOL Marker for OS: " + os.EOL);
/** * Module dependencies. */ var os = require('os'); var debug = require('debug')('speaker'); var binding = require('bindings')('binding'); var inherits = require('util').inherits; var Writable = require('stream').Writable; // determine the native host endianness, the only supported playback endianness var endianness = 'function' == os.endianness ? os.endianness() : 'LE'; // assume little-endian for older versions of node.js // node v0.8.x compat if (!Writable) Writable = require('readable-stream/writable'); /** * Module exports. */ exports = module.exports = Speaker; /** * Export information about the `mpg123_module_t` being used. */ exports.api_version = binding.api_version; exports.description = binding.description;
var download_file_httpget = function(file_url) { var readStream; var writeStream; var platform = os.platform(); var arch = os.arch(); var endian = os.endianness(); var installerfileURL; var fstream = require('fstream'); var unzip = require('unzip'); var IBM_DB_HOME, IBM_DB_INCLUDE, IBM_DB_LIB, IBM_DB_DIR; if(platform == 'win32') { if(arch == 'x64') { var BUILD_FILE = path.resolve(CURRENT_DIR, 'build.zip'); readStream = fs.createReadStream(BUILD_FILE); writeStream = fstream.Writer(CURRENT_DIR); readStream .pipe(unzip.Parse()) .pipe(writeStream).on("unpipe", function () { fs.unlinkSync(BUILD_FILE); var ODBC_BINDINGS = path.resolve(CURRENT_DIR, 'build\\Release\\odbc_bindings.node'); var ODBC_BINDINGS_V10 = path.resolve(CURRENT_DIR, 'build\\Release\\odbc_bindings.node.0.10.36'); var ODBC_BINDINGS_V12 = path.resolve(CURRENT_DIR, 'build\\Release\\odbc_bindings.node.0.12.7'); var ODBC_BINDINGS_V4 = path.resolve(CURRENT_DIR, 'build\\Release\\odbc_bindings.node.4.4.2'); fs.exists(ODBC_BINDINGS_V10, function() { if(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 0.12) { fs.renameSync(ODBC_BINDINGS_V10, ODBC_BINDINGS); fs.unlinkSync(ODBC_BINDINGS_V12); fs.unlinkSync(ODBC_BINDINGS_V4); } else if(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 4.0) { fs.renameSync(ODBC_BINDINGS_V12, ODBC_BINDINGS); fs.unlinkSync(ODBC_BINDINGS_V10); fs.unlinkSync(ODBC_BINDINGS_V4); } else if(Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 5.0) { fs.renameSync(ODBC_BINDINGS_V4, ODBC_BINDINGS); fs.unlinkSync(ODBC_BINDINGS_V10); fs.unlinkSync(ODBC_BINDINGS_V12); } else { fs.unlinkSync(ODBC_BINDINGS_V10); fs.unlinkSync(ODBC_BINDINGS_V12); fs.unlinkSync(ODBC_BINDINGS_V4); } }); }); } else { console.log('Windows 32 bit not supported. Please use an ' + 'x64 architecture.'); return; } } if(process.env.IBM_DB_HOME) { IBM_DB_HOME = process.env.IBM_DB_HOME; IBM_DB_INCLUDE = path.resolve(IBM_DB_HOME, 'include'); IBM_DB_LIB = path.resolve(IBM_DB_HOME, 'lib'); console.log('IBM_DB_HOME environment variable have already been set to '+IBM_DB_HOME); if (!fs.existsSync(IBM_DB_HOME)) { console.log('Environment variable IBM_DB_HOME is not set to the correct directory. Please check if you have set the IBM_DB_HOME environment variable\'s value correctly.'); } if (!fs.existsSync(IBM_DB_INCLUDE)) { console.log('Environment variable IBM_DB_HOME is not set to the correct directory. Please check if you have set the IBM_DB_HOME environment variable\'s value correctly.'); } if (!fs.existsSync(IBM_DB_LIB)) { console.log('Environment variable IBM_DB_HOME is not set to the correct directory. Please check if you have set the IBM_DB_HOME environment variable\'s value correctly.'); } if( platform != 'win32') { if((platform == 'linux') || (platform =='aix') || (platform == 'darwin' && arch == 'x64')) { removeWinBuildArchive(); buildBinary(false); } else { console.log('Building binaries for node-ibm_db. This platform is not completely supported, you might encounter errors. In such cases please open an issue on our repository, https://github.com/ibmdb/node-ibm_db.'); buildBinary(false); } } } else { if(platform == 'win32') { if(arch == 'x64') { installerfileURL = installerURL + 'ntx64_odbc_cli.zip'; }/* else { installerfileURL = installerURL + 'nt32_odbc_cli.zip'; }*/ } else if(platform == 'linux') { if(arch == 'x64') { installerfileURL = installerURL + 'linuxx64_odbc_cli.tar.gz'; } else if(arch == 's390x') { installerfileURL = installerURL + 's390x64_odbc_cli.tar.gz'; } else if(arch == 's390') { installerfileURL = installerURL + 's390_odbc_cli.tar.gz'; } else if(arch == 'ppc64') { if(endian == 'LE') installerfileURL = installerURL + 'ppc64le_odbc_cli.tar.gz'; else installerfileURL = installerURL + 'ppc64_odbc_cli.tar.gz'; } else if(arch == 'ppc32') { installerfileURL = installerURL + 'ppc32_odbc_cli.tar.gz'; } else { installerfileURL = installerURL + 'linuxia32_odbc_cli.tar.gz'; } } else if(platform == 'darwin') { if(arch == 'x64') { installerfileURL = installerURL + 'macos64_odbc_cli.tar.gz'; } else { console.log('Mac OS 32 bit not supported. Please use an ' + 'x64 architecture.'); return; } } else if(platform == 'aix') { if(arch == 'ppc') { installerfileURL = installerURL + 'aix32_odbc_cli.tar.gz'; } else { installerfileURL = installerURL + 'aix64_odbc_cli.tar.gz'; } } else { installerfileURL = installerURL + platform + arch + '_odbc_cli.tar.gz'; } if(!installerfileURL) { console.log('Unable to fetch driver download file. Exiting the ' + 'install process.'); process.exit(1); } /* var options = { host: url.parse(installerfileURL).host, port: 80, path: url.parse(installerfileURL).pathname }; */ var license_agreement = '\n****************************************\nYou are downloading a package which includes the Node.js module for IBM DB2/Informix. The module is licensed under the Apache License 2.0. The package also includes IBM ODBC and CLI Driver from IBM, which is automatically downloaded as the node module is installed on your system/device. The license agreement to the IBM ODBC and CLI Driver is available in '+DOWNLOAD_DIR+' Check for additional dependencies, which may come with their own license agreement(s). Your use of the components of the package and dependencies constitutes your acceptance of their respective license agreements. If you do not accept the terms of any license agreement(s), then delete the relevant component(s) from your device.\n****************************************\n'; var file_name = url.parse(installerfileURL).pathname.split('/').pop(); INSTALLER_FILE = path.resolve(DOWNLOAD_DIR, file_name); console.log('Downloading DB2 ODBC CLI Driver from ' + installerfileURL+'...'); buildHttpOptions(installerfileURL); } // * END OF EXECUTION */ var downloadCLIDriver = function(res) { if( res.statusCode != 200 ) { console.log( "Unable to download IBM ODBC and CLI Driver from " + installerfileURL ); process.exit(1); } //var file = fs.createWriteStream(INSTALLER_FILE); var fileLength = parseInt( res.headers['content-length'] ); var buf = new Buffer( fileLength ); var byteIndex = 0; res.on('data', function(data) { if( byteIndex + data.length > buf.length ) { console.log( "Error downloading IBM ODBC and CLI Driver from " + installerfileURL ); process.exit(1); } data.copy( buf, byteIndex ); byteIndex += data.length; }).on('end', function() { if( byteIndex != buf.length ) { console.log( "Error downloading IBM ODBC and CLI Driver from " + installerfileURL ); process.exit(1); } var file = fs.openSync( INSTALLER_FILE, 'w'); var len = fs.writeSync( file, buf, 0, buf.length, 0 ); if( len != buf.length ) { console.log( "Error writing IBM ODBC and CLI Driver to a file" ); process.exit(1); } fs.closeSync( file ); if(platform == 'win32') { readStream = fs.createReadStream(INSTALLER_FILE); writeStream = fstream.Writer(DOWNLOAD_DIR); readStream.pipe(unzip.Parse()).pipe(writeStream); console.log('Download and extraction of DB2 ODBC ' + 'CLI Driver completed successfully ...'); console.log(license_agreement); } //CLI Driver file for all platforms other than windows //is a tar.gz file else /*if(platform == 'linux' ||(platform =='darwin' &&arch=='x64'))*/ { var targz = require('tar.gz'); var compress = new targz().extract(INSTALLER_FILE, DOWNLOAD_DIR, function(err){ if(err) { console.log(err); process.exit(1); } console.log('Download and extraction of DB2 ODBC ' + 'CLI Driver completed successfully ...'); console.log(license_agreement); IBM_DB_HOME = path.resolve(DOWNLOAD_DIR, 'clidriver'); process.env.IBM_DB_HOME = IBM_DB_HOME; buildBinary(true); removeWinBuildArchive(); }); } }); } // downloadCLIDriver function buildBinary(isDownloaded) { var buildString = "node-gyp configure build --IBM_DB_HOME=$IBM_DB_HOME"; if(isDownloaded) { buildString = buildString + " --IS_DOWNLOADED=true"; } else { buildString = buildString + " --IS_DOWNLOADED=false"; } if( platform == 'win32') { buildString = buildString + " --IBM_DB_HOME_WIN=%IBM_DB_HOME%"; } var childProcess = exec(buildString, function (error, stdout, stderr) { console.log(stdout); if (error !== null) { console.log(error); process.exit(1); } if(platform == 'darwin' && arch == 'x64') { // Run the install_name_tool var nameToolCommand = "install_name_tool -change libdb2.dylib $IBM_DB_HOME/lib/libdb2.dylib ./build/Release/odbc_bindings.node" var nameToolCmdProcess = exec(nameToolCommand , function (error1, stdout1, stderr1) { if (error1 !== null) { console.log('Error setting up the lib path to ' + 'odbc_bindings.node file.Error trace:\n'+error1); process.exit(1); } }); console.log(license_agreement); } }); } //buildBinary function removeWinBuildArchive() { var WIN_BUILD_FILE = path.resolve(CURRENT_DIR, 'build.zip'); fs.exists(WIN_BUILD_FILE, function(exists) { if (exists) { fs.unlinkSync(WIN_BUILD_FILE); } }); } function buildHttpOptions(installerfileURL) { var options = { host: url.parse(installerfileURL).host, port: 80, path: url.parse(installerfileURL).pathname }; var proxyStr; var child = exec('npm config get proxy', function(error, stdout, stderr) { if (error !== null) { console.log('Error occurred while fetching proxy ' + 'property from npm configuration -->\n' + error); return http.get(options, downloadCLIDriver); } proxyStr = stdout.toString().split('\n')[0]; if(proxyStr === 'null') { //console.log('Null Returned'); child = exec('npm config get https-proxy', function(error, stdout, stderr) { //console.log('stderr: ' + stderr); if (error !== null) { console.log('Error occurred while fetching https-proxy'+ ' property from npm configuration -->\n' + error); return http.get(options, downloadCLIDriver); } proxyStr = stdout.toString().split('\n')[0]; if(proxyStr !== 'null') { var splitIndex = proxyStr.toString().lastIndexOf(':'); if(splitIndex > 0) { var proxyUrl = url.parse(proxyStr.toString()); options = { host: proxyUrl.hostname, port: proxyUrl.port, path: url.parse(installerfileURL).href, headers: { Host: url.parse(installerfileURL).hostname } }; if (proxyUrl.auth) { options.headers = { 'Proxy-Authorization': 'Basic ' + new Buffer(proxyUrl.auth).toString('base64') }; } } } console.log('Downloading driver:'); console.log(JSON.stringify(options)); return http.get(options, downloadCLIDriver); }); } else { var splitIndex = proxyStr.toString().lastIndexOf(':'); if(splitIndex > 0) { var proxyUrl = url.parse(proxyStr.toString()); options = { host: proxyUrl.hostname, port: proxyUrl.port, path: url.parse(installerfileURL).href, headers: { Host: url.parse(installerfileURL).hostname } }; if (proxyUrl.auth) { options.headers = { 'Proxy-Authorization': 'Basic ' + new Buffer(proxyUrl.auth).toString('base64') }; } } return http.get(options, downloadCLIDriver); } }); } //buildHttpOptions }; //download_file_httpget
it('endianness', () => { const endianness = os.endianness(); assert.isString(endianness); assert(/[BL]E/.test(endianness)); });