From f3b11895e451ce3f1b752e2d639f1bcd62eca1f7 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 7 Jun 2019 12:10:18 +0100 Subject: [PATCH] utility for hashing files --- .../groovy/com/muwire/core/files/FileHasher.groovy | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy b/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy index ef4d3723..451c4378 100644 --- a/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy +++ b/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy @@ -67,4 +67,18 @@ class FileHasher { byte [] hashList = output.toByteArray() InfoHash.fromHashList(hashList) } + + public static void main(String[] args) { + if (args.length != 1) { + println "This utility computes an infohash of a file" + println "Pass absolute path to a file as an argument" + System.exit(1) + } + + def file = new File(args[0]) + file = file.getAbsoluteFile() + def hasher = new FileHasher() + def infohash = hasher.hashFile(file) + println infohash + } }