Browse Source

API: node.fs.read() takes a normal encoding parameter.

Removes node.UTF8, node.RAW, node.ASCII enum versions of the encodings.
node.fs.read() now supports "raws" encoding.
v0.7.4-release
Ryan Dahl 16 years ago
parent
commit
0d1ec5fdbe
  1. 4
      doc/api.html
  2. 3
      doc/api.txt
  3. 10
      doc/node.1
  4. 4
      src/constants.cc
  5. 7
      src/file.cc
  6. 4
      src/file.js

4
doc/api.html

@ -815,8 +815,6 @@ Read data from the file specified by <tt>fd</tt>.
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>
@ -1863,7 +1861,7 @@ init (Handle&lt;Object&gt; target)
<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>

3
doc/api.txt

@ -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.

10
doc/node.1

@ -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)
@ -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\.

4
src/constants.cc

@ -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);

7
src/file.cc

@ -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)
@ -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));
}

4
src/file.js

@ -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 () {

Loading…
Cancel
Save