Skip to content

Instantly share code, notes, and snippets.

@ljmotta
Last active October 13, 2020 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljmotta/df0d27d84c6e4371637c2bc572d8e8e3 to your computer and use it in GitHub Desktop.
Save ljmotta/df0d27d84c6e4371637c2bc572d8e8e3 to your computer and use it in GitHub Desktop.
Base64Png VS Code package.json activate part2
import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs";
let backendProxy: VsCodeBackendProxy;
export function activate(context: vscode.ExtensionContext) {
// ...
context.subscriptions.push(
vscode.commands.registerCommand("extension.kogito.createBase64Png", (file: { fsPath: string }) => {
const buffer = fs.readFileSync(file.fsPath);
const parsedPath = path.parse(file.fsPath);
const base64FileName = `${parsedPath.name}${parsedPath.ext}.base64png`;
const base64AbsoluteFilePath = path.join(parsedPath.dir, base64FileName);
fs.writeFileSync(base64AbsoluteFilePath, buffer.toString("base64"));
vscode.window.showInformationMessage("Generated the Base64 file with success!", "Open").then((selected) => {
if (!selected) {
return;
}
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(base64AbsoluteFilePath));
});
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment