Use a buffered digest where possible instead of reading the whole file contents into memory.

This commit is contained in:
CalDescent 2021-10-30 18:21:06 +01:00
parent 60f96d15bd
commit bada4fd140
2 changed files with 3 additions and 5 deletions

View File

@ -350,7 +350,7 @@ public class ArbitraryDataDiff {
private static byte[] digestFromPath(Path path) {
try {
return Crypto.digest(Files.readAllBytes(path));
return Crypto.digest(path.toFile());
} catch (IOException e) {
return null;
}

View File

@ -111,8 +111,7 @@ public class ArbitraryDataFile {
File file = path.toFile();
if (file.exists()) {
try {
byte[] fileContent = Files.readAllBytes(file.toPath());
byte[] digest = Crypto.digest(fileContent);
byte[] digest = Crypto.digest(file);
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(digest);
// Copy file to data directory if needed
@ -502,8 +501,7 @@ public class ArbitraryDataFile {
File file = this.getFile();
if (file != null && file.exists()) {
try {
byte[] fileContent = Files.readAllBytes(file.toPath());
return Crypto.digest(fileContent);
return Crypto.digest(file);
} catch (IOException e) {
LOGGER.error("Couldn't compute digest for ArbitraryDataFile");