Я предвосхищу это, сказав, что я сам не использовал Lazy, а просто посмотрел документы.
Я ожидал, что Lazy выдаст событие 'end', но я не могу сказать, так ли это, в любом случае вы можете привязать обратный вызов непосредственно к событию end в потоке чтения.
each_line = (file, callback, eof_callback) ->
last_line = null
stream = fs.createReadStream file
stream.on 'end', eof_callback
lazy = Lazy(stream).lines.map(String).filter (line) ->
not (
# Filter the not interesting rows in the top of the file
/^html$/i.test(line) or
/^\s+body$/i.test(line) or
/^\s+\/\/\s+Generator.*$/i.test(line)
)
lazy.forEach (line) ->
# We only emit those lines that are whole lines, multilines will become joined
if /^\t/g.test(line)
last_line += line.replace(/\t/g, '').replace(/(\r\n|\n|\r)/gm," ")
else
callback(last_line) if last_line
last_line = line.replace(/(\r\n|\n|\r)/gm," ")