ln-stream

1.0.2 • Public • Published

ln-stream

for each line processor

attach proc for a line and defer the post-processor

lnstream = require('ln-stream')
lnstream(filename, proc, defer)

wc-like program

lnstream = require 'ln-stream'
 
lines = 0
words = 0
chars = 0
 
# processer for each line 
proc = (line) ->
  lines += 1
  words += line.split ' '
               .length
  chars += line.length
 
# after the all lines 
defer = () ->
  console.log "%d %d %d"lineswordschars
 
lnstream './README.md'procdefer
 
# => 36 120 504 

simple multi-process (pseudo)

To realize true multi-process, you can use the functions in child_process.

seq 1000 1003 > list
proc = (id) ->
  setTimeout (-> console.log id)id
lnstream './list'proc(-> 0)
[bash] $ time coffee test.coffee
1000
1001
1002
1003

real    0m1.197s
user    0m0.113s
sys     0m0.036s

Readme

Keywords

Package Sidebar

Install

npm i ln-stream

Weekly Downloads

1

Version

1.0.2

License

BSD-2-Clause

Last publish

Collaborators

  • cympfh