Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more efficient youtube-dl download

  • Loading branch information...
commit 574cd7f71eab9fb2c6cb506ce2b45be1804fb8ed 1 parent 05c2ba3
@fent fent authored
Showing with 12 additions and 18 deletions.
  1. +12 −18 scripts/download.js
View
30 scripts/download.js
@@ -4,11 +4,18 @@ var fs = require('fs')
, exec = require('child_process').exec
-var folder = path.join(__dirname, '..', 'bin')
- , filename = '/youtube-dl'
- , filepath = folder + filename
+var dir = path.join(__dirname, '..', 'bin')
+ , filename = 'youtube-dl'
+ , filepath = path.join(dir, filename)
+ , n = 0
+ ;
+// make bin dir if it doesn't exists
+if (!path.existsSync(dir)) {
+ fs.mkdirSync(dir, 0744);
+}
+
// download latst version of youtube-dl
https.get({
host: 'raw.github.com'
@@ -18,23 +25,10 @@ https.get({
throw Error('Response Error: ' + res.statusCode);
}
- var content = '';
- res.on('data', function(data) {
- return content += data;
- });
-
+ res.pipe(fs.createWriteStream(filepath));
res.on('end', function() {
- // make bin folder if it doesn't exists
- if (!path.existsSync(folder)) {
- fs.mkdirSync(folder, 0744);
- }
-
- // write file when finished
- fs.writeFileSync(filepath, content);
-
- // make it executable
+ // make file executable
fs.chmodSync(filepath, 0711);
-
console.log('Finished!');
});
Please sign in to comment.
Something went wrong with that request. Please try again.