Skip to content

Commit

Permalink
fix: increase file download buffer size (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo committed Jan 31, 2023
1 parent 44d3f33 commit 0275a9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public void unarchive(Unarchive method, File toUnarchive, Path unarchiveInto) th
static void unzip(File zipFile, File destDir) throws IOException {
try (ZipFile zf = new ZipFile(zipFile)) {
Enumeration<? extends ZipEntry> entries = zf.entries();
// IOUtils uses a 4K buffer by default. Using 64K will make things go faster.
byte[] buffer = new byte[1024 * 64];

while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
File newFile = safeNewZipFile(destDir, zipEntry);
Expand All @@ -52,7 +55,7 @@ static void unzip(File zipFile, File destDir) throws IOException {
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.SYNC);
InputStream is = zf.getInputStream(zipEntry)) {
IOUtils.copy(is, fos);
IOUtils.copyLarge(is, fos, buffer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public abstract class ArtifactDownloader {
protected static final String HTTP_RANGE_HEADER_KEY = "Range";
static final String ARTIFACT_DOWNLOAD_EXCEPTION_FMT =
"Failed to download artifact name: '%s' for component %s-%s, reason: ";
private static final int DOWNLOAD_BUFFER_SIZE = 1024;
private static final int DOWNLOAD_BUFFER_SIZE = 1024 * 64; // Download/write with 64KB buffer
private static final int READ_BUFFER_SIZE = 8192;
protected final Logger logger;
protected final ComponentIdentifier identifier;
protected final ComponentArtifact artifact;
Expand All @@ -64,7 +65,7 @@ protected ArtifactDownloader(ComponentIdentifier identifier, ComponentArtifact a

private void updateDigestFromFile(Path filePath, MessageDigest digest) throws IOException {
try (InputStream existingArtifact = Files.newInputStream(filePath)) {
byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE];
byte[] buffer = new byte[READ_BUFFER_SIZE];
int readBytes = existingArtifact.read(buffer);
while (readBytes > -1) {
digest.update(buffer, 0, readBytes);
Expand Down

0 comments on commit 0275a9b

Please sign in to comment.