code: function _endDownload(downloadId, error) {
      var downloadInfo = pendingDownloads[downloadId];
      delete pendingDownloads[downloadId];
  
      if (error) {
          // Abort the download if still pending
          // Note that this will trigger response's "end" event
          downloadInfo.request.abort();
  
          // Clean up any partially-downloaded file
          // (if no outStream, then we never got a response back yet and never created any file)
          if (downloadInfo.outStream) {
              downloadInfo.outStream.end(function () {
                  fs.unlink(downloadInfo.localPath);
              });
          }
  
          downloadInfo.callback(error, null);
  
      } else {
          // Download completed successfully. Flush stream to disk and THEN signal completion
          downloadInfo.outStream.end(function () {
              downloadInfo.callback(null, downloadInfo.localPath);
          });
      }
  }
docs: Wrap up after the given download has terminated (successfully or not). Closes connections, calls back the
  client's callback, and IF there was an error, delete any partially-downloaded file.
  
  @param {string} downloadId Unique id originally passed to _cmdDownloadFile()
  @param {?string} error If null, download was treated as successful