diff --git a/doc/api.html b/doc/api.html index 4641471a3f..be20f95dfa 100644 --- a/doc/api.html +++ b/doc/api.html @@ -874,7 +874,7 @@ on error: no parameters.
-node.fs.cat(filename, encoding) +node.fs.cat(filename, encoding="utf8")

@@ -882,7 +882,7 @@ Outputs the entire contents of a file. Example:

-
node.fs.cat("/etc/passwd", "utf8").addCallback(function (content) {
+
node.fs.cat("/etc/passwd").addCallback(function (content) {
   puts(content);
 });
@@ -1906,7 +1906,7 @@ init (Handle<Object> target) diff --git a/doc/api.txt b/doc/api.txt index 1209d51e59..8a1e818feb 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -525,12 +525,12 @@ reading from in the file. - on success: returns +data, bytes_read+, what was read from the file. - on error: no parameters. -+node.fs.cat(filename, encoding)+:: ++node.fs.cat(filename, encoding="utf8")+:: Outputs the entire contents of a file. Example: + -------------------------------- -node.fs.cat("/etc/passwd", "utf8").addCallback(function (content) { +node.fs.cat("/etc/passwd").addCallback(function (content) { puts(content); }); -------------------------------- diff --git a/doc/node.1 b/doc/node.1 index c010440622..0332a29e0b 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -783,13 +783,13 @@ data, bytes_read, what was read from the file\. .RE .RE .PP -node\.fs\.cat(filename, encoding) +node\.fs\.cat(filename, encoding="utf8") .RS 4 Outputs the entire contents of a file\. Example: .sp .RS 4 .nf -node\.fs\.cat("/etc/passwd", "utf8")\.addCallback(function (content) { +node\.fs\.cat("/etc/passwd")\.addCallback(function (content) { puts(content); }); .fi diff --git a/src/file.js b/src/file.js index 25a8f89f2b..e02e19a31a 100644 --- a/src/file.js +++ b/src/file.js @@ -8,6 +8,8 @@ node.fs.cat = function (path, encoding) { var open_promise = node.fs.open(path, node.O_RDONLY, 0666); var cat_promise = new node.Promise(); + encoding = encoding || "utf8"; + open_promise.addErrback(function () { cat_promise.emitError(); }); open_promise.addCallback(function (fd) { var content = (encoding === "raw" ? [] : ""); diff --git a/src/http.js b/src/http.js index 777bfd58fc..ea558cd1f5 100644 --- a/src/http.js +++ b/src/http.js @@ -550,6 +550,8 @@ node.http.Client.prototype.put = function (uri, headers) { node.http.cat = function (url, encoding) { var promise = new node.Promise(); + encoding = encoding || "utf8"; + var uri = node.http.parseUri(url); var client = node.http.createClient(uri.port || 80, uri.host); var req = client.get(uri.path || "/"); diff --git a/src/node.js b/src/node.js index 7de2bdf977..19b4e263fa 100644 --- a/src/node.js +++ b/src/node.js @@ -152,7 +152,7 @@ node.Module.prototype.loadScript = function (callback) { node.assert(self.loadPromise === null); self.loadPromise = loadPromise; - var cat_promise = node.cat(self.filename, "utf8"); + var cat_promise = node.cat(self.filename); cat_promise.addErrback(function () { node.stdio.writeError("Error reading " + self.filename + "\n");