Skip to content

Commit

Permalink
Remove "raw" encoding. Rename "raws" to "binary".
Browse files Browse the repository at this point in the history
Deprecation warnings have been added to help the conversion to this new API.
  • Loading branch information
ry committed Sep 21, 2009
1 parent 2db7d67 commit 07792af
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 281 deletions.
54 changes: 23 additions & 31 deletions doc/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ <h2 id="_synopsis">SYNOPSIS</h2>
</div>
<h2 id="_api">API</h2>
<div class="sectionbody">
<div class="paragraph"><p>Node supports 4 byte-string encodings. ASCII (<tt>"ascii"</tt>), UTF-8 (<tt>"utf8"</tt>)
both use the string object, obviously. Then two "raw binary" encodings - one
uses an array of integers (<tt>"raw"</tt>) and the other uses a string (<tt>"raws"</tt>).
Neither raw encodings are perfect and their implementations are rather
inefficient. Hopefully the raw encoding situation will improve in the
future.</p></div>
<div class="paragraph"><p>Node supports 3 string encodings. UTF-8 (<tt>"utf8"</tt>), ASCII (<tt>"ascii"</tt>), and
Binary (<tt>"binary"</tt>). <tt>"ascii"</tt> and <tt>"binary"</tt> only look at the first 8 bits
of the 16bit javascript string characters. Both are relatively fast&#8212;use
them if you can. <tt>"utf8"</tt> is slower and should be avoided when possible.</p></div>
<div class="paragraph"><p>Unless otherwise noted, functions are all asynchronous and do not block
execution.</p></div>
<h3 id="_helpers">Helpers</h3><div style="clear:left"></div>
Expand Down Expand Up @@ -373,10 +371,9 @@ <h3 id="_standard_i_o">Standard I/O</h3><div style="clear:left"></div>
<td align="left" valign="top"><p class="table"><tt>data</tt></p></td>
<td align="left" valign="top"><p class="table">Made when stdin has received a chunk of data.
Depending on the encoding that stdin was opened
with, <tt>data</tt> will be either an array of integers
(raw encoding) or a string (ascii or utf8
encoding). This event will only be emited after
<tt>node.stdio.open()</tt> has been called.</p></td>
with, <tt>data</tt> will be a string. This event will
only be emited after <tt>node.stdio.open()</tt> has
been called.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><tt>"close"</tt></p></td>
Expand Down Expand Up @@ -599,7 +596,8 @@ <h4 id="_tt_node_childprocess_tt"><tt>node.ChildProcess</tt></h4>
<dd>
<p>
Write data to the child process&#8217;s <tt>stdin</tt>. The second argument is optional and
specifies the encoding: possible values are <tt>"utf8"</tt>, <tt>"ascii"</tt>, and <tt>"raw"</tt>.
specifies the encoding: possible values are <tt>"utf8"</tt>, <tt>"ascii"</tt>, and
<tt>"binary"</tt>.
</p>
</dd>
<dt class="hdlist1">
Expand Down Expand Up @@ -1050,8 +1048,7 @@ <h4 id="_tt_node_http_serverrequest_tt"><tt>node.http.ServerRequest</tt></h4>
<td align="left" valign="top"><p class="table"><tt>chunk</tt></p></td>
<td align="left" valign="top"><p class="table">Emitted when a piece of the message body is received. Example: A chunk of
the body is given as the single argument. The transfer-encoding has been
decoded. The body chunk is either a String in the case of UTF-8 encoding or
an array of numbers in the case of raw encoding. The body encoding is set
decoded. The body chunk is a String. The body encoding is set
with <tt>request.setBodyEncoding()</tt>.</p></td>
</tr>
<tr>
Expand Down Expand Up @@ -1123,8 +1120,8 @@ <h4 id="_tt_node_http_serverrequest_tt"><tt>node.http.ServerRequest</tt></h4>
</dt>
<dd>
<p>
Set the encoding for the request body. Either <tt>"utf8"</tt> or <tt>"raw"</tt>. Defaults
to raw.
Set the encoding for the request body. Either <tt>"utf8"</tt> or <tt>"binary"</tt>. Defaults
to <tt>"binary"</tt>.
</p>
</dd>
<dt class="hdlist1">
Expand Down Expand Up @@ -1380,9 +1377,8 @@ <h4 id="_tt_node_http_clientresponse_tt"><tt>node.http.ClientResponse</tt></h4>
<td align="left" valign="top"><p class="table"><tt>chunk</tt></p></td>
<td align="left" valign="top"><p class="table">Emitted when a piece of the message body is received. Example: A chunk of
the body is given as the single argument. The transfer-encoding has been
decoded. The body chunk is either a String in the case of UTF-8 encoding or
an array of numbers in the case of raw encoding. The body encoding is set
with <tt>response.setBodyEncoding()</tt>.</p></td>
decoded. The body chunk a String. The body encoding is set with
<tt>response.setBodyEncoding()</tt>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><tt>"complete"</tt></p></td>
Expand Down Expand Up @@ -1424,8 +1420,8 @@ <h4 id="_tt_node_http_clientresponse_tt"><tt>node.http.ClientResponse</tt></h4>
</dt>
<dd>
<p>
Set the encoding for the response body. Either <tt>"utf8"</tt> or <tt>"raw"</tt>.
Defaults to raw.
Set the encoding for the response body. Either <tt>"utf8"</tt> or <tt>"binary"</tt>.
Defaults to <tt>"binary"</tt>.
</p>
</dd>
<dt class="hdlist1">
Expand Down Expand Up @@ -1574,11 +1570,9 @@ <h4 id="_tt_node_tcp_connection_tt"><tt>node.tcp.Connection</tt></h4>
<td align="left" valign="top"><p class="table"><tt>"receive"</tt></p></td>
<td align="left" valign="top"><p class="table"><tt>data</tt></p></td>
<td align="left" valign="top"><p class="table">Called when data is received on the
connection. Encoding of data is set
by <tt>connection.setEncoding()</tt>. <tt>data</tt>
will either be a string, in the case of
utf8, or an array of integer in the case
of raw encoding.</p></td>
connection. <tt>data</tt> will be a string.
Encoding of data is set by
<tt>connection.setEncoding()</tt>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p class="table"><tt>"eof"</tt></p></td>
Expand Down Expand Up @@ -1658,18 +1652,16 @@ <h4 id="_tt_node_tcp_connection_tt"><tt>node.tcp.Connection</tt></h4>
</dt>
<dd>
<p>
Sets the encoding (either <tt>"utf8"</tt> or <tt>"raw"</tt>) for data that is received.
Sets the encoding (either <tt>"ascii"</tt>, <tt>"utf8"</tt>, or <tt>"binary"</tt>) for data that is received.
</p>
</dd>
<dt class="hdlist1">
<tt>connection.send(data, encoding="ascii")</tt>
</dt>
<dd>
<p>
Sends data on the connection. The data should be eithre an array
of integers (for raw binary) or a string (for utf8 or ascii).
The second parameter specifies the encoding in the case of a
string&#8212;it defaults to ASCII because encoding to UTF8 is
Sends data on the connection. The second parameter specifies the encoding
in the case of a string&#8212;it defaults to ASCII because encoding to UTF8 is
rather slow.
</p>
</dd>
Expand Down Expand Up @@ -1930,7 +1922,7 @@ <h2 id="_extension_api">Extension API</h2>
<div id="footer">
<div id="footer-text">
Version 0.1.11<br />
Last updated 2009-09-18 18:31:06 CEST
Last updated 2009-09-21 12:26:35 CEST
</div>
</div>
</body>
Expand Down
52 changes: 22 additions & 30 deletions doc/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ Server running at http://127.0.0.1:8000/

== API

Node supports 4 byte-string encodings. ASCII (+"ascii"+), UTF-8 (+"utf8"+)
both use the string object, obviously. Then two "raw binary" encodings - one
uses an array of integers (+"raw"+) and the other uses a string (+"raws"+).
Neither raw encodings are perfect and their implementations are rather
inefficient. Hopefully the raw encoding situation will improve in the
future.
Node supports 3 string encodings. UTF-8 (+"utf8"+), ASCII (+"ascii"+), and
Binary (+"binary"+). +"ascii"+ and +"binary"+ only look at the first 8 bits
of the 16bit javascript string characters. Both are relatively fast--use
them if you can. +"utf8"+ is slower and should be avoided when possible.

Unless otherwise noted, functions are all asynchronous and do not block
execution.
Expand Down Expand Up @@ -222,10 +220,9 @@ synchronous.

| +"data"+ | +data+ | Made when stdin has received a chunk of data.
Depending on the encoding that stdin was opened
with, +data+ will be either an array of integers
(raw encoding) or a string (ascii or utf8
encoding). This event will only be emited after
+node.stdio.open()+ has been called.
with, +data+ will be a string. This event will
only be emited after +node.stdio.open()+ has
been called.
| +"close"+ | | Made when stdin has been closed.
|=========================================================

Expand Down Expand Up @@ -394,7 +391,8 @@ The PID of the child process.

+child.write(data, encoding="ascii")+ ::
Write data to the child process's +stdin+. The second argument is optional and
specifies the encoding: possible values are +"utf8"+, +"ascii"+, and +"raw"+.
specifies the encoding: possible values are +"utf8"+, +"ascii"+, and
+"binary"+.


+child.close()+ ::
Expand Down Expand Up @@ -640,8 +638,7 @@ the user--and passed as the first argument to a +"request"+ listener.
|+"body"+ | +chunk+ |
Emitted when a piece of the message body is received. Example: A chunk of
the body is given as the single argument. The transfer-encoding has been
decoded. The body chunk is either a String in the case of UTF-8 encoding or
an array of numbers in the case of raw encoding. The body encoding is set
decoded. The body chunk is a String. The body encoding is set
with +request.setBodyEncoding()+.

|+"complete"+ | |
Expand Down Expand Up @@ -692,8 +689,8 @@ The HTTP protocol version as a string. Read only. Examples:


+request.setBodyEncoding(encoding)+ ::
Set the encoding for the request body. Either +"utf8"+ or +"raw"+. Defaults
to raw.
Set the encoding for the request body. Either +"utf8"+ or +"binary"+. Defaults
to +"binary"+.


+request.pause()+ ::
Expand Down Expand Up @@ -895,9 +892,8 @@ This object is created internally and passed to the +"response"+ event.
|+"body"+ | +chunk+ |
Emitted when a piece of the message body is received. Example: A chunk of
the body is given as the single argument. The transfer-encoding has been
decoded. The body chunk is either a String in the case of UTF-8 encoding or
an array of numbers in the case of raw encoding. The body encoding is set
with +response.setBodyEncoding()+.
decoded. The body chunk a String. The body encoding is set with
+response.setBodyEncoding()+.

|+"complete"+ | |
Emitted exactly once for each message. No arguments.
Expand All @@ -916,8 +912,8 @@ After emitted no other events will be emitted on the response.
The response headers.

+response.setBodyEncoding(encoding)+ ::
Set the encoding for the response body. Either +"utf8"+ or +"raw"+.
Defaults to raw.
Set the encoding for the response body. Either +"utf8"+ or +"binary"+.
Defaults to +"binary"+.

+response.pause()+ ::
Pauses response from emitting events. Useful to throttle back a download.
Expand Down Expand Up @@ -1005,11 +1001,9 @@ socket for +node.tcp.Server+.
after a call to +createConnection()+ or
+connect()+.
|+"receive"+ | +data+ | Called when data is received on the
connection. Encoding of data is set
by +connection.setEncoding()+. +data+
will either be a string, in the case of
utf8, or an array of integer in the case
of raw encoding.
connection. +data+ will be a string.
Encoding of data is set by
+connection.setEncoding()+.
|+"eof"+ | | Called when the other end of the
connection sends a FIN packet.
After this is emitted the +readyState+
Expand Down Expand Up @@ -1055,13 +1049,11 @@ Either +"closed"+, +"open"+, +"opening"+, +"readOnly"+, or +"writeOnly"+.


+connection.setEncoding(encoding)+::
Sets the encoding (either +"utf8"+ or +"raw"+) for data that is received.
Sets the encoding (either +"ascii"+, +"utf8"+, or +"binary"+) for data that is received.

+connection.send(data, encoding="ascii")+::
Sends data on the connection. The data should be eithre an array
of integers (for raw binary) or a string (for utf8 or ascii).
The second parameter specifies the encoding in the case of a
string--it defaults to ASCII because encoding to UTF8 is
Sends data on the connection. The second parameter specifies the encoding
in the case of a string--it defaults to ASCII because encoding to UTF8 is
rather slow.


Expand Down
30 changes: 16 additions & 14 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/18/2009
.\" Date: 09/21/2009
.\" Manual:
.\" Source:
.\"
.TH "NODE" "1" "09/18/2009" "" ""
.TH "NODE" "1" "09/21/2009" "" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
Expand Down Expand Up @@ -38,7 +38,7 @@ Server running at http://127\.0\.0\.1:8000/
.fi
.RE
.SH "API"
Node supports 4 byte\-string encodings\. ASCII ("ascii"), UTF\-8 ("utf8") both use the string object, obviously\. Then two "raw binary" encodings \- one uses an array of integers ("raw") and the other uses a string ("raws")\. Neither raw encodings are perfect and their implementations are rather inefficient\. Hopefully the raw encoding situation will improve in the future\.
Node supports 3 string encodings\. UTF\-8 ("utf8"), ASCII ("ascii"), and Binary ("binary")\. "ascii" and "binary" only look at the first 8 bits of the 16bit javascript string characters\. Both are relatively fast\(emuse them if you can\. "utf8" is slower and should be avoided when possible\.
.sp
Unless otherwise noted, functions are all asynchronous and do not block execution\.
.sp
Expand Down Expand Up @@ -329,7 +329,7 @@ T}:T{
data
.sp
T}:T{
Made when stdin has received a chunk of data\. Depending on the encoding that stdin was opened with, data will be either an array of integers (raw encoding) or a string (ascii or utf8 encoding)\. This event will only be emited after node\.stdio\.open() has been called\.
Made when stdin has received a chunk of data\. Depending on the encoding that stdin was opened with, data will be a string\. This event will only be emited after node\.stdio\.open() has been called\.
.sp
T}
T{
Expand Down Expand Up @@ -558,7 +558,7 @@ Write data to the child process\(cqs
stdin\. The second argument is optional and specifies the encoding: possible values are
"utf8",
"ascii", and
"raw"\.
"binary"\.
.RE
.PP
child\.close()
Expand Down Expand Up @@ -946,7 +946,7 @@ T}:T{
chunk
.sp
T}:T{
Emitted when a piece of the message body is received\. Example: A chunk of the body is given as the single argument\. The transfer\-encoding has been decoded\. The body chunk is either a String in the case of UTF\-8 encoding or an array of numbers in the case of raw encoding\. The body encoding is set with request\.setBodyEncoding()\.
Emitted when a piece of the message body is received\. Example: A chunk of the body is given as the single argument\. The transfer\-encoding has been decoded\. The body chunk is a String\. The body encoding is set with request\.setBodyEncoding()\.
.sp
T}
T{
Expand Down Expand Up @@ -1030,7 +1030,8 @@ request\.setBodyEncoding(encoding)
Set the encoding for the request body\. Either
"utf8"
or
"raw"\. Defaults to raw\.
"binary"\. Defaults to
"binary"\.
.RE
.PP
request\.pause()
Expand Down Expand Up @@ -1300,7 +1301,7 @@ T}:T{
chunk
.sp
T}:T{
Emitted when a piece of the message body is received\. Example: A chunk of the body is given as the single argument\. The transfer\-encoding has been decoded\. The body chunk is either a String in the case of UTF\-8 encoding or an array of numbers in the case of raw encoding\. The body encoding is set with response\.setBodyEncoding()\.
Emitted when a piece of the message body is received\. Example: A chunk of the body is given as the single argument\. The transfer\-encoding has been decoded\. The body chunk a String\. The body encoding is set with response\.setBodyEncoding()\.
.sp
T}
T{
Expand Down Expand Up @@ -1338,7 +1339,8 @@ response\.setBodyEncoding(encoding)
Set the encoding for the response body\. Either
"utf8"
or
"raw"\. Defaults to raw\.
"binary"\. Defaults to
"binary"\.
.RE
.PP
response\.pause()
Expand Down Expand Up @@ -1502,7 +1504,7 @@ T}:T{
data
.sp
T}:T{
Called when data is received on the connection\. Encoding of data is set by connection\.setEncoding()\. data will either be a string, in the case of utf8, or an array of integer in the case of raw encoding\.
Called when data is received on the connection\. data will be a string\. Encoding of data is set by connection\.setEncoding()\.
.sp
T}
T{
Expand Down Expand Up @@ -1589,14 +1591,14 @@ Either
connection\.setEncoding(encoding)
.RS 4
Sets the encoding (either
"utf8"
or
"raw") for data that is received\.
"ascii",
"utf8", or
"binary") for data that is received\.
.RE
.PP
connection\.send(data, encoding="ascii")
.RS 4
Sends data on the connection\. The data should be eithre an array of integers (for raw binary) or a string (for utf8 or ascii)\. The second parameter specifies the encoding in the case of a string\(emit defaults to ASCII because encoding to UTF8 is rather slow\.
Sends data on the connection\. The second parameter specifies the encoding in the case of a string\(emit defaults to ASCII because encoding to UTF8 is rather slow\.
.RE
.PP
connection\.close()
Expand Down
2 changes: 1 addition & 1 deletion src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ node.fs.cat = function (path, encoding) {
cat_promise.emitError(new Error("Could not open " + path));
});
open_promise.addCallback(function (fd) {
var content = (encoding === "raw" ? [] : "");
var content = "";
var pos = 0;

function readChunk () {
Expand Down
4 changes: 2 additions & 2 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ OutgoingMessage.prototype.send = function (data, encoding) {

if (length === 0) {
this.output.push(data);
encoding = encoding || (data.constructor === Array ? "raw" : "ascii");
encoding = encoding || "ascii";
this.outputEncodings.push(encoding);
return;
}
Expand All @@ -197,7 +197,7 @@ OutgoingMessage.prototype.send = function (data, encoding) {
}

this.output.push(data);
encoding = encoding || (data.constructor === Array ? "raw" : "ascii");
encoding = encoding || "ascii";
this.outputEncodings.push(encoding);
};

Expand Down
Loading

0 comments on commit 07792af

Please sign in to comment.