Truncate existing output files in the compression commands

Signed-off-by: Graham <gpe@openrs2.dev>
bzip2
Graham 4 years ago
parent 107c432e65
commit cdae86aad6
  1. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt
  2. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt
  3. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt
  4. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/InflateCommand.kt
  5. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt
  6. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt
  7. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt
  8. 2
      compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt

@ -10,7 +10,7 @@ import dev.openrs2.compress.bzip2.Bzip2
public class Bunzip2Command : CliktCommand(name = "bunzip2") { public class Bunzip2Command : CliktCommand(name = "bunzip2") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
override fun run() { override fun run() {
Bzip2.createHeaderlessInputStream(input).use { input -> Bzip2.createHeaderlessInputStream(input).use { input ->

@ -10,7 +10,7 @@ import dev.openrs2.compress.bzip2.Bzip2
public class Bzip2Command : CliktCommand(name = "bzip2") { public class Bzip2Command : CliktCommand(name = "bzip2") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
override fun run() { override fun run() {
input.use { input -> input.use { input ->

@ -14,7 +14,7 @@ import java.util.zip.DeflaterOutputStream
public class DeflateCommand : CliktCommand(name = "deflate") { public class DeflateCommand : CliktCommand(name = "deflate") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
private val level by option().int().default(Deflater.BEST_COMPRESSION).validate { private val level by option().int().default(Deflater.BEST_COMPRESSION).validate {
require(it >= Deflater.NO_COMPRESSION && it <= Deflater.BEST_COMPRESSION) { require(it >= Deflater.NO_COMPRESSION && it <= Deflater.BEST_COMPRESSION) {
"--level must be between ${Deflater.NO_COMPRESSION} and ${Deflater.BEST_COMPRESSION} inclusive" "--level must be between ${Deflater.NO_COMPRESSION} and ${Deflater.BEST_COMPRESSION} inclusive"

@ -11,7 +11,7 @@ import java.util.zip.InflaterInputStream
public class InflateCommand : CliktCommand(name = "inflate") { public class InflateCommand : CliktCommand(name = "inflate") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
override fun run() { override fun run() {
InflaterInputStream(input, Inflater(true)).use { input -> InflaterInputStream(input, Inflater(true)).use { input ->

@ -10,7 +10,7 @@ import dev.openrs2.compress.gzip.Gzip
public class GunzipCommand : CliktCommand(name = "gunzip") { public class GunzipCommand : CliktCommand(name = "gunzip") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
override fun run() { override fun run() {
Gzip.createHeaderlessInputStream(input).use { input -> Gzip.createHeaderlessInputStream(input).use { input ->

@ -14,7 +14,7 @@ import java.util.zip.Deflater
public class GzipCommand : CliktCommand(name = "gzip") { public class GzipCommand : CliktCommand(name = "gzip") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
private val level by option().int().default(Deflater.BEST_COMPRESSION).validate { private val level by option().int().default(Deflater.BEST_COMPRESSION).validate {
require(it >= Deflater.NO_COMPRESSION && it <= Deflater.BEST_COMPRESSION) { require(it >= Deflater.NO_COMPRESSION && it <= Deflater.BEST_COMPRESSION) {
"--level must be between ${Deflater.NO_COMPRESSION} and ${Deflater.BEST_COMPRESSION} inclusive" "--level must be between ${Deflater.NO_COMPRESSION} and ${Deflater.BEST_COMPRESSION} inclusive"

@ -14,7 +14,7 @@ import org.tukaani.xz.LZMA2Options
public class LzmaCommand : CliktCommand(name = "lzma") { public class LzmaCommand : CliktCommand(name = "lzma") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
private val level by option().int().default(LZMA2Options.PRESET_DEFAULT).validate { private val level by option().int().default(LZMA2Options.PRESET_DEFAULT).validate {
require(it >= LZMA2Options.PRESET_MIN && it <= LZMA2Options.PRESET_MAX) { require(it >= LZMA2Options.PRESET_MIN && it <= LZMA2Options.PRESET_MAX) {
"--level must be between ${LZMA2Options.PRESET_MIN} and ${LZMA2Options.PRESET_MAX} inclusive" "--level must be between ${LZMA2Options.PRESET_MIN} and ${LZMA2Options.PRESET_MAX} inclusive"

@ -13,7 +13,7 @@ import dev.openrs2.compress.lzma.Lzma
public class UnlzmaCommand : CliktCommand(name = "unlzma") { public class UnlzmaCommand : CliktCommand(name = "unlzma") {
private val input by option().inputStream().defaultStdin() private val input by option().inputStream().defaultStdin()
private val length by option().long().required() private val length by option().long().required()
private val output by option().outputStream().defaultStdout() private val output by option().outputStream(truncateExisting = true).defaultStdout()
override fun run() { override fun run() {
Lzma.createHeaderlessInputStream(input, length).use { input -> Lzma.createHeaderlessInputStream(input, length).use { input ->

Loading…
Cancel
Save