mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
refactor: move stream tarball helper as a dependency
This commit is contained in:
parent
ba99fd5ba1
commit
d7e6bae469
8 changed files with 5 additions and 91 deletions
|
@ -16,6 +16,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@verdaccio/file-locking": "^0.0.3",
|
||||
"@verdaccio/streams": "^0.0.2",
|
||||
"JSONStream": "^1.1.1",
|
||||
"apache-md5": "^1.1.2",
|
||||
"async": "^2.0.1",
|
||||
|
|
|
@ -10,7 +10,7 @@ const Stream = require('stream');
|
|||
const Search = require('./search');
|
||||
const LocalStorage = require('./storage/local/local-storage');
|
||||
const Logger = require('./logger');
|
||||
const MyStreams = require('./storage/streams');
|
||||
const MyStreams = require('@verdaccio/streams');
|
||||
const Proxy = require('./storage/up-storage');
|
||||
const Utils = require('./utils');
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const createError = require('http-errors');
|
||||
const mkdirp = require('mkdirp');
|
||||
const MyStream = require('../streams');
|
||||
const MyStream = require('@verdaccio/streams');
|
||||
const locker = require('@verdaccio/file-locking');
|
||||
const fileExist = 'EEXISTS';
|
||||
const noSuchFile = 'ENOENT';
|
||||
|
|
|
@ -13,7 +13,7 @@ const _ = require('lodash');
|
|||
|
||||
const fsStorage = require('./local-fs');
|
||||
const LocalData = require('./local-data');
|
||||
const customStream = require('../streams');
|
||||
const customStream = require('@verdaccio/streams');
|
||||
|
||||
const pkgFileName = 'package.json';
|
||||
const fileExist = 'EEXISTS';
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Stream = require('stream');
|
||||
|
||||
/**
|
||||
* This stream is used to read tarballs from repository.
|
||||
* @param {*} options
|
||||
* @return {Stream}
|
||||
*/
|
||||
class ReadTarball extends Stream.PassThrough {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(options) {
|
||||
super(options);
|
||||
// called when data is not needed anymore
|
||||
add_abstract_method(this, 'abort');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This stream is used to upload tarballs to a repository.
|
||||
* @param {*} options
|
||||
* @return {Stream}
|
||||
*/
|
||||
class UploadTarball extends Stream.PassThrough {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(options) {
|
||||
super(options);
|
||||
// called when user closes connection before upload finishes
|
||||
add_abstract_method(this, 'abort');
|
||||
|
||||
// called when upload finishes successfully
|
||||
add_abstract_method(this, '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
|
||||
*/
|
||||
function add_abstract_method(self, name) {
|
||||
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]();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.ReadTarball = ReadTarball;
|
||||
module.exports.UploadTarball = UploadTarball;
|
|
@ -7,7 +7,7 @@ const request = require('request');
|
|||
const Stream = require('stream');
|
||||
const URL = require('url');
|
||||
const Logger = require('../logger');
|
||||
const MyStreams = require('./streams');
|
||||
const MyStreams = require('@verdaccio/streams');
|
||||
const Utils = require('../utils');
|
||||
const zlib = require('zlib');
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
let ReadTarball = require('../../src/lib/storage/streams').ReadTarball;
|
||||
|
||||
describe('mystreams', function() {
|
||||
it('should delay events', function(cb) {
|
||||
let test = new ReadTarball();
|
||||
test.abort();
|
||||
setTimeout(function() {
|
||||
test.abort = function() {
|
||||
cb();
|
||||
};
|
||||
test.abort = function() {
|
||||
throw Error('fail');
|
||||
};
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue