<commit_before>{open} = require 'io/file'

class Downloader
  constructor: (@url, @file, @callback) ->
    @_downloader = Cc["@mozilla.org/network/downloader;1"].createInstance()
    @_ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService)

    @_downloader.QueryInterface Ci.nsIDownloader
    @_downloader.init this, @file

  @::__defineGetter__ 'file', ->
    @_file

  @::__defineSetter__ 'file', (file) ->
    if file.path?
      @_file = file
    else
      @_file = open file

  #
  # Starts the download. This is the only public method for this class.
  #
  download: ->
    @_httpChannel = @_ioService.newChannel @url, '', null
    @_httpChannel.QueryInterface Ci.nsIHttpChannel
    @_httpChannel.asyncOpen @_downloader, null

  @download: (url, file, callback) ->
    (new Downloader url, file, callback).download()

  #
  # nsIDownloader delegate callback function.
  #
  onDownloadComplete: (dl, req, ctxt, status, file) ->
     try
       match = @_httpChannel.getResponseHeader('Content-Disposition').match(/filename="([^"]+)"/i)
       suggestedFilename = match?[1]
     catch err
       match = url.match(/.+\/([^\/\?]+)/)
       suggestedFilename = match?[1]

     wesabe.callback @callback, req.status is 0, [file, suggestedFilename]

     delete @_httpChannel
     delete @_downloader
     delete @_ioService
     delete @callback


module.exports = Downloader<commit_msg>Missed another local that should be an ivar.<commit_after>{open} = require 'io/file'

class Downloader
  constructor: (@url, @file, @callback) ->
    @_downloader = Cc["@mozilla.org/network/downloader;1"].createInstance()
    @_ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService)

    @_downloader.QueryInterface Ci.nsIDownloader
    @_downloader.init this, @file

  @::__defineGetter__ 'file', ->
    @_file

  @::__defineSetter__ 'file', (file) ->
    if file.path?
      @_file = file
    else
      @_file = open file

  #
  # Starts the download. This is the only public method for this class.
  #
  download: ->
    @_httpChannel = @_ioService.newChannel @url, '', null
    @_httpChannel.QueryInterface Ci.nsIHttpChannel
    @_httpChannel.asyncOpen @_downloader, null

  @download: (url, file, callback) ->
    (new Downloader url, file, callback).download()

  #
  # nsIDownloader delegate callback function.
  #
  onDownloadComplete: (dl, req, ctxt, status, file) ->
     try
       match = @_httpChannel.getResponseHeader('Content-Disposition').match(/filename="([^"]+)"/i)
       suggestedFilename = match?[1]
     catch err
       match = @url.match(/.+\/([^\/\?]+)/)
       suggestedFilename = match?[1]

     wesabe.callback @callback, req.status is 0, [file, suggestedFilename]

     delete @_httpChannel
     delete @_downloader
     delete @_ioService
     delete @callback


module.exports = Downloader
{'fraction_non_alphanumeric': 0.13906359189378056, 'fraction_numerical': 0.0034940600978336828, 'mean_word_length': 3.3576864535768647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1786815', 'n_tokens_mistral': 939, 'n_tokens_neox': 916, 'n_words': 208}