Created
June 20, 2016 09:47
-
-
Save imchao9/a67a49e40e7cf55ac6d170696f5d12e9 to your computer and use it in GitHub Desktop.
nodejs下载文件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function downloadFile(url) { | |
| var httpClient = url.slice(0,5) === "https"? https:http; | |
| httpClient.get(url,function(response) { | |
| var RegFileName = new RegExp(); | |
| RegFileName.compile(".*%2F(.*?)$"); | |
| var fileName = RegFileName.exec(url)[1]; | |
| console.log(fileName); | |
| if(fileName) { | |
| var writer = fs.createWriteStream(resPath+fileName); | |
| response.pipe(writer); | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment