Skip to content

Conversation

@bwateratmsft
Copy link
Contributor

No description provided.

@bwateratmsft bwateratmsft requested a review from a team as a code owner December 9, 2025 13:26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drawing extra attention to this since it's more than just basic typing/lint changes.

This comment was marked as resolved.

@bwateratmsft bwateratmsft requested a review from Copilot December 9, 2025 16:56
bwateratmsft

This comment was marked as resolved.

This comment was marked as resolved.

*/
export async function putFile(context: IActionContext, site: ParsedSite, data: string | ArrayBuffer, url: string, etag: string | undefined): Promise<string> {
const options: {} = etag ? { ['If-Match']: etag } : {};
export async function putFile(context: IActionContext, site: ParsedSite, data: string | ArrayBuffer | Uint8Array, url: string, etag: string | undefined): Promise<string> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode is actually passing in Uint8Array, and below in SiteClient.vfsPutItem we can support both ArrayBuffer and Uint8Array, so the easiest non-breaking change is to include | Uint8Array.

method: 'PUT',
url,
body: typeof data === 'string' ? data : data.toString(),
body: typeof data === 'string' ? data : new TextDecoder('utf-8').decode(data),
Copy link
Contributor Author

@bwateratmsft bwateratmsft Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code worked, but somewhat by luck. VSCode's FS interfaces pass around Uint8Array, which is what we are passing into this method. At runtime, in the desktop VSCode, it's actually a Node Buffer, which implements .toString(encoding?: ...), with UTF-8 being the default encoding. So, in the past we were taking the byte array and encoding it to UTF-8 before upload.

Thing is, Uint8Array (the base type also shared by web) does not do that; it has just .toString() which writes unencoded, comma-separated Uint8s.

The better solution is to use TextDecoder to be explicit about what we're trying to do. It supports ArrayBuffer, Uint8Array, and Buffer all the same. TextDecoder is more technically correct, the best kind of correct.

This comment was marked as resolved.

@bwateratmsft bwateratmsft merged commit dcade1c into main Dec 11, 2025
4 checks passed
@bwateratmsft bwateratmsft deleted the bmw/appserviceEng branch December 11, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants