Chore: Remove `new Buffer` in favor of `Buffer.from` (#20918)

pull/21079/head
Kevin Aleman 4 years ago committed by GitHub
parent 3901dcec3c
commit 31552ca009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/assets/server/assets.js
  2. 2
      app/custom-sounds/server/methods/uploadCustomSound.js
  3. 2
      app/emoji-custom/server/methods/uploadEmojiCustom.js
  4. 2
      app/importer-hipchat/server/importer.js
  5. 2
      app/importer-slack-users/server/importer.js
  6. 4
      app/importer/server/classes/ImporterBase.js
  7. 2
      app/importer/server/methods/uploadImportFile.js
  8. 4
      app/irc/server/servers/RFC2813/index.js
  9. 4
      app/ldap/server/ldap.js
  10. 2
      app/lib/server/functions/setUserAvatar.js
  11. 2
      app/meteor-accounts-saml/server/lib/ServiceProvider.ts
  12. 2
      app/meteor-accounts-saml/server/lib/Utils.ts
  13. 2
      app/webdav/server/methods/uploadFileToWebdav.ts
  14. 2
      server/routes/avatar/utils.js
  15. 2
      server/startup/migrations/v002.js

@ -209,7 +209,7 @@ export const RocketChatAssets = new class {
});
}
const file = new Buffer(binaryContent, 'binary');
const file = Buffer.from(binaryContent, 'binary');
if (assets[asset].constraints.width || assets[asset].constraints.height) {
const dimensions = sizeOf(file);
if (assets[asset].constraints.width && assets[asset].constraints.width !== dimensions.width) {

@ -11,7 +11,7 @@ Meteor.methods({
throw new Meteor.Error('not_authorized');
}
const file = new Buffer(binaryContent, 'binary');
const file = Buffer.from(binaryContent, 'binary');
const rs = RocketChatFile.bufferToStream(file);
RocketChatFileCustomSoundsInstance.deleteFile(`${ soundData._id }.${ soundData.extension }`);

@ -15,7 +15,7 @@ Meteor.methods({
emojiData.name = limax(emojiData.name, { replacement: '_' });
// delete aliases for notification purposes. here, it is a string rather than an array
delete emojiData.aliases;
const file = new Buffer(binaryContent, 'binary');
const file = Buffer.from(binaryContent, 'binary');
const rs = RocketChatFile.bufferToStream(file);
RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${ emojiData.name }.${ emojiData.extension }`));

@ -31,7 +31,7 @@ export class HipChatImporter extends Base {
super.prepare(dataURI, sentContentType, fileName, skipTypeCheck);
const { image } = RocketChatFile.dataURIParse(dataURI);
// const contentType = ref.contentType;
const zip = new this.AdmZip(new Buffer(image, 'base64'));
const zip = new this.AdmZip(Buffer.from(image, 'base64'));
const zipEntries = zip.getEntries();
let tempRooms = [];
let tempUsers = [];

@ -26,7 +26,7 @@ export class SlackUsersImporter extends Base {
super.updateProgress(ProgressStep.PREPARING_USERS);
const uriResult = RocketChatFile.dataURIParse(dataURI);
const buf = new Buffer(uriResult.image, 'base64');
const buf = Buffer.from(uriResult.image, 'base64');
const parsed = this.csvParser(buf.toString());
parsed.forEach((user, index) => {

@ -140,7 +140,7 @@ export class Base {
*/
prepareUsingLocalFile(fullFilePath) {
const file = fs.readFileSync(fullFilePath);
const buffer = Buffer.isBuffer(file) ? file : new Buffer(file);
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(file);
const { contentType } = this.importRecord;
const fileName = this.importRecord.file;
@ -163,7 +163,7 @@ export class Base {
prepare(dataURI, sentContentType, fileName, skipTypeCheck) {
this.collection.remove({});
if (!skipTypeCheck) {
const fileType = this.getFileType(new Buffer(dataURI.split(',')[1], 'base64'));
const fileType = this.getFileType(Buffer.from(dataURI.split(',')[1], 'base64'));
this.logger.debug('Uploaded file information is:', fileType);
this.logger.debug('Expected file type is:', this.info.mimeType);

@ -34,7 +34,7 @@ Meteor.methods({
importer.instance.startFileUpload(newFileName, contentType);
// Save the file on the File Store
const file = new Buffer(binaryContent, 'base64');
const file = Buffer.from(binaryContent, 'base64');
const readStream = RocketChatFile.bufferToStream(file);
const writeStream = RocketChatImportFileInstance.createWriteStream(newFileName, contentType);

@ -18,7 +18,7 @@ class RFC2813 {
this.serverPrefix = null;
// Hold the buffer while receiving
this.receiveBuffer = new Buffer('');
this.receiveBuffer = Buffer.from('');
}
/**
@ -136,7 +136,7 @@ class RFC2813 {
}
// Reset the buffer
this.receiveBuffer = new Buffer('');
this.receiveBuffer = Buffer.from('');
lines.forEach((line) => {
if (line.length && !line.startsWith('\a')) {

@ -258,14 +258,14 @@ export default class LDAP {
if (attribute) {
filter = new this.ldapjs.filters.EqualityFilter({
attribute,
value: new Buffer(id, 'hex'),
value: Buffer.from(id, 'hex'),
});
} else {
const filters = [];
Unique_Identifier_Field.forEach((item) => {
filters.push(new this.ldapjs.filters.EqualityFilter({
attribute: item,
value: new Buffer(id, 'hex'),
value: Buffer.from(id, 'hex'),
}));
});

@ -51,7 +51,7 @@ export const setUserAvatar = function(user, dataURI, contentType, service) {
contentType = fileData.contentType;
}
const buffer = new Buffer(image, encoding);
const buffer = Buffer.from(image, encoding);
const fileStore = FileUpload.getStore('Avatars');
fileStore.deleteByName(user.username);

@ -182,7 +182,7 @@ export class SAMLServiceProvider {
}
public validateResponse(samlResponse: string, callback: IResponseValidateCallback): void {
const xml = new Buffer(samlResponse, 'base64').toString('utf8');
const xml = Buffer.from(samlResponse, 'base64').toString('utf8');
const parser = new ResponseParser(this.serviceProviderOptions);
return parser.validate(xml, callback);

@ -152,7 +152,7 @@ export class SAMLUtils {
}
public static inflateXml(base64Data: string, successCallback: (xml: string) => void, errorCallback: (err: string | object | null) => void): void {
const buffer = new Buffer(base64Data, 'base64');
const buffer = Buffer.from(base64Data, 'base64');
zlib.inflateRaw(buffer, (err, decoded) => {
if (err) {
this.log(`Error while inflating. ${ err }`);

@ -24,7 +24,7 @@ Meteor.methods({
}
const uploadFolder = 'Rocket.Chat Uploads/';
const buffer = new Buffer(fileData);
const buffer = Buffer.from(fileData);
try {
const cred = getWebdavCredentials(account);

@ -15,7 +15,7 @@ export const serveAvatar = (avatar, format, res) => {
if (['png', 'jpg', 'jpeg'].includes(format)) {
res.setHeader('Content-Type', `image/${ format }`);
sharp(new Buffer(avatar))
sharp(Buffer.from(avatar))
.toFormat(format)
.pipe(res);
return;

@ -29,7 +29,7 @@ Migrations.add({
const dataURI = avatars[service].blob;
const { image, contentType } = RocketChatFile.dataURIParse(dataURI);
const rs = RocketChatFile.bufferToStream(new Buffer(image, 'base64'));
const rs = RocketChatFile.bufferToStream(Buffer.from(image, 'base64'));
const fileStore = FileUpload.getStore('Avatars');
fileStore.deleteByName(user.username);

Loading…
Cancel
Save