forked from openrs2/openrs2
This is useful for checking the CRC-32 checksum of files used by the loader. It outputs the checksum in signed decimal format, which is the format used in the file name suffixes in the loader (e.g. unpackclass_-1911426584.pack). Signed-off-by: Graham <gpe@openrs2.dev>bzip2
parent
c849c5ad46
commit
44fb2ebe25
@ -0,0 +1,29 @@ |
||||
plugins { |
||||
`maven-publish` |
||||
application |
||||
kotlin("jvm") |
||||
} |
||||
|
||||
application { |
||||
mainClassName = "dev.openrs2.crc32.Crc32CommandKt" |
||||
} |
||||
|
||||
dependencies { |
||||
api(project(":cli")) |
||||
} |
||||
|
||||
publishing { |
||||
publications.create<MavenPublication>("maven") { |
||||
from(components["java"]) |
||||
|
||||
pom { |
||||
packaging = "jar" |
||||
name.set("OpenRS2 CRC-32") |
||||
description.set( |
||||
""" |
||||
A tool for calculating the CRC-32 checksum of a file. |
||||
""".trimIndent() |
||||
) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
package dev.openrs2.crc32 |
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand |
||||
import com.github.ajalt.clikt.parameters.options.option |
||||
import dev.openrs2.cli.defaultStdin |
||||
import dev.openrs2.cli.inputStream |
||||
import java.util.zip.CRC32 |
||||
|
||||
fun main(args: Array<String>) = Crc32Command().main(args) |
||||
|
||||
class Crc32Command : CliktCommand(name = "crc32") { |
||||
private val input by option().inputStream().defaultStdin() |
||||
|
||||
override fun run() { |
||||
val crc = CRC32() |
||||
|
||||
input.use { input -> |
||||
val bytes = ByteArray(4096) |
||||
|
||||
while (true) { |
||||
val len = input.read(bytes) |
||||
if (len == -1) { |
||||
break |
||||
} |
||||
|
||||
crc.update(bytes, 0, len) |
||||
} |
||||
} |
||||
|
||||
echo(crc.value.toInt()) |
||||
} |
||||
} |
Loading…
Reference in new issue