   queue.drain = callback
 
 getAvailable = (callback) ->
-  apm = require.resolve '.bin/apm'
-  apmProcess = spawn(apm, ['available', '--json'])
-  chunks = []
-  apmProcess.stdout.on 'data', (chunk) -> chunks.push(chunk)
-  apmProcess.on 'close', (code) ->
+  command = require.resolve '.bin/apm'
+  args = ['available', '--json']
+  output = []
+  stdout = (lines) -> output.push(lines)
+  exit = (code) ->
     if code is 0
       try
-        packages = JSON.parse(Buffer.concat(chunks).toString()) ? []
+        packages = JSON.parse(output.join()) ? []
       catch error
         callback(error)
         return

{spawn} = require 'child_process'
roaster = require 'roaster'
async = require 'async'


      actom.activatePackage(name) if activateOnFailure
      callback(new Error("Installing '#{name}' failed."))

  new BufferedProcess({command, args, exit})

uninstall = ({name}, callback) ->
  atom.deactivatePackage(name) if atom.isPackageActive(name)

  command = require.resolve '.bin/apm'
  args = ['uninstall', name]
  exit = (code) ->
    if code is 0
      atom.unloadPackage(name) if atom.isPackageLoaded(name)
      callback()
    else
      callback(new Error("Uninstalling '#{name}' failed."))

  new BufferedProcess({command, args, exit})

module.exports = {renderMarkdownInMetadata, install, uninstall, getAvailable}
