       return
     ws.once 'close', ->
       fs.fsync fd, ->
-        if fd < 0
-          callback new Error 'Bad file descriptor'
-          tmpFile.unlink()
-          return
         try
           onEnd tmpFile, cascade, callback
         catch error

  ctx = canvas.getContext '2d'
  imageData = ctx.getImageData 0, 0, canvas.width, canvas.height
  data = imageData.data

  tmpFile = new temporary.File

  rs = canvas.pngStream()

onEnd = (tmpFile, cascade, callback) ->
  bin = path.join __dirname, '../build/Release/scddetect'
  exec "#{bin} #{tmpFile.path} #{cascade}", (err, stdout, stderr) ->
    if err
      callback err
      tmpFile.unlink()
