index.js
function search(stream, needle) {

  var ss = new streamsearch(needle),
      push = ss.push.bind(ss);
  ss.maxMatches = 1;

  var defered = defer();
  stream.on("data", push);

  stream.once("finish", function(){
    defered.reject("No stub found in stream")
  });

  var pos = 0;

  ss.on("info", function(isMatch, data, start, end){
    if(data)
      pos += end - start;

    if(!isMatch)
      return;

    stream.removeListener("data", push);
    defered.resolve(pos);
  });
  return defered;
}
function search(stream, needle) {

  var ss = new streamsearch(needle),
      push = ss.push.bind(ss);
  ss.maxMatches = 1;

  var defered = defer();
  stream.on("data", push);

  stream.once("finish", function(){
    defered.reject("No stub found in stream")
  });

  var pos = 0;

  ss.on("info", function(isMatch, data, start, end){
    if(data)
      pos += end - start;

    if(!isMatch)
      return;

    stream.removeListener("data", push);
    defered.resolve(pos);
  });
  return defered;
}
function search ( stream , needle ) { var ss = new streamsearch ( needle ) , push = ss . push . bind ( ss ) ; ss . maxMatches = 1 ; var defered = defer ( ) ; stream . on ( "data" , push ) ; stream . once ( "finish" , function ( ) { defered . reject ( "No stub found in stream" ) } ) ; var pos = 0 ; ss . on ( "info" , function ( isMatch , data , start , end ) { if ( data ) pos += end - start ; if ( ! isMatch ) return ; stream . removeListener ( "data" , push ) ; defered . resolve ( pos ) ; } ) ; return defered ; }
search for a stub in a stream, return a promise
search for a stub in a stream return a promise