From ac1405687e144d55f1ced462ef2f1bdaab793035 Mon Sep 17 00:00:00 2001 From: John Murray Date: Thu, 22 Jun 2023 11:39:59 +0100 Subject: [PATCH] Eliminate log warning about use of deprecated `new Buffer()` (#1134) * Bump version after release * Stop using deprecated `new Buffer()` (fixes #1133) --- packages/extension/package.json | 2 +- packages/extension/test/__mocks__/fs.ts | 2 +- packages/util/persistence/serializable-storage.ts | 11 +++-------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/extension/package.json b/packages/extension/package.json index ee0b822b9..b18ccb603 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -2,7 +2,7 @@ "name": "sqltools", "displayName": "SQLTools", "description": "Connecting users to many of the most commonly used databases. Welcome to database management done right.", - "version": "0.27.1", + "version": "0.27.2-SNAPSHOT", "publisher": "mtxr", "license": "MIT", "preview": false, diff --git a/packages/extension/test/__mocks__/fs.ts b/packages/extension/test/__mocks__/fs.ts index 5aff8b237..47bd894e3 100644 --- a/packages/extension/test/__mocks__/fs.ts +++ b/packages/extension/test/__mocks__/fs.ts @@ -23,7 +23,7 @@ function existsSync(directoryPath) { } function writeFileSync(directoryPath, content) { - mockFiles[directoryPath] = new Buffer(content); + mockFiles[directoryPath] = Buffer.from(content); } fs.readFileSync = readFileSync; diff --git a/packages/util/persistence/serializable-storage.ts b/packages/util/persistence/serializable-storage.ts index c8f3d68f5..7529a5107 100644 --- a/packages/util/persistence/serializable-storage.ts +++ b/packages/util/persistence/serializable-storage.ts @@ -15,7 +15,7 @@ export default class SerializableStorage { public read(): this { try { - const content = fs.readFileSync(this.storagePath, { encoding: this.encoding }); + const content = fs.readFileSync(this.storagePath, this.encoding); if (content && content.length > 0) { this.items = JSON.parse(content); } else { @@ -27,16 +27,11 @@ export default class SerializableStorage { return this; } - private serializeContent(): Buffer { - return new Buffer(JSON.stringify(this.items, null, 2), 'utf8'); - } public save(): this { - return this.write(); - } - private write(): this { - fs.writeFileSync(this.storagePath, this.serializeContent()); + fs.writeFileSync(this.storagePath, JSON.stringify(this.items, null, 2), this.encoding); return this; } + public reset(): this { this.items = JSON.parse(this.defaultSerializable); return this;