import FileUtil from './fileUtil'

export default {
  /**
   * 创建下载
   * @param data 数据
   * @param options 选项
   * @returns {string}
   */
  createDownloadUrl(data, options) {
    let blob = new Blob([data], options);
    return FileUtil.createObjectURL(blob);
  },
  /**
   * 创建下载链接
   * @param obj
   * @returns {string}
   */
  createObjectURL(obj){
    return window.URL.createObjectURL(obj);
  },
  /**
   * 下载文件
   * @param data
   * @param options
   * @param filename
   */
  download(data, options, filename){
    const url = FileUtil.createDownloadUrl(data,options);
    const a = document.createElement("a");
    a.target = "_black";
    a.download = filename;
    a.href = url;
    a.click();
  }
}
