From f3948983c5d7e6445724be77781b7e3579b16e75 Mon Sep 17 00:00:00 2001 From: Tomasz Sapeta Date: Tue, 13 Sep 2022 15:34:33 +0200 Subject: [PATCH] [tools] Fix transforming binary files [skip ci] --- tools/src/Transforms.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/src/Transforms.ts b/tools/src/Transforms.ts index 54a7faea3a599..3a65a8b0c26c2 100644 --- a/tools/src/Transforms.ts +++ b/tools/src/Transforms.ts @@ -125,8 +125,14 @@ export async function copyFileWithTransformsAsync( // Transform source content. const content = await getTransformedFileContentAsync(sourcePath, filteredContentTransforms); - // Save transformed source file at renamed target path. - await fs.outputFile(targetPath, content); + if (filteredContentTransforms.length > 0) { + // Save transformed source file at renamed target path. + await fs.outputFile(targetPath, content); + } else { + // When there are no transforms, it's safer to just copy the file. + // Only then binary files will be copied properly since the `content` is utf8-encoded. + await fs.copy(sourcePath, targetPath, { overwrite: true }); + } // Keep original file mode if needed. if (options.keepFileMode) {