Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Soft migration of sys -> util, Removal of deprecated utils module.
Browse files Browse the repository at this point in the history
  • Loading branch information
miksago authored and ry committed Oct 11, 2010
1 parent 0a0e90d commit e38eb0c
Show file tree
Hide file tree
Showing 55 changed files with 543 additions and 541 deletions.
4 changes: 2 additions & 2 deletions benchmark/io.js
@@ -1,5 +1,5 @@
var fs = require('fs');
var sys = require('sys');
var util = require('util');
var Buffer = require('buffer').Buffer;

var path = "/tmp/wt.dat";
Expand Down Expand Up @@ -43,7 +43,7 @@ function writetest(size, bsize) {

s.on('drain', function () {
dowrite();
if (c++ % 2000 == 0) sys.print(".");
if (c++ % 2000 == 0) util.print(".");
});

dowrite();
Expand Down
4 changes: 2 additions & 2 deletions benchmark/process_loop.js
@@ -1,4 +1,4 @@
var sys = require("sys"),
var util = require("util"),
childProcess = require("child_process");

function next (i) {
Expand All @@ -7,7 +7,7 @@ function next (i) {
var child = childProcess.spawn("echo", ["hello"]);

child.stdout.addListener("data", function (chunk) {
sys.print(chunk);
util.print(chunk);
});

child.addListener("exit", function (code) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/run.js
@@ -1,5 +1,5 @@
var path = require("path");
var sys = require("sys");
var util = require("util");
var childProcess = require("child_process");
var benchmarks = [ "timers.js"
, "process_loop.js"
Expand All @@ -19,7 +19,7 @@ function exec (script, callback) {

function runNext (i) {
if (i >= benchmarks.length) return;
sys.print(benchmarks[i] + ": ");
util.print(benchmarks[i] + ": ");
exec(benchmarks[i], function (elapsed, code) {
if (code != 0) {
console.log("ERROR ");
Expand Down
66 changes: 33 additions & 33 deletions doc/api.markdown
Expand Up @@ -34,7 +34,7 @@ variable with the same name as the module.

Example:

var sys = require('sys');
var util = require('util');

It is possible to extend node with other modules. See `'Modules'`

Expand Down Expand Up @@ -271,7 +271,7 @@ manipulated, e.g. to remove listeners.
server.on('stream', function (stream) {
console.log('someone connected!');
});
console.log(sys.inspect(server.listeners('stream'));
console.log(util.inspect(server.listeners('stream'));
// [ [Function] ]


Expand Down Expand Up @@ -766,9 +766,9 @@ What platform you're running on. `'linux2'`, `'darwin'`, etc.

Returns an object describing the memory usage of the Node process.

var sys = require('sys');
var util = require('util');

console.log(sys.inspect(process.memoryUsage()));
console.log(util.inspect(process.memoryUsage()));

This will generate:

Expand Down Expand Up @@ -806,35 +806,35 @@ given, otherwise returns the current mask.



## sys
## util

These functions are in the module `'sys'`. Use `require('sys')` to access
These functions are in the module `'util'`. Use `require('util')` to access
them.


### sys.print(string)
### util.print(string)

Like `console.log()` but without the trailing newline.

require('sys').print('String with no newline');
require('util').print('String with no newline');


### sys.debug(string)
### util.debug(string)

A synchronous output function. Will block the process and
output `string` immediately to `stderr`.

require('sys').debug('message on stderr');
require('util').debug('message on stderr');


### sys.log(string)
### util.log(string)

Output with timestamp on `stdout`.

require('sys').log('Timestmaped message.');
require('util').log('Timestmaped message.');


### sys.inspect(object, showHidden=false, depth=2)
### util.inspect(object, showHidden=false, depth=2)

Return a string representation of `object`, which is useful for debugging.

Expand All @@ -847,14 +847,14 @@ formatting the object. This is useful for inspecting large complicated objects.
The default is to only recurse twice. To make it recurse indefinitely, pass
in `null` for `depth`.

Example of inspecting all properties of the `sys` object:
Example of inspecting all properties of the `util` object:

var sys = require('sys');
var util = require('util');

console.log(sys.inspect(sys, true, null));
console.log(util.inspect(util, true, null));


### sys.pump(readableStream, writeableStream, [callback])
### util.pump(readableStream, writeableStream, [callback])

Experimental

Expand Down Expand Up @@ -962,16 +962,16 @@ existing streams; `-1` means that a new stream should be created.

Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit code:

var sys = require('sys'),
var util = require('util'),
spawn = require('child_process').spawn,
ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', function (data) {
sys.print('stdout: ' + data);
util.print('stdout: ' + data);
});

ls.stderr.on('data', function (data) {
sys.print('stderr: ' + data);
util.print('stderr: ' + data);
});

ls.on('exit', function (code) {
Expand All @@ -981,7 +981,7 @@ Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the exit cod

Example: A very elaborate way to run 'ps ax | grep ssh'

var sys = require('sys'),
var util = require('util'),
spawn = require('child_process').spawn,
ps = spawn('ps', ['ax']),
grep = spawn('grep', ['ssh']);
Expand All @@ -991,7 +991,7 @@ Example: A very elaborate way to run 'ps ax | grep ssh'
});

ps.stderr.on('data', function (data) {
sys.print('ps stderr: ' + data);
util.print('ps stderr: ' + data);
});

ps.on('exit', function (code) {
Expand All @@ -1002,11 +1002,11 @@ Example: A very elaborate way to run 'ps ax | grep ssh'
});

grep.stdout.on('data', function (data) {
sys.print(data);
util.print(data);
});

grep.stderr.on('data', function (data) {
sys.print('grep stderr: ' + data);
util.print('grep stderr: ' + data);
});

grep.on('exit', function (code) {
Expand Down Expand Up @@ -1035,14 +1035,14 @@ See also: `child_process.exec()`
High-level way to execute a command as a child process, buffer the
output, and return it all in a callback.

var sys = require('sys'),
var util = require('util'),
exec = require('child_process').exec,
child;

child = exec('cat *.js bad_file | wc -l',
function (error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
util.print('stdout: ' + stdout);
util.print('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
Expand Down Expand Up @@ -1140,7 +1140,7 @@ the object `sandbox` will be used as the global object for `code`.
Example: compile and execute code that increments a global variable and sets a new one.
These globals are contained in the sandbox.

var sys = require('sys'),
var util = require('util'),
Script = process.binding('evals').Script,
sandbox = {
animal: 'cat',
Expand All @@ -1149,7 +1149,7 @@ These globals are contained in the sandbox.

Script.runInNewContext(
'count += 1; name = "kitty"', sandbox, 'myfile.js');
console.log(sys.inspect(sandbox));
console.log(util.inspect(sandbox));

// { animal: 'cat', count: 3, name: 'kitty' }

Expand Down Expand Up @@ -1207,7 +1207,7 @@ Running code does not have access to local scope. `sandbox` is optional.
Example: compile code that increments a global variable and sets one, then execute this code multiple times.
These globals are contained in the sandbox.

var sys = require('sys'),
var util = require('util'),
Script = process.binding('evals').Script,
scriptObj, i,
sandbox = {
Expand All @@ -1222,7 +1222,7 @@ These globals are contained in the sandbox.
scriptObj.runInNewContext(sandbox);
}

console.log(sys.inspect(sandbox));
console.log(util.inspect(sandbox));

// { animal: 'cat', count: 12, name: 'kitty' }

Expand Down Expand Up @@ -2963,7 +2963,7 @@ the first character, then it returns an empty string. Examples:
Test whether or not the given path exists. Then, call the `callback` argument with either true or false. Example:

path.exists('/etc/passwd', function (exists) {
sys.debug(exists ? "it's there" : "no passwd!");
util.debug(exists ? "it's there" : "no passwd!");
});


Expand Down Expand Up @@ -3214,7 +3214,7 @@ The module `circle.js` has exported the functions `area()` and
`circumference()`. To export an object, add to the special `exports`
object. (Alternatively, one can use `this` instead of `exports`.) Variables
local to the module will be private. In this example the variable `PI` is
private to `circle.js`. The function `puts()` comes from the module `'sys'`,
private to `circle.js`. The function `puts()` comes from the module `'util'`,
which is a built-in module. Modules which are not prefixed by `'./'` are
built-in module--more about this later.

Expand Down
4 changes: 2 additions & 2 deletions lib/assert.js
Expand Up @@ -23,7 +23,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// UTILITY
var inherits = require('sys').inherits;
var util = require('util');
var pSlice = Array.prototype.slice;

// 1. The assert module provides functions that throw
Expand All @@ -47,7 +47,7 @@ assert.AssertionError = function AssertionError (options) {
Error.captureStackTrace(this, stackStartFunction);
}
};
inherits(assert.AssertionError, Error);
util.inherits(assert.AssertionError, Error);

assert.AssertionError.prototype.toString = function() {
if (this.message) {
Expand Down
4 changes: 2 additions & 2 deletions lib/child_process.js
@@ -1,4 +1,4 @@
var inherits = require('sys').inherits;
var util = require('util');
var EventEmitter = require('events').EventEmitter;
var Stream = require('net').Stream;
var InternalChildProcess = process.binding('child_process').ChildProcess;
Expand Down Expand Up @@ -155,7 +155,7 @@ function ChildProcess () {

this.__defineGetter__('pid', function () { return internal.pid; });
}
inherits(ChildProcess, EventEmitter);
util.inherits(ChildProcess, EventEmitter);


ChildProcess.prototype.kill = function (sig) {
Expand Down
1 change: 0 additions & 1 deletion lib/crypto.js
Expand Up @@ -3582,7 +3582,6 @@ var RootCaCerts = [
+"-----END CERTIFICATE-----\n"
];

var sys = require("sys");
try {
var binding = process.binding('crypto');
var SecureContext = binding.SecureContext;
Expand Down
4 changes: 2 additions & 2 deletions lib/dgram.js
@@ -1,4 +1,4 @@
var sys = require("sys");
var util = require("util");
var fs = require("fs");
var events = require("events");
var dns = require('dns');
Expand Down Expand Up @@ -72,7 +72,7 @@ function Socket (type, listener) {
}
}

sys.inherits(Socket, events.EventEmitter);
util.inherits(Socket, events.EventEmitter);
exports.Socket = Socket;

exports.createSocket = function (type, listener) {
Expand Down
12 changes: 6 additions & 6 deletions lib/fs.js
@@ -1,4 +1,4 @@
var sys = require('sys');
var util = require('util');
var events = require('events');

var binding = process.binding('fs');
Expand Down Expand Up @@ -666,7 +666,7 @@ var ReadStream = fs.ReadStream = function(path, options) {
self._read();
});
};
sys.inherits(ReadStream, events.EventEmitter);
util.inherits(ReadStream, events.EventEmitter);

fs.FileReadStream = fs.ReadStream; // support the legacy name

Expand Down Expand Up @@ -761,7 +761,7 @@ var readStreamForceCloseWarning;
ReadStream.prototype.forceClose = function (cb) {
if (!readStreamForceCloseWarning) {
readStreamForceCloseWarning = "ReadStream.prototype.forceClose renamed to destroy()";
sys.error(readStreamForceCloseWarning);
util.error(readStreamForceCloseWarning);
}
return this.destroy(cb);
};
Expand Down Expand Up @@ -844,7 +844,7 @@ var WriteStream = fs.WriteStream = function(path, options) {
this.flush();
}
};
sys.inherits(WriteStream, events.EventEmitter);
util.inherits(WriteStream, events.EventEmitter);

fs.FileWriteStream = fs.WriteStream; // support the legacy name

Expand Down Expand Up @@ -940,7 +940,7 @@ var writeStreamCloseWarning;
WriteStream.prototype.close = function (cb) {
if (!writeStreamCloseWarning) {
writeStreamCloseWarning = "WriteStream.prototype.close renamed to end()";
sys.error(writeStreamCloseWarning);
util.error(writeStreamCloseWarning);
}
return this.end(cb);
};
Expand All @@ -958,7 +958,7 @@ var writeStreamForceCloseWarning;
WriteStream.prototype.forceClose = function (cb) {
if (!writeStreamForceCloseWarning) {
writeStreamForceCloseWarning = "WriteStream.prototype.forceClose renamed to destroy()";
sys.error(writeStreamForceCloseWarning);
util.error(writeStreamForceCloseWarning);
}
return this.destroy(cb);
};
Expand Down

0 comments on commit e38eb0c

Please sign in to comment.