 csvParse = require 'csv-parse'
 fs = require 'fs'
 _ = require 'lodash'
+Q = require 'q'
 
-exports.f = f = (input, callback) ->
-  csvParse input, (err, data) ->
-    callback err if err
+exports.f = f = (input) ->
+  Q.nfcall csvParse, input
+  .then (data) ->
     filtered = _.filter data, (i) ->
       1 < i.length
     ret = {}

        min: parseFloat line[3]
        volume: parseFloat line[5]
        amount: parseFloat line[6]
    callback null, ret

exports.io = io = (inputFile, outputFile) ->
  fs.readFile inputFile, encoding: 'ascii', (err, data) ->
    throw err if err
    f data, (err, data) ->
      throw err if err
      fs.writeFile outputFile, JSON.stringify(data), encoding: 'ascii', (err) ->
        throw err if err

if require.main == module
  do ->

      help: 'output file'
      required: true
    args = parser.parseArgs()
    sync args.input, args.output
    .done()
