Browse Source

Default to utf8 encoding for node.fs.cat()

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
9db2e5f375
  1. 6
      doc/api.html
  2. 4
      doc/api.txt
  3. 4
      doc/node.1
  4. 2
      src/file.js
  5. 2
      src/http.js
  6. 2
      src/node.js

6
doc/api.html

@ -874,7 +874,7 @@ on error: no parameters.
</ul></div> </ul></div>
</dd> </dd>
<dt class="hdlist1"> <dt class="hdlist1">
<tt>node.fs.cat(filename, encoding)</tt> <tt>node.fs.cat(filename, encoding="utf8")</tt>
</dt> </dt>
<dd> <dd>
<p> <p>
@ -882,7 +882,7 @@ Outputs the entire contents of a file. Example:
</p> </p>
<div class="listingblock"> <div class="listingblock">
<div class="content"> <div class="content">
<pre><tt>node.fs.cat("/etc/passwd", "utf8").addCallback(function (content) { <pre><tt>node.fs.cat("/etc/passwd").addCallback(function (content) {
puts(content); puts(content);
});</tt></pre> });</tt></pre>
</div></div> </div></div>
@ -1906,7 +1906,7 @@ init (Handle&lt;Object&gt; target)
<div id="footer"> <div id="footer">
<div id="footer-text"> <div id="footer-text">
Version 0.1.10<br /> Version 0.1.10<br />
Last updated 2009-09-15 22:31:35 CEST Last updated 2009-09-15 22:34:24 CEST
</div> </div>
</div> </div>
</body> </body>

4
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 success: returns +data, bytes_read+, what was read from the file.
- on error: no parameters. - on error: no parameters.
+node.fs.cat(filename, encoding)+:: +node.fs.cat(filename, encoding="utf8")+::
Outputs the entire contents of a file. Example: 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); puts(content);
}); });
-------------------------------- --------------------------------

4
doc/node.1

@ -783,13 +783,13 @@ data, bytes_read, what was read from the file\.
.RE .RE
.RE .RE
.PP .PP
node\.fs\.cat(filename, encoding) node\.fs\.cat(filename, encoding="utf8")
.RS 4 .RS 4
Outputs the entire contents of a file\. Example: Outputs the entire contents of a file\. Example:
.sp .sp
.RS 4 .RS 4
.nf .nf
node\.fs\.cat("/etc/passwd", "utf8")\.addCallback(function (content) { node\.fs\.cat("/etc/passwd")\.addCallback(function (content) {
puts(content); puts(content);
}); });
.fi .fi

2
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 open_promise = node.fs.open(path, node.O_RDONLY, 0666);
var cat_promise = new node.Promise(); var cat_promise = new node.Promise();
encoding = encoding || "utf8";
open_promise.addErrback(function () { cat_promise.emitError(); }); open_promise.addErrback(function () { cat_promise.emitError(); });
open_promise.addCallback(function (fd) { open_promise.addCallback(function (fd) {
var content = (encoding === "raw" ? [] : ""); var content = (encoding === "raw" ? [] : "");

2
src/http.js

@ -550,6 +550,8 @@ node.http.Client.prototype.put = function (uri, headers) {
node.http.cat = function (url, encoding) { node.http.cat = function (url, encoding) {
var promise = new node.Promise(); var promise = new node.Promise();
encoding = encoding || "utf8";
var uri = node.http.parseUri(url); var uri = node.http.parseUri(url);
var client = node.http.createClient(uri.port || 80, uri.host); var client = node.http.createClient(uri.port || 80, uri.host);
var req = client.get(uri.path || "/"); var req = client.get(uri.path || "/");

2
src/node.js

@ -152,7 +152,7 @@ node.Module.prototype.loadScript = function (callback) {
node.assert(self.loadPromise === null); node.assert(self.loadPromise === null);
self.loadPromise = loadPromise; self.loadPromise = loadPromise;
var cat_promise = node.cat(self.filename, "utf8"); var cat_promise = node.cat(self.filename);
cat_promise.addErrback(function () { cat_promise.addErrback(function () {
node.stdio.writeError("Error reading " + self.filename + "\n"); node.stdio.writeError("Error reading " + self.filename + "\n");

Loading…
Cancel
Save