0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-04-01 02:42:23 -05:00

fix: buffer deprecated warnings (#1993)

* chore: use Buffer.from and Buffer.alloc instead of deprecated new Buffer

* chore: fix lint

* chore: fix lint

Co-authored-by: Jarom Loveridge <jaroml@gradecam.com>
This commit is contained in:
Juan Picado 2020-11-03 07:55:08 +01:00 committed by GitHub
parent f90174935f
commit 4feaf241c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 13 additions and 13 deletions

View file

@ -121,7 +121,7 @@ export function publishPackage(storage: IStorageHandler, config: Config, auth: I
});
// this is dumb and memory-consuming, but what choices do we have?
// flow: we need first refactor this file before decides which type use here
stream.end(new Buffer(data.data, 'base64'));
stream.end(Buffer.from(data.data, 'base64'));
stream.done();
};

View file

@ -26,7 +26,7 @@ export function aesDecrypt(buf: Buffer, secret: string): Buffer {
const b2 = c.final();
return Buffer.concat([b1, b2]);
} catch (_) {
return new Buffer(0);
return Buffer.alloc(0);
}
}

View file

@ -53,7 +53,7 @@ export function getUserAgent(): string {
}
export function convertPayloadToBase64(payload: string): Buffer {
return new Buffer(payload, 'base64');
return Buffer.from(payload, 'base64');
}
/**

View file

@ -7,7 +7,7 @@ export default function(server) {
describe('package access control', () => {
const buildAccesToken = (auth) => {
return buildToken(TOKEN_BASIC, `${(new Buffer(auth).toString('base64'))}`);
return buildToken(TOKEN_BASIC, `${(Buffer.from(auth).toString('base64'))}`);
};
/**

View file

@ -35,7 +35,7 @@ export default function(server, express) {
expect(res).toBeDefined();
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
res.send(new Buffer([1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]));
res.send(Buffer.from([1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]));
});
});

View file

@ -8,7 +8,7 @@ import {CREDENTIALS} from "../functional/config.functional";
import getPackage from '../functional/fixtures/package';
const buildAuthHeader = (user, pass): string => {
return buildToken(TOKEN_BASIC, new Buffer(`${user}:${pass}`).toString('base64'));
return buildToken(TOKEN_BASIC, Buffer.from(`${user}:${pass}`).toString('base64'));
};
export default class Server implements IServerBridge {

View file

@ -29,7 +29,7 @@ export default class ExampleMiddlewarePlugin implements IPluginMiddleware<{}> {
auth.authenticate('user', 'password', () => {});
auth.allow_access({packageName: 'packageName'}, remoteUser, () => {});
auth.add_user('user', 'password', () => {});
auth.aesEncrypt(new Buffer('pass'));
auth.aesEncrypt(Buffer.from('pass'));
// storage
storage.addPackage('name', generatePackageTemplate('test'), () => {});
storage.addVersion('name', 'version', generateVersion('name', '1.0.0'), 'tag', () => {});

View file

@ -201,7 +201,7 @@ describe('Auth utilities', () => {
const secret = 'secret';
const config: Config = getConfig('security-legacy', secret);
const auth: IAuth = new Auth(config);
const token = auth.aesEncrypt(new Buffer(`corruptedBuffer`)).toString('base64');
const token = auth.aesEncrypt(Buffer.from(`corruptedBuffer`)).toString('base64');
const security: Security = getSecurity(config);
const credentials = getMiddlewareCredentials(security, secret, buildToken(TOKEN_BEARER, token));
expect(credentials).not.toBeDefined();

View file

@ -62,7 +62,7 @@ describe('LocalStorage', () => {
resolve();
});
stream.end(new Buffer(tarballData.data, 'base64'));
stream.end(Buffer.from(tarballData.data, 'base64'));
stream.done();
});
};
@ -343,7 +343,7 @@ describe('LocalStorage', () => {
done();
});
stream.end(new Buffer(tarballData.data, 'base64'));
stream.end(Buffer.from(tarballData.data, 'base64'));
stream.done();
});
@ -358,7 +358,7 @@ describe('LocalStorage', () => {
done();
});
stream.end(new Buffer(tarballData.data, 'base64'));
stream.end(Buffer.from(tarballData.data, 'base64'));
stream.done();
});
@ -371,7 +371,7 @@ describe('LocalStorage', () => {
expect(err.message).toMatch(/this package is already present/);
done();
});
stream.end(new Buffer(tarballData.data, 'base64'));
stream.end(Buffer.from(tarballData.data, 'base64'));
stream.done();
});
@ -389,7 +389,7 @@ describe('LocalStorage', () => {
done();
});
stream.end(new Buffer(tarballData.data, 'base64'));
stream.end(Buffer.from(tarballData.data, 'base64'));
stream.done();
});