Decode binary file in Visual Studio Code

idleberg picture idleberg · Oct 17, 2016 · Viewed 17.2k times · Source

When trying to open a binary file in Visual Studio Code, the following message will show:

The file will not be displayed in the editor because it is either binary, very large or uses an unsupported text encoding

This is likely a protection to avoid the editor from freezing.

I would love to decode the file before showing it in the editor and have a function ready to handle that. The problem is, that I never have a chance to run my function since the following code never triggers:

vscode.workspace.onDidOpenTextDocument(function (doc) {
    if (doc && doc.fileName.endsWith('.scpt')) {
        console.log("You're trying to open a binary AppleScript file")
    }
});

Unfortunately, the API doesn't provide an equivalent event to onWillSaveTextDocument for opening files, which would fire before the message above shows. Does anybody know of a different solution?

Answer

glls picture glls · Jun 6, 2017

There is an Extension for VSCode called HexDump that you can use to Display a specified file in hexadecimal.

Once installed:

right-click on the file, and select "Show HexDump".

And will display the following:enter image description here