Browse Source

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.
qdn
CalDescent 3 years ago
parent
commit
8bebe11b4e
  1. 14
      src/main/java/org/qortal/arbitrary/ArbitraryDataReader.java
  2. 5
      src/main/java/org/qortal/arbitrary/ArbitraryDataTransactionBuilder.java

14
src/main/java/org/qortal/arbitrary/ArbitraryDataReader.java

@ -358,10 +358,18 @@ public class ArbitraryDataReader {
}
try {
// TODO: compression types
//if (transactionData.getCompression() == ArbitraryTransactionData.Compression.ZIP) {
// Handle each type of compression
if (transactionData.getCompression() == Compression.ZIP) {
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) {
throw new IllegalStateException(String.format("Unable to unzip file: %s", e.getMessage()));
}

5
src/main/java/org/qortal/arbitrary/ArbitraryDataTransactionBuilder.java

@ -65,7 +65,10 @@ public class ArbitraryDataTransactionBuilder {
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);
try {

Loading…
Cancel
Save