<commit_before>import { fileToUrl } from 'uni-platform/helpers/file'
/**
 * 下载任务
 */
class DownloadTask {
  _xhr
  _callbacks = []
  constructor (xhr) {
    this._xhr = xhr
  }
  /**
   * 监听下载进度
   * @param {Function} callback 回调
   */
  onProgressUpdate (callback) {
    if (typeof callback !== 'function') {
      return
    }
    this._callbacks.push(callback)
  }
  /**
   * 停止任务
   */
  abort () {
    if (this._xhr) {
      this._xhr.abort()
      delete this._xhr
    }
  }
}
/**
 * 下载文件
 * @param {*} param0
 * @param {string} callbackId
 * @return {DownloadTask}
 */
export function downloadFile ({
  url,
  header
}, callbackId) {
  var timeout = (__uniConfig.networkTimeout && __uniConfig.networkTimeout.downloadFile) || 60 * 1000
  const {
    invokeCallbackHandler: invoke
  } = UniServiceJSBridge
  var timer
  var xhr = new XMLHttpRequest()
  var downloadTask = new DownloadTask(xhr)<commit_msg>fix: H5 DownloadTask 支持 offProgressUpdate<commit_after>import { fileToUrl } from 'uni-platform/helpers/file'
/**
 * 下载任务
 */
class DownloadTask {
  _xhr
  _callbacks = []
  constructor (xhr) {
    this._xhr = xhr
  }
  /**
   * 监听下载进度
   * @param {Function} callback 回调
   */
  onProgressUpdate (callback) {
    if (typeof callback !== 'function') {
      return
    }
    this._callbacks.push(callback)
  }
  offProgressUpdate (callback) {
    const index = this._callbacks.indexOf(callback)
    if (index >= 0) {
      this._callbacks.splice(index, 1)
    }
  }
  /**
   * 停止任务
   */
  abort () {
    if (this._xhr) {
      this._xhr.abort()
      delete this._xhr
    }
  }
}
/**
 * 下载文件
 * @param {*} param0
 * @param {string} callbackId
 * @return {DownloadTask}
 */
export function downloadFile ({
  url,
  header
}, callbackId) {
  var timeout = (__uniConfig.networkTimeout && __uniConfig.networkTimeout.downloadFile) || 60 * 1000
  const {
    invokeCallbackHandler: invoke
  } = UniServiceJSBridge
  var timer
  var xhr = new XMLHttpRequest()
  var downloadTask = new DownloadTask(xhr)
{'fraction_non_alphanumeric': 0.1312375249500998, 'fraction_numerical': 0.008483033932135729, 'mean_word_length': 2.8190476190476192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1366808', 'n_tokens_mistral': 724, 'n_tokens_neox': 724, 'n_words': 147}