@ -21,31 +21,50 @@
'use strict' ;
'use strict' ;
const binding = process . binding ( 'os' ) ;
const getCPUs = binding . getCPUs ;
const getLoadAvg = binding . getLoadAvg ;
const pushValToArrayMax = process . binding ( 'util' ) . pushValToArrayMax ;
const pushValToArrayMax = process . binding ( 'util' ) . pushValToArrayMax ;
const constants = process . binding ( 'constants' ) . os ;
const constants = process . binding ( 'constants' ) . os ;
const internalUtil = require ( 'internal/util' ) ;
const deprecate = require ( 'internal/util' ) . deprecate ;
const isWindows = process . platform === 'win32' ;
const isWindows = process . platform === 'win32' ;
exports . hostname = binding . getHostname ;
const {
exports . uptime = binding . getUptime ;
getCPUs ,
exports . freemem = binding . getFreeMem ;
getFreeMem ,
exports . totalmem = binding . getTotalMem ;
getHomeDirectory ,
exports . type = binding . getOSType ;
getHostname ,
exports . release = binding . getOSRelease ;
getInterfaceAddresses ,
exports . networkInterfaces = binding . getInterfaceAddresses ;
getLoadAvg ,
exports . homedir = binding . getHomeDirectory ;
getOSRelease ,
exports . userInfo = binding . getUserInfo ;
getOSType ,
getTotalMem ,
getUserInfo ,
getUptime ,
isBigEndian
} = process . binding ( 'os' ) ;
getFreeMem [ Symbol . toPrimitive ] = ( ) => getFreeMem ( ) ;
getHostname [ Symbol . toPrimitive ] = ( ) => getHostname ( ) ;
getHomeDirectory [ Symbol . toPrimitive ] = ( ) => getHomeDirectory ( ) ;
getOSRelease [ Symbol . toPrimitive ] = ( ) => getOSRelease ( ) ;
getOSType [ Symbol . toPrimitive ] = ( ) => getOSType ( ) ;
getTotalMem [ Symbol . toPrimitive ] = ( ) => getTotalMem ( ) ;
getUptime [ Symbol . toPrimitive ] = ( ) => getUptime ( ) ;
const kEndianness = isBigEndian ? 'BE' : 'LE' ;
const tmpDirDeprecationMsg =
'os.tmpDir() is deprecated. Use os.tmpdir() instead.' ;
const getNetworkInterfacesDepMsg =
'os.getNetworkInterfaces is deprecated. Use os.networkInterfaces instead.' ;
const avgValues = new Float64Array ( 3 ) ;
const avgValues = new Float64Array ( 3 ) ;
exports . loadavg = function loadavg ( ) {
const cpuValues = new Float64Array ( 6 * pushValToArrayMax ) ;
function loadavg ( ) {
getLoadAvg ( avgValues ) ;
getLoadAvg ( avgValues ) ;
return [ avgValues [ 0 ] , avgValues [ 1 ] , avgValues [ 2 ] ] ;
return [ avgValues [ 0 ] , avgValues [ 1 ] , avgValues [ 2 ] ] ;
} ;
}
const cpuValues = new Float64Array ( 6 * pushValToArrayMax ) ;
function addCPUInfo ( ) {
function addCPUInfo ( ) {
for ( var i = 0 , c = 0 ; i < arguments . length ; ++ i , c += 6 ) {
for ( var i = 0 , c = 0 ; i < arguments . length ; ++ i , c += 6 ) {
this [ this . length ] = {
this [ this . length ] = {
@ -61,25 +80,22 @@ function addCPUInfo() {
} ;
} ;
}
}
}
}
exports . cpus = function cpus ( ) {
return getCPUs ( addCPUInfo , cpuValues , [ ] ) ;
} ;
Object . defineProperty ( exports , 'constants' , {
function cpus ( ) {
configurable : false ,
return getCPUs ( addCPUInfo , cpuValues , [ ] ) ;
enumerable : true ,
}
value : constants
} ) ;
exports . arch = function ( ) {
function arch ( ) {
return process . arch ;
return process . arch ;
} ;
}
arch [ Symbol . toPrimitive ] = ( ) => process . arch ;
exports . platform = function ( ) {
function platform ( ) {
return process . platform ;
return process . platform ;
} ;
}
platform [ Symbol . toPrimitive ] = ( ) => process . platform ;
exports . tmpdir = function ( ) {
function tmpdir ( ) {
var path ;
var path ;
if ( isWindows ) {
if ( isWindows ) {
path = process . env . TEMP ||
path = process . env . TEMP ||
@ -97,22 +113,41 @@ exports.tmpdir = function() {
}
}
return path ;
return path ;
} ;
}
tmpdir [ Symbol . toPrimitive ] = ( ) => tmpdir ( ) ;
const tmpDirDeprecationMsg =
function endianness ( ) {
'os.tmpDir() is deprecated. Use os.tmpdir() instead.' ;
return kEndianness ;
exports . tmpDir = internalUtil . deprecate ( exports . tmpdir ,
}
tmpDirDeprecationMsg ,
endianness [ Symbol . toPrimitive ] = ( ) => kEndianness ;
'DEP0022' ) ;
exports . getNetworkInterfaces = internalUtil . deprecate ( function ( ) {
module . exports = exports = {
return exports . networkInterfaces ( ) ;
arch ,
} , 'os.getNetworkInterfaces is deprecated. ' +
cpus ,
'Use os.networkInterfaces instead.' , 'DEP0023' ) ;
EOL : isWindows ? '\r\n' : '\n' ,
endianness ,
freemem : getFreeMem ,
homedir : getHomeDirectory ,
hostname : getHostname ,
loadavg ,
networkInterfaces : getInterfaceAddresses ,
platform ,
release : getOSRelease ,
tmpdir ,
totalmem : getTotalMem ,
type : getOSType ,
userInfo : getUserInfo ,
uptime : getUptime ,
exports . EOL = isWindows ? '\r\n' : '\n' ;
// Deprecated APIs
getNetworkInterfaces : deprecate ( getInterfaceAddresses ,
getNetworkInterfacesDepMsg ,
'DEP0023' ) ,
tmpDir : deprecate ( tmpdir , tmpDirDeprecationMsg , 'DEP0022' )
} ;
if ( binding . isBigEndian )
Object . defineProperty ( module . exports , 'constants' , {
exports . endianness = function ( ) { return 'BE' ; } ;
configurable : false ,
else
enumerable : true ,
exports . endianness = function ( ) { return 'LE' ; } ;
value : constants
} ) ;