Skip to content

Commit a6b0301

Browse files
committed
Updated shell lab with image
1 parent caf5096 commit a6b0301

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

examples/shell.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var commands = {
3030
flags: 'r',
3131
encoding: 'utf8',
3232
mode: 0666,
33-
bufferSize: stats.blksize,
33+
bufferSize: 10,
3434
start: 0,
3535
end: stats.size
3636
};
@@ -39,7 +39,7 @@ var commands = {
3939
// Keep track of one extra newline
4040
// So we can start reading in the contents starting
4141
// at the next character
42-
var numLines = 1 + 1;
42+
var numLines = (args[1] || 10) + 1;
4343
var newLines = new Array(numLines);
4444
var index = 0;
4545

@@ -48,12 +48,12 @@ var commands = {
4848
fileStream.on('data', function (data) {
4949
for (var i = 0; i < data.length; i++) {
5050
if (data[i] === '\n') {
51-
newLines[index] = (offset * stats.blksize) + i;
51+
newLines[index] = offset + i;
5252
index = ++index % numLines;
5353
}
5454
}
55-
56-
offset++;
55+
console.log(offset);
56+
offset += data.length;
5757
});
5858

5959
fileStream.on('end', function () {
@@ -82,4 +82,4 @@ stdin.on('data', function (d) {
8282
var args = matches[2].trim().split(/\s+/);
8383

8484
commands[command](args);
85-
});
85+
});

labs/Shell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ In our callback we'll examine each character in the buffer to see if it's a newl
250250

251251
We'll create an array to store the byte offset of each newline for the last N+1 lines. The +1 is so we can keep around an extra trailing line to start reading from.
252252

253-
![Algorithm Explained](/path/to/img.jpg "An illustration of the algorithm in use.")
253+
![Algorithm Explained](https://raw.github.com/nodekc/workshop/master/labs/last4lines.png "An illustration of the algorithm in use.")
254254

255255
```js
256256
var numLines = (args[1] || 10) + 1;

0 commit comments

Comments
 (0)