Skip to content

Commit 5fcc374

Browse files
committed
more single quotes
1 parent 6697821 commit 5fcc374

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

_posts/2014-2-17-javascript-gotchas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
layout: post
3-
title: "JavaScript gotchas"
3+
title: "JavaScript must-knows"
44
author: NodeKC
55
tags:
66
---
77

8-
# JavaScript gotchas
8+
# JavaScript must-knows
99

1010
JavaScript is a language that many developers are familiar with but lack a deep understanding. The language lends itself to new programmers, in part, because of its simple syntax. Many fundamental concepts and features of the language can be overlooked with a simple procedural approach. The goal of this lab is to give you a better understanding of some core concepts and important language features to understand about JavaScript.
1111

_posts/2014-2-27-streams.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
---
2+
layout: post
3+
title: "Streams"
4+
author: NodeKC
5+
tags:
6+
---
7+
18
# Streams
29

3-
Streams are one of the most amazing features of Node. However, it's not a new thing. \*nix systems use I/O streams to move data from one process to another.
10+
Streams are one of the most amazing features of Node. However, it\'s not a new thing. \*nix systems use I/O streams to move data from one process to another.
411

512
## Read Streams
613

7-
The first stream we'll discuss is a read stream. As you might expect this stream supports only reading. Let's take a look at an example.
14+
The first stream we will discuss is a read stream. As you might expect this stream supports only reading. Let\'s take a look at an example.
815

916
Start by creating a file called ```example.txt``` and add whatever contents you like. Create another file called `readable.js` and add the following:
1017

@@ -61,9 +68,9 @@ rs.on('end', function () {
6168
{% endhighlight %}
6269

6370

64-
We get to learn a few different things in this example. First, we create a new readable stream. The `MyStream` function is inheriting the prototype from Node core's `ReadableStream` and in its constructor calls the `ReadableStream` constructor. We must call the constructor of the core implementation in order to perform the necessary initialization of our stream. We are required to implement the internal method `_read` which is called on every read request. In this example the first read request is issued whenever we subscribe to the `'data'` event. There are other ways to do this which we'll cover next.
71+
We get to learn a few different things in this example. First, we create a new readable stream. The `MyStream` function is inheriting the prototype from Node core's `ReadableStream` and in its constructor calls the `ReadableStream` constructor. We must call the constructor of the core implementation in order to perform the necessary initialization of our stream. We are required to implement the internal method `_read` which is called on every read request. In this example the first read request is issued whenever we subscribe to the `'data'` event. There are other ways to do this which we will cover next.
6572

66-
You'll notice in this example that we are able to control the flow of data from a readable stream through `pause` and `resume`. This is incredibly important to allow your application to keep up with incoming data and only receive data when needed.
73+
You will notice in this example that we are able to control the flow of data from a readable stream through `pause` and `resume`. This is incredibly important to allow your application to keep up with incoming data and only receive data when needed.
6774

6875
The above example reads data by the buffer. However, we have more fine grained control over how much data we receive through the `read` method. The next example will give you an idea of the series of events that occurs when reading from a stream that can provide data at various times. This is exactly the situation when dealing with network connections. Feel free to copy and paste this snippet. Study the output and understand the chain of events before moving on.
6976

@@ -126,11 +133,11 @@ rs.on('readable', function () {
126133
log('Reached end of program. It\'s now alive because of async callbacks pending.');
127134
{% endhighlight %}
128135

129-
We've successfully read 2 bytes from our underlying stream with each iteration of the loop. Despite the number of calls to `read` we only invoke our internal function when new data is actually needed.
136+
We\'ve successfully read 2 bytes from our underlying stream with each iteration of the loop. Despite the number of calls to `read` we only invoke our internal function when new data is actually needed.
130137

131138
## Write Stream
132139

133-
An example of where write streams are used are HTTP responses or standard output. Just like `ReadableStream`s, `WritableStream`s have a built in mechanism for rate limiting. These streams are aware of when the underlying buffer has been flushed and provide the caller with this information. This is very useful so that you don't seen more than a client can handle. If the client isn't able to accept information fast enough it will buffer in memory. Let's have a look at a simple example of a commonly used write stream. Open a node REPL and input the following:
140+
An example of where write streams are used are HTTP responses or standard output. Just like `ReadableStream`s, `WritableStream`s have a built in mechanism for rate limiting. These streams are aware of when the underlying buffer has been flushed and provide the caller with this information. This is very useful so that you don\'t seen more than a client can handle. If the client isn\'t able to accept information fast enough it will buffer in memory. Let\'s have a look at a simple example of a commonly used write stream. Open a node REPL and input the following:
134141

135142
{% highlight javascript %}
136143
process.stdout.write('Hello World');
@@ -169,7 +176,7 @@ console.log('write (2) return value', result);
169176

170177
Piping
171178

172-
Much praise is given to node by its community for providing an extremely simple interface for chaining streams together using `pipe`. All \*nix developers are familar with having the ability to pipe the standard output of one process into the standard input of another using a `|`. Let's see how we could take our standard input and direct it to our processes output stream.
179+
Much praise is given to node by its community for providing an extremely simple interface for chaining streams together using `pipe`. All \*nix developers are familar with having the ability to pipe the standard output of one process into the standard input of another using a `|`. Let\'s see how we could take our standard input and direct it to our processes output stream.
173180

174181
{% highlight javascript %}
175182
process.stdin.pipe(process.stdout);
@@ -181,7 +188,7 @@ We can test this by placing the above contents in a file called pipe.js and runn
181188
echo 'This is going to be piped out' | node pipe.js
182189
{% endhighlight %}
183190

184-
How easy was that! If we didn't have `pipe` here's how we'd accomplish the same task. You can see pipe is taking care of a lot for us. What you do not see in this example is that `pipe` is automatically handling backpressure.
191+
How easy was that! If we didn\'t have `pipe` here's how we\'d accomplish the same task. You can see pipe is taking care of a lot for us. What you do not see in this example is that `pipe` is automatically handling backpressure.
185192

186193
{% highlight javascript %}
187194
process.stdin.on('data', function (data) {

0 commit comments

Comments
 (0)