Last active
August 29, 2015 14:05
-
-
Save dead-horse/6705119f1a2d41c48899 to your computer and use it in GitHub Desktop.
This file contains 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
var mkdirp = require('mkdirp'); | |
var http = require('http'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var tmp = path.join(__dirname, 't.tgz'); | |
var opts = { | |
hostname: 'cnpm.oss.aliyuncs.com', | |
method: 'GET', | |
port: 80, | |
path: '/cutter/-/cutter-0.0.3.tgz' | |
} | |
http.request(opts, function (res) { | |
res.resume(); | |
res.pause(); | |
mkdirp(path.dirname(tmp), function () { | |
var tarball = fs.createWriteStream(tmp, { mode: 420 }) | |
tarball.on('finish', function () { | |
console.log('tarball finish'); | |
}) | |
res.on('data', function (data) { | |
console.log('res on data: %s', data.length); | |
}) | |
res.on('end', function (d) { | |
console.log('res end'); | |
}) | |
res.resume(); | |
res.pipe(tarball); | |
}); | |
}).end(); |
This file contains 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
var mkdirp = require('mkdirp'); | |
var http = require('http'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var tmp = path.join(__dirname, 't.tgz'); | |
var opts = { | |
hostname: 'cnpm.oss.aliyuncs.com', | |
method: 'GET', | |
port: 80, | |
path: '/cutter/-/cutter-0.0.3.tgz' | |
} | |
http.request(opts, function (res) { | |
res.resume(); | |
res.pause(); | |
mkdirp.sync(path.dirname(tmp)); | |
var tarball = fs.createWriteStream(tmp, { mode: 420 }) | |
tarball.on('finish', function () { | |
console.log('tarball finish'); | |
}) | |
res.on('data', function (data) { | |
console.log('res on data: %s', data.length); | |
}) | |
res.on('end', function (d) { | |
console.log('res end'); | |
}) | |
res.resume(); | |
res.pipe(tarball); | |
}).end(); |
This file contains 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
var mkdirp = require('mkdirp'); | |
var request = require('request'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var tmp = path.join(__dirname, 't.tgz'); | |
var opts = | |
{ url: | |
{ protocol: 'http:', | |
slashes: true, | |
auth: null, | |
host: 'registry.npm.taobao.org', | |
port: null, | |
hostname: 'registry.npm.taobao.org', | |
hash: null, | |
search: null, | |
query: null, | |
pathname: '/cutter/download/cutter-0.0.3.tgz', | |
path: '/cutter/download/cutter-0.0.3.tgz', | |
href: 'http://registry.npm.taobao.org/cutter/download/cutter-0.0.3.tgz' }, | |
method: 'GET', | |
headers: | |
{ version: '2.0.0-alpha.6.0', | |
accept: 'application/x-tar', | |
referer: 'install cutter', | |
'npm-session': '79b8279ef0bb4df9', | |
'user-agent': 'npm/2.0.0-alpha.6.0 node/v0.10.29 darwin x64' }, | |
strictSSL: true, | |
followRedirect: true } | |
var req = request(opts); | |
req.on('response', function (res) { | |
res.resume(); | |
res.pause(); | |
mkdirp(path.dirname(tmp), function () { | |
var tarball = fs.createWriteStream(tmp, { mode: 420 }) | |
tarball.on('finish', function () { | |
console.log('tarball finish'); | |
}) | |
res.on('data', function (data) { | |
console.log('res on data: %s', data.length); | |
}) | |
res.on('end', function (d) { | |
console.log('res end') | |
}) | |
res.resume(); | |
res.pipe(tarball); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment