Commit 2ac0e575a15179f56edbc038937e62788579ccc1
1 parent
65ecbfc6
Changé de line-reader
L'autre ne semblait pas gérer les erreurs. Enfin je crois, GitHub était down pour 15 minutes donc dans le doute, j'ai changé.
Showing
2 changed files
with
21 additions
and
21 deletions
Show diff stats
app/controllers/noms.js
1 | 1 | var Noms = require('../models/noms'); |
2 | -var lineReader = require('line-reader'); | |
2 | +var LineTransform = require('node-line-reader').LineTransform; | |
3 | +var fs = require('fs') | |
3 | 4 | |
4 | 5 | var noms = {} |
5 | 6 | |
... | ... | @@ -15,26 +16,25 @@ noms.get = function (login, cb) { |
15 | 16 | cb(nom.nom) |
16 | 17 | } else { |
17 | 18 | found = false |
18 | - try { | |
19 | - lineReader.eachLine('config/passwd', function (line, last, cbL) { | |
20 | - ex = line.split(':') | |
21 | - // console.log(ex); | |
22 | - if (ex[0] == login) { // Si trouvé | |
23 | - found = true | |
24 | - cb(ex[4]) | |
25 | - cbL(false); | |
26 | - } else { | |
27 | - cbL(); | |
28 | - } | |
29 | - }).then(function () { | |
30 | - if (!found) { | |
31 | - cb(false) | |
32 | - } | |
33 | - }); | |
34 | - } catch (e) { | |
19 | + stream = fs.createReadStream('config/passwd') | |
20 | + transform = new LineTransform() | |
21 | + stream.pipe(transform) | |
22 | + transform.on('data', function (line) { | |
23 | + ex = line.split(':') | |
24 | + if (ex[0] == login) { // Si trouvé | |
25 | + found = true | |
26 | + cb(ex[4]) | |
27 | + } | |
28 | + }) | |
29 | + transform.on('end', function () { | |
30 | + if (!found) { | |
31 | + cb(false) | |
32 | + } | |
33 | + }) | |
34 | + transform.on('error', function (e) { | |
35 | 35 | console.error("Error while fetching name", e) |
36 | 36 | cb(login.toUpperCase()) |
37 | - } | |
37 | + }) | |
38 | 38 | } |
39 | 39 | } |
40 | 40 | }) | ... | ... |
package.json
... | ... | @@ -5,9 +5,9 @@ |
5 | 5 | "body-parser": "^1.12.0", |
6 | 6 | "cookie-parser": "^1.3.4", |
7 | 7 | "express": "^4.12.2", |
8 | - "line-reader": "^0.2.4", | |
9 | 8 | "method-override": "^2.3.1", |
10 | 9 | "mongoose": "^3.8.25", |
11 | - "morgan": "^1.5.1" | |
10 | + "morgan": "^1.5.1", | |
11 | + "node-line-reader": "0.0.2" | |
12 | 12 | } |
13 | 13 | } | ... | ... |