From 2ac0e575a15179f56edbc038937e62788579ccc1 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 21 Mar 2015 13:22:51 +0100 Subject: [PATCH] Changé de line-reader --- app/controllers/noms.js | 38 +++++++++++++++++++------------------- package.json | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/controllers/noms.js b/app/controllers/noms.js index 134070f..85b6850 100644 --- a/app/controllers/noms.js +++ b/app/controllers/noms.js @@ -1,5 +1,6 @@ var Noms = require('../models/noms'); -var lineReader = require('line-reader'); +var LineTransform = require('node-line-reader').LineTransform; +var fs = require('fs') var noms = {} @@ -15,26 +16,25 @@ noms.get = function (login, cb) { cb(nom.nom) } else { found = false - try { - lineReader.eachLine('config/passwd', function (line, last, cbL) { - ex = line.split(':') - // console.log(ex); - if (ex[0] == login) { // Si trouvé - found = true - cb(ex[4]) - cbL(false); - } else { - cbL(); - } - }).then(function () { - if (!found) { - cb(false) - } - }); - } catch (e) { + stream = fs.createReadStream('config/passwd') + transform = new LineTransform() + stream.pipe(transform) + transform.on('data', function (line) { + ex = line.split(':') + if (ex[0] == login) { // Si trouvé + found = true + cb(ex[4]) + } + }) + transform.on('end', function () { + if (!found) { + cb(false) + } + }) + transform.on('error', function (e) { console.error("Error while fetching name", e) cb(login.toUpperCase()) - } + }) } } }) diff --git a/package.json b/package.json index efcd9e2..4c078c3 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "body-parser": "^1.12.0", "cookie-parser": "^1.3.4", "express": "^4.12.2", - "line-reader": "^0.2.4", "method-override": "^2.3.1", "mongoose": "^3.8.25", - "morgan": "^1.5.1" + "morgan": "^1.5.1", + "node-line-reader": "0.0.2" } } -- libgit2 0.21.2