Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 1x 1x 1x 1x 1x 3x 3x 2x 2x 3x 2x 2x 2x 2x 2x | import {PassThrough} from 'stream'; export interface IReadTarball { abort?: () => void; } export interface IUploadTarball { done?: () => void; abort?: () => void; } /** * This stream is used to read tarballs from repository. * @param {*} options * @return {Stream} */ class ReadTarball extends PassThrough implements IReadTarball { /** * * @param {Object} options */ constructor(options: any) { super(options); // called when data is not needed anymore addAbstractMethods(this, 'abort'); } abort(){} } /** * This stream is used to upload tarballs to a repository. * @param {*} options * @return {Stream} */ class UploadTarball extends PassThrough implements IUploadTarball { /** * * @param {Object} options */ constructor(options: any) { super(options); // called when user closes connection before upload finishes addAbstractMethods(this, 'abort'); // called when upload finishes successfully addAbstractMethods(this, 'done'); } abort(){} done(){} } /** * 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 */ // Perhaps someone knows a better way to write this function addAbstractMethods(self: any, name: any) { self._called_methods = self._called_methods || {}; self.__defineGetter__(name, function() { return function() { self._called_methods[name] = true; }; }); self.__defineSetter__(name, function(fn: any ) { delete self[name]; self[name] = fn; Eif (self._called_methods && self._called_methods[name]) { delete self._called_methods[name]; self[name](); } }); } export {ReadTarball, UploadTarball}; |