Skip to content

Commit

Permalink
Clean up streams chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Heaslip committed Jul 7, 2011
1 parent 7faeaaa commit 97cb9fe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 4 additions & 5 deletions book.html
Expand Up @@ -637,7 +637,7 @@ <h1>Buffers</h1>
</div>
<div class='mp'>
<h1>Streams</h1>
<p> Streams are an important concept in node. The stream api is a unified way to handle stream-like data, for example data can be streamed to a file, streamed to a socket to respond to an HTTP request, or a stream can be read-only such as reading from <em>stdin</em>. However since we will be touching on stream specifics in later chapters, for now we will concentrate on the api.</p>
<p> Streams are an important concept in node. The stream API is a unified way to handle stream-like data. For example, data can be streamed to a file, streamed to a socket to respond to an HTTP request, or streamed from a read-only source such as <em>stdin</em>. For now, we'll concentrate on the API, leaving stream specifics to later chapters.</p>

<h2 id="Readable-Streams">Readable Streams</h2>

Expand All @@ -648,16 +648,15 @@ <h2 id="Readable-Streams">Readable Streams</h2>
});
</code></pre>

<p>As we know, we can call <code>toString()</code> a buffer to return a string representation of the binary data, however in the case of streams if desired we may call <code>setEncoding()</code> on the stream,
after which the <em>data</em> event will emit strings.</p>
<p>As we know, we can call <code>toString()</code> on a buffer to return a string representation of the binary data. Likewise, we can call <code>setEncoding()</code> on a stream, after which the <em>data</em> event will emit strings.</p>

<pre><code>req.setEncoding('utf8');
req.on('data', function(str){
// Do something with the String
});
</code></pre>

<p>Another import event is the <em>end</em> event, which represents the ending of <em>data</em> events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we <strong>POST</strong> "hello world", our response will be "hello world".</p>
<p>Another important event is <em>end</em>, which represents the ending of <em>data</em> events. For example, here's an HTTP echo server, which simply "pumps" the request body data through to the response. So if we POST "hello world", our response will be "hello world".</p>

<pre><code>var http = require('http');

Expand All @@ -672,7 +671,7 @@ <h2 id="Readable-Streams">Readable Streams</h2>
}).listen(3000);
</code></pre>

<p>The <em>sys</em> module actually has a function designed specifically for this "pumping" action, aptly named <code>sys.pump()</code>, which accepts a read stream as the first argument, and write stream as the second.</p>
<p>The <em>sys</em> module actually has a function designed specifically for this "pumping" action, aptly named <code>sys.pump()</code>. It accepts a read stream as the first argument, and write stream as the second.</p>

<pre><code>var http = require('http'),
sys = require('sys');
Expand Down
9 changes: 4 additions & 5 deletions chapters/streams.html
@@ -1,6 +1,6 @@
<div class='mp'>
<h1>Streams</h1>
<p> Streams are an important concept in node. The stream api is a unified way to handle stream-like data, for example data can be streamed to a file, streamed to a socket to respond to an HTTP request, or a stream can be read-only such as reading from <em>stdin</em>. However since we will be touching on stream specifics in later chapters, for now we will concentrate on the api.</p>
<p> Streams are an important concept in node. The stream API is a unified way to handle stream-like data. For example, data can be streamed to a file, streamed to a socket to respond to an HTTP request, or streamed from a read-only source such as <em>stdin</em>. For now, we'll concentrate on the API, leaving stream specifics to later chapters.</p>

<h2 id="Readable-Streams">Readable Streams</h2>

Expand All @@ -11,16 +11,15 @@ <h2 id="Readable-Streams">Readable Streams</h2>
});
</code></pre>

<p>As we know, we can call <code>toString()</code> a buffer to return a string representation of the binary data, however in the case of streams if desired we may call <code>setEncoding()</code> on the stream,
after which the <em>data</em> event will emit strings.</p>
<p>As we know, we can call <code>toString()</code> on a buffer to return a string representation of the binary data. Likewise, we can call <code>setEncoding()</code> on a stream, after which the <em>data</em> event will emit strings.</p>

<pre><code>req.setEncoding('utf8');
req.on('data', function(str){
// Do something with the String
});
</code></pre>

<p>Another import event is the <em>end</em> event, which represents the ending of <em>data</em> events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we <strong>POST</strong> "hello world", our response will be "hello world".</p>
<p>Another important event is <em>end</em>, which represents the ending of <em>data</em> events. For example, here's an HTTP echo server, which simply "pumps" the request body data through to the response. So if we POST "hello world", our response will be "hello world".</p>

<pre><code>var http = require('http');

Expand All @@ -35,7 +34,7 @@ <h2 id="Readable-Streams">Readable Streams</h2>
}).listen(3000);
</code></pre>

<p>The <em>sys</em> module actually has a function designed specifically for this "pumping" action, aptly named <code>sys.pump()</code>, which accepts a read stream as the first argument, and write stream as the second.</p>
<p>The <em>sys</em> module actually has a function designed specifically for this "pumping" action, aptly named <code>sys.pump()</code>. It accepts a read stream as the first argument, and write stream as the second.</p>

<pre><code>var http = require('http'),
sys = require('sys');
Expand Down
9 changes: 4 additions & 5 deletions chapters/streams.md
@@ -1,7 +1,7 @@

# Streams

Streams are an important concept in node. The stream api is a unified way to handle stream-like data, for example data can be streamed to a file, streamed to a socket to respond to an HTTP request, or a stream can be read-only such as reading from _stdin_. However since we will be touching on stream specifics in later chapters, for now we will concentrate on the api.
Streams are an important concept in node. The stream API is a unified way to handle stream-like data. For example, data can be streamed to a file, streamed to a socket to respond to an HTTP request, or streamed from a read-only source such as _stdin_. For now, we'll concentrate on the API, leaving stream specifics to later chapters.

## Readable Streams

Expand All @@ -11,15 +11,14 @@
// Do something with the Buffer
});

As we know, we can call `toString()` a buffer to return a string representation of the binary data, however in the case of streams if desired we may call `setEncoding()` on the stream,
after which the _data_ event will emit strings.
As we know, we can call `toString()` on a buffer to return a string representation of the binary data. Likewise, we can call `setEncoding()` on a stream, after which the _data_ event will emit strings.

req.setEncoding('utf8');
req.on('data', function(str){
// Do something with the String
});

Another import event is the _end_ event, which represents the ending of _data_ events. For example below we define an HTTP echo server, simply "pumping" the request body data through to the response. So if we **POST** "hello world", our response will be "hello world".
Another important event is _end_, which represents the ending of _data_ events. For example, here's an HTTP echo server, which simply "pumps" the request body data through to the response. So if we POST "hello world", our response will be "hello world".

var http = require('http');

Expand All @@ -33,7 +32,7 @@ Another import event is the _end_ event, which represents the ending of _data_ e
});
}).listen(3000);

The _sys_ module actually has a function designed specifically for this "pumping" action, aptly named `sys.pump()`, which accepts a read stream as the first argument, and write stream as the second.
The _sys_ module actually has a function designed specifically for this "pumping" action, aptly named `sys.pump()`. It accepts a read stream as the first argument, and write stream as the second.

var http = require('http'),
sys = require('sys');
Expand Down

0 comments on commit 97cb9fe

Please sign in to comment.