'Is there a way to retrieve and encode .woff files without any corruption?

I am attempting to retrieve a .woff font file from a url, convert the bytes to hex and then store the file in the new encoded format.

Currently, I have a function which does just this however the file somehow get's corrupted somewhere inbetween.

The function which I have currently is as following:

function getfont(url) {
    fetch(url).then(function(response) {
        return response.text();
    }).then(function(text) {
        var hex = [];
        for (var i = 0; i < text.length; i++) {
            hex.push(text.charCodeAt(i).toString(16));
        }
        console.log(hex.join(''))
    })
}

I have checked the response before encoding and do not seem to see anything obvious which clues me to how the file is getting corrupted after it is being encoded and I have also checked that the font stored at the url works beforehand.

How would I go about fetching the .woff file and storing it as an encoded string without any corruption and being able to use the file after decoding it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source