phoenicis
phoenicis copied to clipboard
Improve Progress Visualisation during Zip Extraction
Currently we update the progress bar during a zip archive extraction only after a complete file has been fully extracted. This leads to visible jumps in the progress bar which does not look really smooth to the user.
To improve on this we can replace the current
Files.copy(in, targetPath, StandardCopyOption.REPLACE_EXISTING);
Operation with a loop that manually copies the file content byte block for byte block. This allows us to update the progress bar more often to give the user a more smooth feeling.
Here an example how a byte stream can be manually copied in byte blocks (copied from https://github.com/PhoenicisOrg/phoenicis/pull/2064#discussion_r320432566):
long counter = 0;
int r = 0;
byte[] b = new byte[1024];
fin = new FileInputStream(filein);
fout = new FileOutputStream(fileout);
while( (r = fin.read(b)) != -1) {
counter += r;
// update the progress bar
fout.write(b, 0, r);
}
Notes:
I'm not sure if counter
contains the number of compressed or uncompressed bytes...
Additionally the input stream wouldn't be of type FileInputStream
. Instead it would be of whatever type apache-compress
gives us
To test, use a big archive like in https://github.com/PhoenicisOrg/scripts/pull/1081.