Fix node DEP0005 (Buffer() being deprecated)

feature/search
Kelvin Schoofs 6 years ago
parent 2d39bced12
commit 461ccc9c23

@ -69,7 +69,7 @@ function createConfigFs(manager: Manager): SSHFileSystem {
config = config || manager.getActive().find(c => c.name === name);
activeButDeleted = true;
}
let str;
let str: string;
if (config) {
str = JSON.stringify({ ...config, name: undefined }, undefined, 4);
let prefix = `// If you haven't already, associate .jsonc files with "JSON with Comments (jsonc)\n`;
@ -78,12 +78,12 @@ function createConfigFs(manager: Manager): SSHFileSystem {
} else {
str = await toPromise<string>(cb => readFile(path.resolve(__dirname, '../resources/defaultConfig.jsonc'), 'utf-8', cb));
}
return new Uint8Array(new Buffer(str));
return new Uint8Array(Buffer.from(str));
},
writeFile: async (uri: vscode.Uri, content: Uint8Array) => {
const name = uri.path.substring(1, uri.path.length - 12);
const errors: ParseError[] = [];
const config = parseJsonc(new Buffer(content).toString(), errors);
const config = parseJsonc(Buffer.from(content).toString(), errors);
if (!config || errors.length) {
vscode.window.showErrorMessage(`Couldn't parse this config as JSON`);
return;

@ -94,7 +94,6 @@ export class SSHFileSystem implements vscode.FileSystemProvider {
}
public readFile(uri: vscode.Uri): Uint8Array | Promise<Uint8Array> {
return new Promise((resolve, reject) => {
const array = new Buffer(0);
const stream = this.sftp.createReadStream(this.relative(uri.path), { autoClose: true });
const bufs = [];
stream.on('data', bufs.push.bind(bufs));

@ -2,7 +2,7 @@
import { Duplex, Writable } from 'stream';
export class MemoryDuplex extends Duplex {
protected buffer = new Buffer(this.size);
protected buffer = Buffer.alloc(this.size);
protected buffered = 0;
protected doPush = false;
constructor(public readonly size: number = 4092) {
@ -10,7 +10,7 @@ export class MemoryDuplex extends Duplex {
}
// tslint:disable-next-line:function-name
public _write(chunk: any, encoding: string, callback: (err?: Error) => void) {
const buffer = chunk instanceof Buffer ? chunk : new Buffer(chunk, encoding);
const buffer = chunk instanceof Buffer ? chunk : Buffer.from(chunk, encoding);
const end = this.buffered + buffer.length;
if (end > this.size) {
return callback(new Error('Buffer overflow'));
@ -23,7 +23,7 @@ export class MemoryDuplex extends Duplex {
public _read() {
const slice = this.buffer.slice(0, this.buffered);
this.buffered = 0;
this.buffer = new Buffer(this.size);
this.buffer = Buffer.alloc(this.size);
this.doPush = this.push(slice);
}
public bytesBuffered() {
@ -37,7 +37,7 @@ export class WritableFunctionStream extends Writable {
}
// tslint:disable-next-line:function-name
public async _write(chunk: any, encoding: string, callback: (err?: Error) => void) {
const buffer = chunk instanceof Buffer ? chunk : new Buffer(chunk, encoding);
const buffer = chunk instanceof Buffer ? chunk : Buffer.from(chunk, encoding);
try {
await this.func(buffer);
callback();

Loading…
Cancel
Save