Skip to content

Commit a23edad

Browse files
author
Benjamin Pasero
committed
debt - avoid deprecated Buffer ctors
1 parent 0c1cb45 commit a23edad

25 files changed

Lines changed: 48 additions & 48 deletions

File tree

build/gulpfile.editor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ gulp.task('editor-distro', ['clean-editor-distro', 'minify-editor', 'optimize-ed
102102
.pipe(es.through(function (data) {
103103
var json = JSON.parse(data.contents.toString());
104104
json.private = false;
105-
data.contents = new Buffer(JSON.stringify(json, null, ' '));
105+
data.contents = Buffer.from(JSON.stringify(json, null, ' '));
106106
this.emit('data', data);
107107
}))
108108
.pipe(gulp.dest('out-monaco-editor-core')),
@@ -142,7 +142,7 @@ gulp.task('editor-distro', ['clean-editor-distro', 'minify-editor', 'optimize-ed
142142
var newStr = '//# sourceMappingURL=' + relativePathToMap.replace(/\\/g, '/');
143143
strContents = strContents.replace(/\/\/\# sourceMappingURL=[^ ]+$/, newStr);
144144

145-
data.contents = new Buffer(strContents);
145+
data.contents = Buffer.from(strContents);
146146
this.emit('data', data);
147147
})).pipe(gulp.dest('out-monaco-editor-core/min')),
148148

build/gulpfile.vscode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const config = {
148148
name: product.nameLong,
149149
urlSchemes: [product.urlProtocol]
150150
}],
151-
darwinCredits: darwinCreditsTemplate ? new Buffer(darwinCreditsTemplate({ commit: commit, date: new Date().toISOString() })) : void 0,
151+
darwinCredits: darwinCreditsTemplate ? Buffer.from(darwinCreditsTemplate({ commit: commit, date: new Date().toISOString() })) : void 0,
152152
linuxExecutableName: product.applicationName,
153153
winIcon: 'resources/win32/code.ico',
154154
token: process.env['VSCODE_MIXIN_PASSWORD'] || process.env['GITHUB_TOKEN'] || void 0,

build/lib/i18n.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ function processCoreBundleFormat(fileHeader: string, languages: Language[], json
570570
contents.push(index < modules.length - 1 ? '\t],' : '\t]');
571571
});
572572
contents.push('});');
573-
emitter.queue(new File({ path: bundle + '.nls.' + language.id + '.js', contents: new Buffer(contents.join('\n'), 'utf-8') }));
573+
emitter.queue(new File({ path: bundle + '.nls.' + language.id + '.js', contents: Buffer.from(contents.join('\n'), 'utf-8') }));
574574
});
575575
});
576576
Object.keys(statistics).forEach(key => {
@@ -667,7 +667,7 @@ export function createXlfFilesForCoreBundle(): ThroughStream {
667667
const filePath = `${xlf.project}/${resource.replace(/\//g, '_')}.xlf`;
668668
const xlfFile = new File({
669669
path: filePath,
670-
contents: new Buffer(xlf.toString(), 'utf8')
670+
contents: Buffer.from(xlf.toString(), 'utf8')
671671
});
672672
this.queue(xlfFile);
673673
}
@@ -738,7 +738,7 @@ export function createXlfFilesForExtensions(): ThroughStream {
738738
if (_xlf) {
739739
let xlfFile = new File({
740740
path: path.join(extensionsProject, extensionName + '.xlf'),
741-
contents: new Buffer(_xlf.toString(), 'utf8')
741+
contents: Buffer.from(_xlf.toString(), 'utf8')
742742
});
743743
folderStream.queue(xlfFile);
744744
}
@@ -810,7 +810,7 @@ export function createXlfFilesForIsl(): ThroughStream {
810810

811811
// Emit only upon all ISL files combined into single XLF instance
812812
const newFilePath = path.join(projectName, resourceFile);
813-
const xlfFile = new File({ path: newFilePath, contents: new Buffer(xlf.toString(), 'utf-8') });
813+
const xlfFile = new File({ path: newFilePath, contents: Buffer.from(xlf.toString(), 'utf-8') });
814814
this.queue(xlfFile);
815815
});
816816
}
@@ -1174,7 +1174,7 @@ function createI18nFile(originalFilePath: string, messages: any): File {
11741174
let content = JSON.stringify(result, null, '\t').replace(/\r\n/g, '\n');
11751175
return new File({
11761176
path: path.join(originalFilePath + '.i18n.json'),
1177-
contents: new Buffer(content, 'utf8')
1177+
contents: Buffer.from(content, 'utf8')
11781178
});
11791179
}
11801180

@@ -1328,7 +1328,7 @@ function createIslFile(originalFilePath: string, messages: Map<string>, language
13281328

13291329
return new File({
13301330
path: filePath,
1331-
contents: iconv.encode(new Buffer(content.join('\r\n'), 'utf8'), innoSetup.codePage)
1331+
contents: iconv.encode(Buffer.from(content.join('\r\n'), 'utf8'), innoSetup.codePage)
13321332
});
13331333
}
13341334

build/lib/nls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ module nls {
131131

132132
export function fileFrom(file: File, contents: string, path: string = file.path) {
133133
return new File({
134-
contents: new Buffer(contents),
134+
contents: Buffer.from(contents),
135135
base: file.base,
136136
cwd: file.cwd,
137137
path: path

build/lib/optimize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function loader(bundledFileHeader: string, bundleLoader: boolean): NodeJS.ReadWr
7171
this.emit('data', new VinylFile({
7272
path: 'fake',
7373
base: '',
74-
contents: new Buffer(bundledFileHeader)
74+
contents: Buffer.from(bundledFileHeader)
7575
}));
7676
this.emit('data', data);
7777
} else {
@@ -115,7 +115,7 @@ function toConcatStream(bundledFileHeader: string, sources: bundle.IFile[], dest
115115
return new VinylFile({
116116
path: source.path ? root + '/' + source.path.replace(/\\/g, '/') : 'fake',
117117
base: base,
118-
contents: new Buffer(source.contents)
118+
contents: Buffer.from(source.contents)
119119
});
120120
});
121121

@@ -199,7 +199,7 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
199199
bundleInfoArray.push(new VinylFile({
200200
path: 'bundleInfo.json',
201201
base: '.',
202-
contents: new Buffer(JSON.stringify(result.bundleData, null, '\t'))
202+
contents: Buffer.from(JSON.stringify(result.bundleData, null, '\t'))
203203
}));
204204
}
205205
es.readArray(bundleInfoArray).pipe(bundleInfoStream);

build/lib/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export function loadSourcemaps(): NodeJS.ReadWriteStream {
190190
return;
191191
}
192192

193-
f.contents = new Buffer(contents.replace(/\/\/# sourceMappingURL=(.*)$/g, ''), 'utf8');
193+
f.contents = Buffer.from(contents.replace(/\/\/# sourceMappingURL=(.*)$/g, ''), 'utf8');
194194

195195
fs.readFile(path.join(path.dirname(f.path), lastMatch[1]), 'utf8', (err, contents) => {
196196
if (err) { return cb(err); }
@@ -209,7 +209,7 @@ export function stripSourceMappingURL(): NodeJS.ReadWriteStream {
209209
const output = input
210210
.pipe(es.mapSync<VinylFile, VinylFile>(f => {
211211
const contents = (<Buffer>f.contents).toString('utf8');
212-
f.contents = new Buffer(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, ''), 'utf8');
212+
f.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, ''), 'utf8');
213213
return f;
214214
}));
215215

build/lib/watch/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const es = require('event-stream');
99
function handleDeletions() {
1010
return es.mapSync(f => {
1111
if (/\.ts$/.test(f.relative) && !f.contents) {
12-
f.contents = new Buffer('');
12+
f.contents = Buffer.from('');
1313
f.stat = { mtime: new Date() };
1414
}
1515

extensions/git/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export async function grep(filename: string, pattern: RegExp): Promise<boolean>
239239
export function readBytes(stream: Readable, bytes: number): Promise<Buffer> {
240240
return new Promise<Buffer>((complete, error) => {
241241
let done = false;
242-
let buffer = new Buffer(bytes);
242+
let buffer = Buffer.allocUnsafe(bytes);
243243
let bytesRead = 0;
244244

245245
stream.on('data', (data: Buffer) => {

extensions/typescript/src/utils/electronForkStart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ log('ELECTRON_RUN_AS_NODE: ' + process.env['ELECTRON_RUN_AS_NODE']);
5757

5858
var fsWriteSyncString = function (fd: number, str: string, _position: number, encoding?: string) {
5959
// fs.writeSync(fd, string[, position[, encoding]]);
60-
var buf = new Buffer(str, encoding || 'utf8');
60+
var buf = Buffer.from(str, encoding || 'utf8');
6161
return fsWriteSyncBuffer(fd, buf, 0, buf.length);
6262
};
6363

extensions/typescript/src/utils/wireProtocol.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ import * as stream from 'stream';
88
const DefaultSize: number = 8192;
99
const ContentLength: string = 'Content-Length: ';
1010
const ContentLengthSize: number = Buffer.byteLength(ContentLength, 'utf8');
11-
const Blank: number = new Buffer(' ', 'utf8')[0];
12-
const BackslashR: number = new Buffer('\r', 'utf8')[0];
13-
const BackslashN: number = new Buffer('\n', 'utf8')[0];
11+
const Blank: number = Buffer.from(' ', 'utf8')[0];
12+
const BackslashR: number = Buffer.from('\r', 'utf8')[0];
13+
const BackslashN: number = Buffer.from('\n', 'utf8')[0];
1414

1515
class ProtocolBuffer {
1616

1717
private index: number = 0;
18-
private buffer: Buffer = new Buffer(DefaultSize);
18+
private buffer: Buffer = Buffer.allocUnsafe(DefaultSize);
1919

2020
public append(data: string | Buffer): void {
2121
let toAppend: Buffer | null = null;
2222
if (Buffer.isBuffer(data)) {
2323
toAppend = <Buffer>data;
2424
} else {
25-
toAppend = new Buffer(<string>data, 'utf8');
25+
toAppend = Buffer.from(<string>data, 'utf8');
2626
}
2727
if (this.buffer.length - this.index >= toAppend.length) {
2828
toAppend.copy(this.buffer, this.index, 0, toAppend.length);
2929
} else {
3030
let newSize = (Math.ceil((this.index + toAppend.length) / DefaultSize) + 1) * DefaultSize;
3131
if (this.index === 0) {
32-
this.buffer = new Buffer(newSize);
32+
this.buffer = Buffer.allocUnsafe(newSize);
3333
toAppend.copy(this.buffer, 0, 0, toAppend.length);
3434
} else {
3535
this.buffer = Buffer.concat([this.buffer.slice(0, this.index), toAppend], newSize);

0 commit comments

Comments
 (0)