Actually handle gzip encoded connections when downloading.

This commit is contained in:
modmuss50
2021-07-16 22:48:50 +01:00
parent 6695e2b5d1
commit 8e11e4a385
2 changed files with 18 additions and 2 deletions

View File

@@ -26,9 +26,11 @@ package net.fabricmc.loom.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
@@ -109,7 +111,13 @@ public class DownloadUtil {
}
try { // Try download to the output
FileUtils.copyInputStreamToFile(connection.getInputStream(), to);
InputStream inputStream = connection.getInputStream();
if ("gzip".equals(connection.getContentEncoding())) {
inputStream = new GZIPInputStream(inputStream);
}
FileUtils.copyInputStreamToFile(inputStream, to);
} catch (IOException e) {
to.delete(); // Probably isn't good if it fails to copy/save
throw e;

View File

@@ -26,9 +26,11 @@ package net.fabricmc.loom.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import javax.annotation.Nullable;
@@ -84,7 +86,13 @@ public class HashedDownloadUtil {
}
try { // Try download to the output
FileUtils.copyInputStreamToFile(connection.getInputStream(), to);
InputStream inputStream = connection.getInputStream();
if ("gzip".equals(connection.getContentEncoding())) {
inputStream = new GZIPInputStream(inputStream);
}
FileUtils.copyInputStreamToFile(inputStream, to);
} catch (IOException e) {
delete(to); // Probably isn't good if it fails to copy/save
throw e;