2014-11-12 06:14:37 -05:00
|
|
|
var Stream = require('stream')
|
|
|
|
var Util = require('util')
|
|
|
|
|
|
|
|
module.exports.ReadTarballStream = ReadTarball
|
|
|
|
module.exports.UploadTarballStream = UploadTarball
|
2013-09-27 03:54:16 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// This stream is used to read tarballs from repository
|
|
|
|
//
|
|
|
|
function ReadTarball(options) {
|
2014-11-12 06:14:37 -05:00
|
|
|
var self = new Stream.PassThrough(options)
|
2014-11-12 07:05:07 -05:00
|
|
|
Object.setPrototypeOf(self, ReadTarball.prototype)
|
2014-11-12 06:14:37 -05:00
|
|
|
|
|
|
|
// called when data is not needed anymore
|
|
|
|
add_abstract_method(self, 'abort')
|
2013-09-27 03:54:16 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
return self
|
2013-09-27 04:54:43 -05:00
|
|
|
}
|
2013-09-27 03:54:16 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
Util.inherits(ReadTarball, Stream.PassThrough)
|
2013-09-27 03:54:16 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// This stream is used to upload tarballs to a repository
|
|
|
|
//
|
|
|
|
function UploadTarball(options) {
|
2014-11-12 06:14:37 -05:00
|
|
|
var self = new Stream.PassThrough(options)
|
2014-11-12 07:05:07 -05:00
|
|
|
Object.setPrototypeOf(self, UploadTarball.prototype)
|
2014-11-12 06:14:37 -05:00
|
|
|
|
|
|
|
// called when user closes connection before upload finishes
|
|
|
|
add_abstract_method(self, 'abort')
|
2013-10-26 07:18:36 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
// called when upload finishes successfully
|
|
|
|
add_abstract_method(self, 'done')
|
2013-10-26 07:18:36 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
return self
|
2013-09-27 03:54:16 -05:00
|
|
|
}
|
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
Util.inherits(UploadTarball, Stream.PassThrough)
|
2013-09-27 03:54:16 -05:00
|
|
|
|
2013-09-27 04:54:43 -05:00
|
|
|
//
|
|
|
|
// This function intercepts abstract calls and replays them allowing
|
|
|
|
// us to attach those functions after we are ready to do so
|
|
|
|
//
|
|
|
|
function add_abstract_method(self, name) {
|
2014-11-12 06:14:37 -05:00
|
|
|
self._called_methods = self._called_methods || {}
|
|
|
|
self.__defineGetter__(name, function() {
|
|
|
|
return function() {
|
|
|
|
self._called_methods[name] = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
self.__defineSetter__(name, function(fn) {
|
|
|
|
delete self[name]
|
|
|
|
self[name] = fn
|
|
|
|
if (self._called_methods && self._called_methods[name]) {
|
|
|
|
delete self._called_methods[name]
|
|
|
|
self[name]()
|
|
|
|
}
|
|
|
|
})
|
2013-09-27 04:54:43 -05:00
|
|
|
}
|
|
|
|
|