{"id":13431205,"url":"https://github.com/rndme/download","last_synced_at":"2025-05-14T01:11:36.695Z","repository":{"id":21492248,"uuid":"24811136","full_name":"rndme/download","owner":"rndme","description":"file downloading using client-side javascript","archived":false,"fork":false,"pushed_at":"2023-05-13T19:25:04.000Z","size":71,"stargazers_count":2314,"open_issues_count":50,"forks_count":414,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-05-10T06:04:59.843Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rndme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-05T07:59:38.000Z","updated_at":"2025-05-08T08:02:37.000Z","dependencies_parsed_at":"2024-06-12T16:42:59.412Z","dependency_job_id":"eb4cc269-e9e5-43b5-be55-d6c458f9e3f1","html_url":"https://github.com/rndme/download","commit_stats":{"total_commits":68,"total_committers":13,"mean_commits":5.230769230769231,"dds":"0.32352941176470584","last_synced_commit":"09d6492f47ef18feca39c3d748960dce44f93a89"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndme%2Fdownload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndme%2Fdownload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndme%2Fdownload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rndme%2Fdownload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rndme","download_url":"https://codeload.github.com/rndme/download/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253633114,"owners_count":21939389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:01:01.320Z","updated_at":"2025-05-14T01:11:31.684Z","avatar_url":"https://github.com/rndme.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","脚手架以及工具包","38. 下载组件"],"sub_categories":["24.3 Web Sockets"],"readme":"# download \n\n[![NPM version][npm-image]][npm-url] \n[![Size][size-image]][size-url] \n[![License][license-image]][license-url] \n[![CDNJS](https://img.shields.io/cdnjs/v/downloadjs.svg)](https://cdnjs.com/libraries/downloadjs)\n\n\n## Summary\n---------\nThe download() function is used to trigger a file download from JavaScript. \n\nIt specifies the contents and name of a new file placed in the browser's download directory. The input can be a URL, String, Blob, or Typed Array of data, or via a dataURL representing the file's data as base64 or url-encoded string. No matter the input format, download() saves a file using the specified file name and mime information in the same manner as a server using a Content-Disposition HTTP header.\n\n## Getting and Using\n---------\n\n### Via NPM/Bower \n`npm install downloadjs`  \u003cbr /\u003e\n`bower install downloadjs`\n\n`require(\"downloadjs\")(data, strFileName, strMimeType);`\n\n### Simple global `download` function via `\u003cscript\u003e` include\n    download(data, strFileName, strMimeType);\n\n### Included via AMD\n    require(['path/to/file'], function(download) {\n        download(data, strFileName, strMimeType);\n    });\n\n\n### Parameters\n---------\n* **data** - The Blob, File, String, or dataURL containing the soon-to-be File's contents.\n* **strFileName** - The name of the file to be created. Note that older browsers (like FF3.5, Ch5) don't honor the file name you provide, instead they automatically name the downloaded file.\n* **strMimeType** - The MIME content-type of the file to download. While optional, it helps the browser present friendlier information about the download to the user, encouraging them to accept the download.\n\n\n\n## Example Usage\n---------\n\n\n### Plain Text\n#### text string  -  [live demo](http://pagedemos.com/hw24em95rsfq/output/)\n    download(\"hello world\", \"dlText.txt\", \"text/plain\");\n\n#### text dataURL  -  [live demo](http://pagedemos.com/r9ywm98s6b29/output/)\n    download(\"data:text/plain,hello%20world\", \"dlDataUrlText.txt\", \"text/plain\");\n\n#### text blob  -  [live demo](http://pagedemos.com/ckcah2vp8kza/output/)\n    download(new Blob([\"hello world\"]), \"dlTextBlob.txt\", \"text/plain\");\n\n#### text url - [live demo](http://pagedemos.com/pz6hkyqutjtw/output/)\n    download(\"/robots.txt\");\n\n\n#### text UInt8 Array -  [live demo](http://pagedemos.com/zuyk46wbkktq/output/)\n    var str= \"hello world\",\tarr= new Uint8Array(str.length);\n    str.split(\"\").forEach(function(a,b){\n   \t  arr[b]=a.charCodeAt();\n    });\n\n    download( arr, \"textUInt8Array.txt\", \"text/plain\" );\n\n### HTML\n#### html string -  [live demo](http://pagedemos.com/k7rwq7msu3eb/output/)\n    download(document.documentElement.outerHTML, \"dlHTML.html\", \"text/html\");\n\n#### html Blob -  [live demo](http://pagedemos.com/bxehm2fdf3g4/output/)\n    download(new Blob([\"hello world\".bold()]), \"dlHtmlBlob.html\", \"text/html\");\n\n#### ajax callback -  [live demo](http://pagedemos.com/arr2ym74aw8t/output/)\n(note that callback mode won't work on vanilla ajax or with binary files)\n   \n    $.ajax({\n    \t\turl: \"/download.html\",\n    \t\tsuccess: download.bind(true, \"text/html\", \"dlAjaxCallback.html\")\n    });\n\n\n### Binary Files\n#### image from URL  -  [live demo](http://pagedemos.com/yvvmxbjrwq7u/output/)\n    download(\"/diff6.png\");\n\n#### Image via ajax for custom filename - [live demo](http://pagedemos.com/v2848zfgwrju/output/)\n\tvar x=new XMLHttpRequest();\n\tx.open( \"GET\", \"/diff6.png\" , true);\n\tx.responseType=\"blob\";\n\tx.onload= function(e){download(e.target.response, \"awesomesauce.png\", \"image/png\");};\n\tx.send();\n\n\n## Compatibility\n---------\ndownload.js works with a wide range of devices and browsers.\n\nYou can expect it to work for the vast majority of your users, with some common-sense limits:\n\n* Devices without file systems like iPhone, iPad, Wii, et al. have nowhere to save the file to, sorry.\n* Android support starts at 4.2 for the built-in browser, though chrome 36+ and firefox 20+ on android 2.3+ work well.\n* Devices without Blob support won't be able to download Blobs or TypedArrays\n* Legacy devices (no a[download]) support can only download a few hundred kilobytes of data, and can't give the file a custom name.\n* Devices without window.URL support can only download a couple megabytes of data\n* IE versions of 9 and before are NOT supported because the don't support a[download] or dataURL frame locations.\n\n\n## FAQ\n---------\n\n * `Can I tell when a download is done/canceled?` No.\n * `How can I style the temporary download link?` Define CSS class styles for `.download-js-link`.\n * `What's up with Safari?` I don't know either but pull requests that improve the situation are welcome.\n * `Why is my binary file corrupted?` Likely: an incorrect MIME or using jQuery ajax, which has no bin support.\n * `How big of files work?` Depends, try yourself: [File Echo Demo](http://pagedemos.com/gqs6hbmjcpem/)... I do a 1GB dl routinely on a thinkpad...\n\n\n## Change Log (v4.1)\n---------\n* 2008 :: landed a FF+Chrome compatible way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime\n* 2012 :: added named files via a[download], msSaveBlob() for IE (10+) support, and window.URL support for larger+faster saves than dataURLs\n* 2014 :: added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support\n* 2015 :: converted to amd/commonJS module with browser-friendly fallback\n* 2015 :: 4.1 added direct URL downloading via a single URL argument.\n* 2016 :: 4.2 added large dataURL support, a more semantic codebase, and hidden temp links\n* 2017 :: added support for empty dataURLs\n* 20XX :: ???? Considering Zip, Tar, and other multi-file outputs, Blob.prototype.download option, and more, stay tuned folks.\n\n\n[MIT license]: http://opensource.org/licenses/MIT\n[npm-image]: https://badge.fury.io/js/downloadjs.svg\n[npm-url]: https://npmjs.org/package/downloadjs\n[license-image]: https://img.shields.io/badge/license-MIT-green.svg\n[license-url]: http://opensource.org/licenses/MIT\n[size-image]: http://img.badgesize.io/rndme/download/master/download.min.js.svg?compression=gzip\u0026label=gzip%20size\n[size-url]: https://unpkg.com/downloadjs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frndme%2Fdownload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frndme%2Fdownload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frndme%2Fdownload/lists"}