From 2da576a1f81940130e4f0d29f3d00bfc6c7d0596 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Fri, 23 Nov 2018 16:54:50 +0100 Subject: [PATCH] fix(xo-web): avoid using TextDecoder (#3718) This is an experimental API and not really necessary here. --- packages/xo-web/src/xo-app/vm-import/ova/index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/xo-web/src/xo-app/vm-import/ova/index.js b/packages/xo-web/src/xo-app/vm-import/ova/index.js index ac3ea553f..db73e64cf 100644 --- a/packages/xo-web/src/xo-app/vm-import/ova/index.js +++ b/packages/xo-web/src/xo-app/vm-import/ova/index.js @@ -83,7 +83,7 @@ const filterDisks = disks => { } // =================================================================== -/* global FileReader, TextDecoder */ +/* global FileReader */ async function readFileFragment (file, start = 0, end) { const reader = new FileReader() @@ -92,18 +92,21 @@ async function readFileFragment (file, start = 0, end) { } function parseTarHeader (header) { - const textDecoder = new TextDecoder('ascii') - const fileName = textDecoder.decode(header.slice(0, 100)).split('\0')[0] + const fileName = Buffer.from(header.slice(0, 100)) + .toString('ascii') + .split('\0')[0] if (fileName.length === 0) { return null } - const fileSize = parseInt(textDecoder.decode(header.slice(124, 124 + 11)), 8) + const fileSize = parseInt( + Buffer.from(header.slice(124, 124 + 11)).toString('ascii'), + 8 + ) return { fileName, fileSize } } async function parseOVF (fileFragment) { - const textDecoder = new TextDecoder('utf-8') - const xmlString = textDecoder.decode(await readFileFragment(fileFragment)) + const xmlString = Buffer.from(await readFileFragment(fileFragment)).toString() return new Promise((resolve, reject) => xml2js.parseString( xmlString,