Skip to content

Commit

Permalink
API: node.fs.read() takes a normal encoding parameter.
Browse files Browse the repository at this point in the history
Removes node.UTF8, node.RAW, node.ASCII enum versions of the encodings.
node.fs.read() now supports "raws" encoding.
  • Loading branch information
ry committed Sep 13, 2009
1 parent d1a13bd commit 0d1ec5f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 26 deletions.
4 changes: 1 addition & 3 deletions doc/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,6 @@ <h3 id="_file_i_o">File I/O</h3><div style="clear:left"></div>
bytes to read.</p></div>
<div class="paragraph"><p><tt>position</tt> is an integer specifying where to begin
reading from in the file.</p></div>
<div class="paragraph"><p><tt>encoding</tt> is either <tt>node.UTF8</tt>
or <tt>node.RAW</tt>.</p></div>
<div class="ulist"><ul>
<li>
<p>
Expand Down Expand Up @@ -1863,7 +1861,7 @@ <h2 id="_extension_api">Extension API</h2>
<div id="footer">
<div id="footer-text">
Version 0.1.10<br />
Last updated 2009-09-12 19:12:41 CEST
Last updated 2009-09-13 18:25:27 CEST
</div>
</div>
</body>
Expand Down
3 changes: 0 additions & 3 deletions doc/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,6 @@ bytes to read.
+position+ is an integer specifying where to begin
reading from in the file.
+
+encoding+ is either +node.UTF8+
or +node.RAW+.
+
- on success: returns +data, bytes_read+, what was read from the file.
- on error: no parameters.

Expand Down
10 changes: 2 additions & 8 deletions doc/node.1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.\" Title: node
.\" Author:
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\" Date: 09/12/2009
.\" Date: 09/13/2009
.\" Manual:
.\" Source:
.\"
.TH "NODE" "1" "09/12/2009" "" ""
.TH "NODE" "1" "09/13/2009" "" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
Expand Down Expand Up @@ -732,12 +732,6 @@ is an integer specifying the number of bytes to read\.
position
is an integer specifying where to begin reading from in the file\.
.sp
encoding
is either
node\.UTF8
or
node\.RAW\.
.sp
.RS 4
\h'-04'\(bu\h'+03'on success: returns
data, bytes_read, what was read from the file\.
Expand Down
4 changes: 0 additions & 4 deletions src/constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ namespace node {
using namespace v8;

void DefineConstants(Handle<Object> target) {
NODE_DEFINE_CONSTANT(target, RAW);
NODE_DEFINE_CONSTANT(target, UTF8);
NODE_DEFINE_CONSTANT(target, ASCII);

// file access modes
NODE_DEFINE_CONSTANT(target, O_RDONLY);
NODE_DEFINE_CONSTANT(target, O_WRONLY);
Expand Down
7 changes: 2 additions & 5 deletions src/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ Write (const Arguments& args)
* 1 length integer. length to read
* 2 position if integer, position to read from in the file.
* if null, read from the current position
* 3 encoding either node.UTF8 or node.RAW
* 3 encoding
*/
static Handle<Value>
Read (const Arguments& args)
Expand All @@ -365,10 +365,7 @@ Read (const Arguments& args)
size_t len = args[1]->IntegerValue();
off_t pos = args[2]->IsNumber() ? args[2]->IntegerValue() : -1;

enum encoding encoding = RAW;
if (args[3]->IsInt32()) {
encoding = static_cast<enum encoding>(args[3]->Int32Value());
}
enum encoding encoding = ParseEncoding(args[3]);

return scope.Close(EIOPromise::Read(fd, len, pos, encoding));
}
Expand Down
4 changes: 1 addition & 3 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ 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 === "raw" ? node.RAW : node.UTF8);

open_promise.addErrback(function () { cat_promise.emitError(); });
open_promise.addCallback(function (fd) {
var content = (encoding === node.UTF8 ? "" : []);
var content = (encoding === "raw" ? [] : "");
var pos = 0;

function readChunk () {
Expand Down

0 comments on commit 0d1ec5f

Please sign in to comment.