Extract zips while reading the chunks, instead reading them to memory first
This commit is contained in:
committed by
Sheepit Renderfarm
parent
154108dc38
commit
9f825b8d0f
@@ -45,6 +45,7 @@ import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Provides various general utility methods for the SheepIt client codebase
|
||||
@@ -105,18 +106,11 @@ public class Utils {
|
||||
*/
|
||||
public static int unzipChunksIntoDirectory(List<String> full_path_chunks, String destinationDirectory, char[] password, Log log) {
|
||||
try {
|
||||
// STEP 1: assemble the chunks into an actual zip (in RAM)
|
||||
ByteArrayOutputStream unzippedData = new ByteArrayOutputStream();
|
||||
|
||||
for (String full_path_chunk: full_path_chunks) {
|
||||
byte[] data = Files.readAllBytes(Paths.get(full_path_chunk));
|
||||
|
||||
unzippedData.write(data);
|
||||
}
|
||||
byte[] full_data = unzippedData.toByteArray();
|
||||
// STEP 1: Create a ChunkInputStream, which will read the chunks' contents in order
|
||||
ChunkInputStream chunkInputStream = new ChunkInputStream(full_path_chunks.stream().map(Paths::get).collect(Collectors.toList()));
|
||||
|
||||
// STEP 2: unzip the zip like before
|
||||
ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(full_data));
|
||||
ZipInputStream zipInputStream = new ZipInputStream(chunkInputStream);
|
||||
if (password != null) {
|
||||
zipInputStream.setPassword(password);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user