mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
always return content-length for tarballs
This commit is contained in:
parent
9c4c93695b
commit
a891354a32
5 changed files with 36 additions and 4 deletions
|
@ -161,10 +161,13 @@ module.exports = function(config_hash) {
|
||||||
|
|
||||||
app.get('/:package/-/:filename', can('access'), function(req, res, next) {
|
app.get('/:package/-/:filename', can('access'), function(req, res, next) {
|
||||||
var stream = storage.get_tarball(req.params.package, req.params.filename)
|
var stream = storage.get_tarball(req.params.package, req.params.filename)
|
||||||
|
stream.on('content-length', function(v) {
|
||||||
|
res.header('Content-Length', v)
|
||||||
|
})
|
||||||
stream.on('error', function(err) {
|
stream.on('error', function(err) {
|
||||||
return res.report_error(err)
|
return res.report_error(err)
|
||||||
})
|
})
|
||||||
res.header('content-type', 'application/octet-stream')
|
res.header('Content-Type', 'application/octet-stream')
|
||||||
stream.pipe(res)
|
stream.pipe(res)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,24 @@ function write_stream(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_stream(name, stream, callback) {
|
function read_stream(name, stream, callback) {
|
||||||
return fs.createReadStream(name)
|
var rstream = fs.createReadStream(name)
|
||||||
|
rstream.on('error', function(err) {
|
||||||
|
stream.emit('error', err)
|
||||||
|
})
|
||||||
|
rstream.on('open', function(fd) {
|
||||||
|
fs.fstat(fd, function(err, stats) {
|
||||||
|
if (err) return stream.emit('error', err)
|
||||||
|
stream.emit('content-length', stats.size)
|
||||||
|
stream.emit('open')
|
||||||
|
rstream.pipe(stream)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
var stream = new mystreams.ReadTarballStream()
|
||||||
|
stream.abort = function() {
|
||||||
|
rstream.close()
|
||||||
|
}
|
||||||
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(name, contents, callback) {
|
function create(name, contents, callback) {
|
||||||
|
|
|
@ -381,7 +381,7 @@ Storage.prototype.get_tarball = function(name, filename, callback) {
|
||||||
|
|
||||||
var stream = new mystreams.ReadTarballStream()
|
var stream = new mystreams.ReadTarballStream()
|
||||||
stream.abort = function() {
|
stream.abort = function() {
|
||||||
rstream.close()
|
rstream.abort()
|
||||||
}
|
}
|
||||||
|
|
||||||
var rstream = this.storage(name).read_stream(filename)
|
var rstream = this.storage(name).read_stream(filename)
|
||||||
|
@ -395,6 +395,9 @@ Storage.prototype.get_tarball = function(name, filename, callback) {
|
||||||
stream.emit('error', err)
|
stream.emit('error', err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
rstream.on('content-length', function(v) {
|
||||||
|
stream.emit('content-length', v)
|
||||||
|
})
|
||||||
rstream.on('open', function() {
|
rstream.on('open', function() {
|
||||||
// re-emitting open because it's handled in storage.js
|
// re-emitting open because it's handled in storage.js
|
||||||
stream.emit('open')
|
stream.emit('open')
|
||||||
|
|
|
@ -226,6 +226,9 @@ Storage.prototype.get_tarball = function(name, filename) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
rstream.on('content-length', function(v) {
|
||||||
|
stream.emit('content-length', v)
|
||||||
|
})
|
||||||
rstream.on('open', function() {
|
rstream.on('open', function() {
|
||||||
is_open = true
|
is_open = true
|
||||||
rstream.pipe(stream)
|
rstream.pipe(stream)
|
||||||
|
@ -261,7 +264,11 @@ Storage.prototype.get_tarball = function(name, filename) {
|
||||||
savestream.done()
|
savestream.done()
|
||||||
})
|
})
|
||||||
|
|
||||||
// XXX: check, what would happen if client disconnects?
|
rstream2.on('content-length', function(v) {
|
||||||
|
console.log('!!!!!!!!!!!!!!!!!!!!!!!', v)
|
||||||
|
stream.emit('content-length', v)
|
||||||
|
savestream.emit('content-length', v)
|
||||||
|
})
|
||||||
rstream2.pipe(stream)
|
rstream2.pipe(stream)
|
||||||
rstream2.pipe(savestream)
|
rstream2.pipe(savestream)
|
||||||
})
|
})
|
||||||
|
|
|
@ -263,6 +263,8 @@ Storage.prototype.get_url = function(url) {
|
||||||
status: 500,
|
status: 500,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
if (res.headers['content-length'])
|
||||||
|
stream.emit('content-length', res.headers['content-length'])
|
||||||
|
|
||||||
rstream.pipe(stream)
|
rstream.pipe(stream)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue