Merge remote-tracking branch 'FabricMC/dev/0.9' into dev/0.9

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-07-13 17:52:49 +08:00
155 changed files with 524 additions and 201 deletions

View File

@@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
* Copyright (c) 2016-2020 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@ package net.fabricmc.loom.util;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import com.google.common.hash.HashCode;
@@ -63,6 +64,15 @@ public class Checksum {
}
}
public static String truncatedSha256(File file) {
try {
HashCode hash = Files.asByteSource(file).hash(Hashing.sha256());
return hash.toString().substring(0, 12);
} catch (IOException e) {
throw new UncheckedIOException("Failed to get file hash of " + file, e);
}
}
public static byte[] sha256(String string) {
HashCode hash = Hashing.sha256().hashString(string, StandardCharsets.UTF_8);
return hash.asBytes();