Skip to content

Commit

Permalink
Clean up file system chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Heaslip committed Jul 7, 2011
1 parent 97cb9fe commit 15dc0e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
17 changes: 8 additions & 9 deletions book.html
Expand Up @@ -685,11 +685,11 @@ <h2 id="Readable-Streams">Readable Streams</h2>
</div>
<div class='mp'>
<h1>File System</h1>
<p> To work with the filesystem, node provides the 'fs' module. The commands follow the POSIX operations, with most methods supporting an asynchronous and synchronous method call. We will look at how to use both and then establish which is the better option.</p>
<p> To work with the filesystem, node provides the "fs" module. The commands emulate the POSIX operations, and most methods work synchronously or asynchronously. We will look at how to use both, then establish which is the better option.</p>

<h2 id="Working-with-the-filesystem">Working with the filesystem</h2>

<p> Lets start with a basic example of working with the filesystem, this example creates a directory, it then creates a file in it. Once the file has been created the contents of the file are written to console:</p>
<p> Lets start with a basic example of working with the filesystem. This example creates a directory, creates a file inside it, then writes the contents of the file to console:</p>

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

Expand All @@ -708,7 +708,7 @@ <h2 id="Working-with-the-filesystem">Working with the filesystem</h2>
});
</code></pre>

<p> As evident in the example above, each callback is placed in the previous callback - this is what is referred to as chainable callbacks. When using asynchronous methods this pattern should be used, as there is no guarantee that the operations will be completed in the order that they are created. This could lead to unpredictable behavior.</p>
<p> As evident in the example above, each callback is placed in the previous callback &mdash; these are referred to as chainable callbacks. This pattern should be followed when using asynchronous methods, as there's no guarantee that the operations will be completed in the order they're created. This could lead to unpredictable behavior.</p>

<p> The example can be rewritten to use a synchronous approach:</p>

Expand All @@ -719,12 +719,11 @@ <h2 id="Working-with-the-filesystem">Working with the filesystem</h2>
console.log(data);
</code></pre>

<p> It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections and other events.</p>
<p> It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections or other events.</p>

<h2 id="File-information">File information</h2>

<p> The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we
are working with. In this example we are getting all the file objects in a directory and displaying whether they are a file or a
<p> The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we're working with. In this example, we're getting all the file objects in a directory and displaying whether they're a file or a
directory object.</p>

<pre><code>var fs = require('fs');
Expand All @@ -750,7 +749,7 @@ <h2 id="File-information">File information</h2>

<h2 id="Watching-files">Watching files</h2>

<p> The fs.watchfile monitors a file and will fire the event whenever the file is changed.</p>
<p> The fs.watchfile method monitors a file and fires an event whenever the file is changed.</p>

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

Expand All @@ -766,11 +765,11 @@ <h2 id="Watching-files">Watching files</h2>
});
</code></pre>

<p> A file can also be unwatched using the fs.unwatchFile method call. This is used once monitoring of a file is no longer required.</p>
<p> A file can also be unwatched using the fs.unwatchFile method call. This should be used once a file no longer needs to be monitored.</p>

<h2 id="Nodejs-Docs-for-further-reading">Nodejs Docs for further reading</h2>

<p> The node api <a href="http://nodejs.org/api.html#file-system-106">docs</a> are very detailed and list all the possible filesystem commands
<p> The node API <a href="http://nodejs.org/api.html#file-system-106">docs</a> are very detailed and list all the possible filesystem commands
available when working with Nodejs.</p>

</div>
Expand Down
17 changes: 8 additions & 9 deletions chapters/fs.html
@@ -1,10 +1,10 @@
<div class='mp'>
<h1>File System</h1>
<p> To work with the filesystem, node provides the 'fs' module. The commands follow the POSIX operations, with most methods supporting an asynchronous and synchronous method call. We will look at how to use both and then establish which is the better option.</p>
<p> To work with the filesystem, node provides the "fs" module. The commands emulate the POSIX operations, and most methods work synchronously or asynchronously. We will look at how to use both, then establish which is the better option.</p>

<h2 id="Working-with-the-filesystem">Working with the filesystem</h2>

<p> Lets start with a basic example of working with the filesystem, this example creates a directory, it then creates a file in it. Once the file has been created the contents of the file are written to console:</p>
<p> Lets start with a basic example of working with the filesystem. This example creates a directory, creates a file inside it, then writes the contents of the file to console:</p>

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

Expand All @@ -23,7 +23,7 @@ <h2 id="Working-with-the-filesystem">Working with the filesystem</h2>
});
</code></pre>

<p> As evident in the example above, each callback is placed in the previous callback - this is what is referred to as chainable callbacks. When using asynchronous methods this pattern should be used, as there is no guarantee that the operations will be completed in the order that they are created. This could lead to unpredictable behavior.</p>
<p> As evident in the example above, each callback is placed in the previous callback &mdash; these are referred to as chainable callbacks. This pattern should be followed when using asynchronous methods, as there's no guarantee that the operations will be completed in the order they're created. This could lead to unpredictable behavior.</p>

<p> The example can be rewritten to use a synchronous approach:</p>

Expand All @@ -34,12 +34,11 @@ <h2 id="Working-with-the-filesystem">Working with the filesystem</h2>
console.log(data);
</code></pre>

<p> It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections and other events.</p>
<p> It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections or other events.</p>

<h2 id="File-information">File information</h2>

<p> The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we
are working with. In this example we are getting all the file objects in a directory and displaying whether they are a file or a
<p> The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we're working with. In this example, we're getting all the file objects in a directory and displaying whether they're a file or a
directory object.</p>

<pre><code>var fs = require('fs');
Expand All @@ -65,7 +64,7 @@ <h2 id="File-information">File information</h2>

<h2 id="Watching-files">Watching files</h2>

<p> The fs.watchfile monitors a file and will fire the event whenever the file is changed.</p>
<p> The fs.watchfile method monitors a file and fires an event whenever the file is changed.</p>

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

Expand All @@ -81,11 +80,11 @@ <h2 id="Watching-files">Watching files</h2>
});
</code></pre>

<p> A file can also be unwatched using the fs.unwatchFile method call. This is used once monitoring of a file is no longer required.</p>
<p> A file can also be unwatched using the fs.unwatchFile method call. This should be used once a file no longer needs to be monitored.</p>

<h2 id="Nodejs-Docs-for-further-reading">Nodejs Docs for further reading</h2>

<p> The node api <a href="http://nodejs.org/api.html#file-system-106">docs</a> are very detailed and list all the possible filesystem commands
<p> The node API <a href="http://nodejs.org/api.html#file-system-106">docs</a> are very detailed and list all the possible filesystem commands
available when working with Nodejs.</p>

</div>
26 changes: 8 additions & 18 deletions chapters/fs.md
@@ -1,11 +1,11 @@

# File System

To work with the filesystem, node provides the 'fs' module. The commands follow the POSIX operations, with most methods supporting an asynchronous and synchronous method call. We will look at how to use both and then establish which is the better option.
To work with the filesystem, node provides the "fs" module. The commands emulate the POSIX operations, and most methods work synchronously or asynchronously. We will look at how to use both, then establish which is the better option.

## Working with the filesystem

Lets start with a basic example of working with the filesystem, this example creates a directory, it then creates a file in it. Once the file has been created the contents of the file are written to console:
Lets start with a basic example of working with the filesystem. This example creates a directory, creates a file inside it, then writes the contents of the file to console:

var fs = require('fs');

Expand All @@ -23,7 +23,7 @@
});
});

As evident in the example above, each callback is placed in the previous callback - this is what is referred to as chainable callbacks. When using asynchronous methods this pattern should be used, as there is no guarantee that the operations will be completed in the order that they are created. This could lead to unpredictable behavior.
As evident in the example above, each callback is placed in the previous callback &mdash; these are referred to as chainable callbacks. This pattern should be followed when using asynchronous methods, as there's no guarantee that the operations will be completed in the order they're created. This could lead to unpredictable behavior.

The example can be rewritten to use a synchronous approach:

Expand All @@ -33,12 +33,11 @@
console.log('file created with contents:');
console.log(data);

It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections and other events.
It is better to use the asynchronous approach on servers with a high load, as the synchronous methods will cause the whole process to halt and wait for the operation to complete. This will block any incoming connections or other events.

## File information

The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we
are working with. In this example we are getting all the file objects in a directory and displaying whether they are a file or a
The fs.Stats object contains information about a particular file or directory. This can be used to determine what type of object we're working with. In this example, we're getting all the file objects in a directory and displaying whether they're a file or a
directory object.

var fs = require('fs');
Expand All @@ -64,7 +63,7 @@

## Watching files

The fs.watchfile monitors a file and will fire the event whenever the file is changed.
The fs.watchfile method monitors a file and fires an event whenever the file is changed.

var fs = require('fs');

Expand All @@ -79,18 +78,9 @@
console.log("file write complete");
});

A file can also be unwatched using the fs.unwatchFile method call. This is used once monitoring of a file is no longer required.

A file can also be unwatched using the fs.unwatchFile method call. This should be used once a file no longer needs to be monitored.

## Nodejs Docs for further reading

The node api [docs](http://nodejs.org/api.html#file-system-106) are very detailed and list all the possible filesystem commands
The node API [docs](http://nodejs.org/api.html#file-system-106) are very detailed and list all the possible filesystem commands
available when working with Nodejs.








0 comments on commit 15dc0e8

Please sign in to comment.