/*!
 * istanbul-coveralls | MIT (c) Shinnosuke Watanabe
 * https://github.com/shinnn/node-strip-dirs
*/

'use strict';

var fs = require('fs');

var handleInput = require('coveralls').handleInput;
var rimraf = require('rimraf');

module.exports = function istanbulCoveralls(_option, _cb) {
  var cb;
  var option;
  if (_cb === undefined) {
    cb = _option;
    option = {rimraf: true};
  } else {
    option = _option;
    cb = _cb;
  }

  fs.readFile('./coverage/lcov.info', {encoding: 'utf-8'}, function(err, buf) {
    if (err) {
      cb(err);
      return;
    }

    handleInput(buf.toString(), function(msg) {
      if (msg) {
        cb(new Error(msg));
        return;
      }

      if (option.rimraf) {
        rimraf('./coverage', cb);
      } else {
        cb();
      }
    });
  });
};

@@ -82,22 +82,25 @@
 nnn/
-node-strip-dir
+istanbul-coverall
 s%0A*/
@@ -283,25 +283,14 @@
 on, 
-_
 cb) %7B%0A
-  var cb;%0A
   va
@@ -305,17 +305,16 @@
 ;%0A  if (
-_
 cb === u
@@ -409,22 +409,8 @@
 on;%0A
-    cb = _cb;%0A
   %7D%0A

handle arguments more simply