aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/jshipit/BlobDownloader.java
diff options
context:
space:
mode:
authoraxtloss <axtlos@getcryst.al>2023-05-26 00:03:58 +0200
committeraxtloss <axtlos@getcryst.al>2023-05-26 00:03:58 +0200
commit87cc052844e2cacca591edd68884f1e7f6c49a3a (patch)
tree2e39577998921746253a7ed1ea08ee99e6d4ecc9 /src/main/java/io/github/jshipit/BlobDownloader.java
parent3fdb1012609b71a41e551ea0aad3b8a27b134e21 (diff)
downloadjshipit-87cc052844e2cacca591edd68884f1e7f6c49a3a.tar.gz
jshipit-87cc052844e2cacca591edd68884f1e7f6c49a3a.tar.bz2
Add comments to functions
Diffstat (limited to '')
-rw-r--r--src/main/java/io/github/jshipit/BlobDownloader.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/main/java/io/github/jshipit/BlobDownloader.java b/src/main/java/io/github/jshipit/BlobDownloader.java
index ea8b09c..f860a93 100644
--- a/src/main/java/io/github/jshipit/BlobDownloader.java
+++ b/src/main/java/io/github/jshipit/BlobDownloader.java
@@ -1,8 +1,6 @@
package io.github.jshipit;
import me.tongfei.progressbar.ProgressBar;
-import org.apache.commons.compress.archivers.tar.*;
-import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import java.io.*;
import java.net.*;
@@ -27,6 +25,9 @@ public class BlobDownloader extends Thread {
this.renameTo = renameTo;
}
+ /*
+ * Download a blob
+ */
public void run() {
URL url_obj = null;
try {
@@ -59,12 +60,12 @@ public class BlobDownloader extends Thread {
}
- int fileSize = con.getContentLength();
+ int fileSize = con.getContentLength(); // We get the file size to display a progress bar
try (InputStream in = con.getInputStream();
OutputStream out = new FileOutputStream(tmpdir + "/" + digest.replace("sha256:", "") + ".tar.gz")) {
- byte[] buffer = new byte[4096];
- int bytesRead;
+ byte[] buffer = new byte[4096]; // Always read in chunks of 4096 bytes
+ int bytesRead; // How many bytes were read, used to update the progress bar
try (ProgressBar pb = new ProgressBar("Download blob "+digest.replace("sha256:", ""), fileSize)) {
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
@@ -90,19 +91,22 @@ public class BlobDownloader extends Thread {
return;
}
- if (!extract) {
- return;
- }
- File extracted = new File(tmpdir + "/" + digest.replace("sha256:", ""));
- if (extracted.exists()) {
- extracted.delete();
- }
- SysUtils tarManager = new SysUtils();
- tarManager.untar(tmpdir + "/" + digest.replace("sha256:", "") + ".tar.gz", tmpdir + "/" + digest.replace("sha256:", ""));
- File tar = new File(tmpdir + "/" + digest.replace("sha256:", "") + ".tar.gz");
- if (tar.exists()) {
- tar.delete();
+ if (extract) {
+
+ File extracted = new File(tmpdir + "/" + digest.replace("sha256:", ""));
+ if (extracted.exists()) {
+ extracted.delete();
+ }
+ SysUtils tarManager = new SysUtils();
+
+ // Extract the downloaded tar.gz
+ tarManager.untar(tmpdir + "/" + digest.replace("sha256:", "") + ".tar.gz", tmpdir + "/" + digest.replace("sha256:", ""));
+
+ File tar = new File(tmpdir + "/" + digest.replace("sha256:", "") + ".tar.gz");
+ if (tar.exists()) {
+ tar.delete();
+ }
}
}
}