Skip to content

vscode.workspace.fs.writeFile other than text #1268

Discussion options

You must be logged in to vote

Hi Miciurash,

When saving binary files using vscode.workspace.fs.writeFile(), it's crucial to ensure that the data is correctly formatted as a Uint8Array because this method expects data in this format. The issue you're encountering with corrupt files likely stems from not converting the fetched data into a Uint8Array properly before writing.

Here's how you can solve this issue:

  1. Fetch the binary data from the web.
  2. Convert the Blob object to an ArrayBuffer using the blob.arrayBuffer() method.
  3. Create a Uint8Array from the ArrayBuffer.
  4. Use vscode.workspace.fs.writeFile() to write the Uint8Array to the desired location.

Try the following (suggested modified code from Copilot) as a guideline…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@burkeholland
Comment options

@Miciurash
Comment options

Answer selected by isidorn
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants