2017-04-23 20:02:26 +02:00
|
|
|
'use strict';
|
2014-11-12 14:14:37 +03:00
|
|
|
|
2017-04-27 03:50:04 +02:00
|
|
|
const Stream = require('stream');
|
2017-04-23 20:02:26 +02:00
|
|
|
|
2017-04-27 03:50:04 +02:00
|
|
|
/**
|
|
|
|
* This stream is used to read tarballs from repository.
|
|
|
|
* @param {*} options
|
2017-06-06 23:07:51 +02:00
|
|
|
* @return {Stream}
|
2017-04-27 03:50:04 +02:00
|
|
|
*/
|
2017-05-26 07:21:30 +02:00
|
|
|
class ReadTarball extends Stream.PassThrough {
|
2014-11-12 14:14:37 +03:00
|
|
|
|
2017-05-26 07:21:30 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Object} options
|
|
|
|
*/
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
// called when data is not needed anymore
|
|
|
|
add_abstract_method(this, 'abort');
|
|
|
|
}
|
2013-09-27 13:54:43 +04:00
|
|
|
}
|
2013-09-27 12:54:16 +04:00
|
|
|
|
2017-04-27 03:50:04 +02:00
|
|
|
/**
|
|
|
|
* This stream is used to upload tarballs to a repository.
|
|
|
|
* @param {*} options
|
2017-06-06 23:07:51 +02:00
|
|
|
* @return {Stream}
|
2017-04-27 03:50:04 +02:00
|
|
|
*/
|
2017-05-26 07:21:30 +02:00
|
|
|
class UploadTarball extends Stream.PassThrough {
|
2014-11-12 14:14:37 +03:00
|
|
|
|
2017-05-26 07:21:30 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Object} options
|
|
|
|
*/
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
// called when user closes connection before upload finishes
|
|
|
|
add_abstract_method(this, 'abort');
|
2013-10-26 16:18:36 +04:00
|
|
|
|
2017-05-26 07:21:30 +02:00
|
|
|
// called when upload finishes successfully
|
|
|
|
add_abstract_method(this, 'done');
|
|
|
|
}
|
2013-09-27 12:54:16 +04:00
|
|
|
}
|
|
|
|
|
2017-04-27 03:50:04 +02:00
|
|
|
/**
|
|
|
|
* This function intercepts abstract calls and replays them allowing.
|
|
|
|
* us to attach those functions after we are ready to do so
|
|
|
|
* @param {*} self
|
|
|
|
* @param {*} name
|
|
|
|
*/
|
2013-09-27 13:54:43 +04:00
|
|
|
function add_abstract_method(self, name) {
|
2017-04-23 20:02:26 +02:00
|
|
|
self._called_methods = self._called_methods || {};
|
2014-11-12 14:14:37 +03:00
|
|
|
self.__defineGetter__(name, function() {
|
|
|
|
return function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
self._called_methods[name] = true;
|
|
|
|
};
|
|
|
|
});
|
2014-11-12 14:14:37 +03:00
|
|
|
self.__defineSetter__(name, function(fn) {
|
2017-04-23 20:02:26 +02:00
|
|
|
delete self[name];
|
|
|
|
self[name] = fn;
|
2014-11-12 14:14:37 +03:00
|
|
|
if (self._called_methods && self._called_methods[name]) {
|
2017-04-23 20:02:26 +02:00
|
|
|
delete self._called_methods[name];
|
|
|
|
self[name]();
|
2014-11-12 14:14:37 +03:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
});
|
2013-09-27 13:54:43 +04:00
|
|
|
}
|
|
|
|
|
2017-05-26 07:21:30 +02:00
|
|
|
module.exports.ReadTarball = ReadTarball;
|
|
|
|
module.exports.UploadTarball = UploadTarball;
|