Allow single files to be uploaded without compression

We may choose to save on CPU by not compressing individual files, so this allows the network to support that. However it is still using compression by default, to reduce file sizes.
This commit is contained in:
CalDescent 2021-11-12 13:44:28 +00:00
parent 236a456cae
commit 8bebe11b4e
2 changed files with 15 additions and 4 deletions

View File

@ -358,10 +358,18 @@ public class ArbitraryDataReader {
} }
try { try {
// TODO: compression types // Handle each type of compression
//if (transactionData.getCompression() == ArbitraryTransactionData.Compression.ZIP) { if (transactionData.getCompression() == Compression.ZIP) {
ZipUtils.unzip(this.filePath.toString(), this.uncompressedPath.getParent().toString()); ZipUtils.unzip(this.filePath.toString(), this.uncompressedPath.getParent().toString());
//} }
else if (transactionData.getCompression() == Compression.NONE) {
Files.createDirectories(this.uncompressedPath);
Path finalPath = Paths.get(this.uncompressedPath.toString(), "data");
this.filePath.toFile().renameTo(finalPath.toFile());
}
else {
throw new IllegalStateException(String.format("Unrecognized compression type: %s", transactionData.getCompression()));
}
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(String.format("Unable to unzip file: %s", e.getMessage())); throw new IllegalStateException(String.format("Unable to unzip file: %s", e.getMessage()));
} }

View File

@ -65,7 +65,10 @@ public class ArbitraryDataTransactionBuilder {
random.nextBytes(lastReference); random.nextBytes(lastReference);
} }
ArbitraryTransactionData.Compression compression = ArbitraryTransactionData.Compression.ZIP; Compression compression = Compression.ZIP;
// FUTURE? Use zip compression for directories, or no compression for single files
// Compression compression = (path.toFile().isDirectory()) ? Compression.ZIP : Compression.NONE;
ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(path, name, service, identifier, method, compression); ArbitraryDataWriter arbitraryDataWriter = new ArbitraryDataWriter(path, name, service, identifier, method, compression);
try { try {