Permalink
Browse files

tutorial review

  • Loading branch information...
1 parent 015646b commit ae372d3b49d19ef58052148e4ea77f0ab60b0268 @bjouhier bjouhier committed Jul 1, 2012
View
@@ -2,8 +2,9 @@
var streams = require('streamline/lib/streams/server/streams');
streams.createHttpServer(function(request, response, _) {
- response.writeHead(200, {'Content-Type': 'text/plain'});
+ response.writeHead(200, {
+ 'Content-Type': 'text/plain; charset=utf8'
+ });
response.end("Hello world!");
-
}).listen(_, 1337);
-console.log('Server running at http://127.0.0.1:1337/');
+console.log('Server running at http://127.0.0.1:1337/');
View
@@ -14,7 +14,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
@@ -14,7 +14,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
View
@@ -14,7 +14,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
View
@@ -15,7 +15,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
@@ -55,13 +55,14 @@ function fileSearch(_, q) {
function doDir(_, dir) {
fs.readdir(dir, _).forEach_(_, function(_, file) {
- var stat = fs.stat(dir + '/' + file, _);
+ var f = dir + '/' + file;
+ var stat = fs.stat(f, _);
if (stat.isFile()) {
- fs.readFile(dir + '/' + file, 'utf8', _).split('\n').forEach(function(line, i) {
- if (line.indexOf(q) >= 0) results += '<br/>' + dir + '/' + file + ':' + i + ':' + line;
+ fs.readFile(f, 'utf8', _).split('\n').forEach(function(line, i) {
+ if (line.indexOf(q) >= 0) results += '<br/>' + f + ':' + i + ':' + line;
});
} else if (stat.isDirectory()) {
- doDir(_, dir + '/' + file);
+ doDir(_, f);
}
});
}
View
@@ -14,7 +14,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
@@ -58,13 +58,14 @@ function fileSearch(_, q) {
function doDir(_, dir) {
fs.readdir(dir, _).forEach_(_, function(_, file) {
- var stat = fs.stat(dir + '/' + file, _);
+ var f = dir + '/' + file;
+ var stat = fs.stat(f, _);
if (stat.isFile()) {
- fs.readFile(dir + '/' + file, 'utf8', _).split('\n').forEach(function(line, i) {
- if (line.indexOf(q) >= 0) results += '<br/>' + dir + '/' + file + ':' + i + ':' + line;
+ fs.readFile(f, 'utf8', _).split('\n').forEach(function(line, i) {
+ if (line.indexOf(q) >= 0) results += '<br/>' + f + ':' + i + ':' + line;
});
} else if (stat.isDirectory()) {
- doDir(_, dir + '/' + file);
+ doDir(_, f);
}
});
}
@@ -14,7 +14,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));
@@ -66,16 +66,17 @@ function fileSearch(_, q) {
function doDir(_, dir) {
fs.readdir(dir, _).forEach_(_, -1, function(_, file) {
- var stat = fs.stat(dir + '/' + file, _);
+ var f = dir + '/' + file;
+ var stat = fs.stat(f, _);
if (stat.isFile()) {
// use the funnel to limit the number of open files
filesFunnel(_, function(_) {
- fs.readFile(dir + '/' + file, 'utf8', _).split('\n').forEach(function(line, i) {
- if (line.indexOf(q) >= 0) results += '<br/>' + dir + '/' + file + ':' + i + ':' + line;
+ fs.readFile(f, 'utf8', _).split('\n').forEach(function(line, i) {
+ if (line.indexOf(q) >= 0) results += '<br/>' + f + ':' + i + ':' + line;
});
});
} else if (stat.isDirectory()) {
- doDir(_, dir + '/' + file);
+ doDir(_, f);
}
});
}
View
@@ -12,7 +12,9 @@ Let us start with streamline's version of node's hello world:
var streams = require('streamline/lib/streams/server/streams');
streams.createHttpServer(function(request, response, _) {
- response.writeHead(200, {'Content-Type': 'text/plain'});
+ response.writeHead(200, {
+ 'Content-Type': 'text/plain; charset=utf8'
+ });
response.end("Hello world!");
}).listen(_, 1337);
@@ -56,7 +58,7 @@ streams.createHttpServer(function(request, response, _) {
var query = qs.parse(url.parse(request.url).query),
t0 = new Date();
response.writeHead(200, {
- 'Content-Type': 'text/html'
+ 'Content-Type': 'text/html; charset=utf8'
});
response.write(_, begPage.replace('{q}', query.q || ''));
response.write(_, search(_, query.q));

0 comments on commit ae372d3

Please sign in to comment.