Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _streamSuccessReadTarBall(storage: any, filename: string): IReadTarball {
const stream: IReadTarball = new ReadTarball({});
const readTarballStream = storage.readTarball(filename);
const e404 = ErrorCode.getNotFound;
stream.abort = function(): void {
if (_.isNil(readTarballStream) === false) {
readTarballStream.abort();
}
};
readTarballStream.on('error', function(err) {
// @ts-ignore
if (err.code === STORAGE.NO_SUCH_FILE_ERROR || err.code === HTTP_STATUS.NOT_FOUND) {
stream.emit('error', e404('no such file available'));
} else {
stream.emit('error', err);
}
public getTarball(name: string, filename: string): IReadTarball {
const readStream = new ReadTarball({});
readStream.abort = function() {};
const self = this;
// if someone requesting tarball, it means that we should already have some
// information about it, so fetching package info is unnecessary
// trying local first
// flow: should be IReadTarball
let localStream: any = self.localStorage.getTarball(name, filename);
let isOpen = false;
localStream.on(
'error',
(err): any => {
if (isOpen || err.status !== HTTP_STATUS.NOT_FOUND) {
return readStream.emit('error', err);
addTarball(name, filename) {
assert(this.utils.validate_name(filename));
let length = 0;
const shaOneHash = Crypto.createHash('sha1');
const uploadStream = new customStream.UploadTarball();
const _transform = uploadStream._transform;
const storage = this._getLocalStorage(name);
uploadStream.abort = function() {};
uploadStream.done = function() {};
uploadStream._transform = function(data) {
shaOneHash.update(data);
// measure the length for validation reasons
length += data.length;
_transform.apply(uploadStream, arguments);
};
if (name === pkgFileName || name === '__proto__') {
process.nextTick(function() {
uploadStream.emit('error', this.utils.ErrorCode.get403());
});
addTarball(name: string, filename: string) {
assert(this.utils.validate_name(filename));
let length = 0;
const shaOneHash = Crypto.createHash('sha1');
const uploadStream = new UploadTarball();
const _transform = uploadStream._transform;
const storage = this._getLocalStorage(name);
uploadStream.abort = function() {};
uploadStream.done = function() {};
uploadStream._transform = function(data) {
shaOneHash.update(data);
// measure the length for validation reasons
length += data.length;
_transform.apply(uploadStream, arguments);
};
if (name === pkgFileName || name === '__proto__') {
process.nextTick(() => {
uploadStream.emit('error', this.utils.ErrorCode.get403());
});
public search(startKey: string, options: any): IReadTarball {
const stream = new ReadTarball({ objectMode: true });
this._searchEachPackage(
(item: Package, cb: CallbackAction): void => {
// @ts-ignore
if (item.time > parseInt(startKey, 10)) {
this.getPackageMetadata(item.name, (err: VerdaccioError, data: Package): void => {
if (err) {
return cb(err);
}
// @ts-ignore
const time = new Date(item.time).toISOString();
const result = prepareSearchPackage(data, time);
if (_.isNil(result) === false) {
stream.push(result);
}
public addTarball(name: string, filename: string): IUploadTarball {
assert(validateName(filename));
let length = 0;
const shaOneHash = createTarballHash();
const uploadStream: IUploadTarball = new UploadTarball({});
const _transform = uploadStream._transform;
const storage = this._getLocalStorage(name);
uploadStream.abort = function(): void {};
uploadStream.done = function(): void {};
uploadStream._transform = function(data, ...args): void {
shaOneHash.update(data);
// measure the length for validation reasons
length += data.length;
const appliedData = [data, ...args];
// FIXME: not sure about this approach, tsc complains
// @ts-ignore
_transform.apply(uploadStream, appliedData);
};
writeTarball(name): IUploadTarball {
this.logger.debug({name}, 'some name @name');
const uploadStream = new UploadTarball({});
uploadStream.on('close', () => {});
if (uploadStream.abort) {
uploadStream.abort();
}
if (uploadStream.done) {
uploadStream.done();
}
return uploadStream;
}
writeTarball(name: string): IUploadTarball {
const uploadStream = new UploadTarball();
return uploadStream;
}
_streamSuccessReadTarBall(storage, filename) {
const stream = new customStream.ReadTarball();
const readTarballStream = storage.createReadStream(filename);
const e404 = this.utils.ErrorCode.get404;
stream.abort = function() {
if (_.isNil(readTarballStream) === false) {
readTarballStream.abort();
}
};
readTarballStream.on('error', function(err) {
if (err && err.code === noSuchFile) {
stream.emit('error', e404('no such file available'));
} else {
stream.emit('error', err);
}
});
_streamSuccessReadTarBall(storage: ILocalFS, filename: string) {
const stream = new ReadTarball();
const readTarballStream = storage.createReadStream(filename);
const e404 = this.utils.ErrorCode.get404;
stream.abort = function() {
if (_.isNil(readTarballStream) === false) {
readTarballStream.abort();
}
};
readTarballStream.on('error', function(err) {
if (err && err.code === noSuchFile) {
stream.emit('error', e404('no such file available'));
} else {
stream.emit('error', err);
}
});