You are fetching the image from the server in base64 format so now decode the image which is in base64 format and store the output in a variable. Now lets see the decoded string and check the starting 10-12 characters of the decoded string because file extensions are stored in the starting of the file.
For example, if you want to understand the above logic open an jpeg/png image in notepad and observe the first 10-12 character in the file and you can find their respective file extensions in that file.
So I'm also doing the same thing here I will search for GZIP string in the decoded file, if its found then the file is in GZIP Format else its not.It may be a bit confusing. Let me show you the code for this :
`
var encodedData; //This one was fetched from the server
var decodedData = atob(encodedData); //atob() decodes the string which is in base64 format
var extension = "GZIP"
var IndexOfGZIP = decodedData.IndexOf(extension) //Checking for GZIP word in decoded data
//If it is equal to -1 it says that GZIP is not found in data
if( IndexOfGZIP !== -1 ){
//Normally the file extensions are found in the starting of the file only and hence I'm taking only first 11 characters into consideration.
if( IndexOfGZIP >= 0 && IndexOfGZIP <=10 ){
console.log("This is a GZIP file only")
}else{
console.log("File is not in GZIP Format")
}
}else{
console.log("File is not in GZIP Format")
}
`
Hope this helps you.