From cdae86aad61c97158fd57a15209f8e3d96b8746a Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 12 Sep 2020 14:24:09 +0100 Subject: [PATCH] Truncate existing output files in the compression commands Signed-off-by: Graham --- .../main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt | 2 +- .../main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt | 2 +- .../java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt | 2 +- .../java/dev/openrs2/compress/cli/deflate/InflateCommand.kt | 2 +- .../main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt | 2 +- .../src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt | 2 +- .../src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt | 2 +- .../main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt index a69d5611..b72c277a 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bunzip2Command.kt @@ -10,7 +10,7 @@ import dev.openrs2.compress.bzip2.Bzip2 public class Bunzip2Command : CliktCommand(name = "bunzip2") { 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() { Bzip2.createHeaderlessInputStream(input).use { input -> diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt index 0b0f9355..00f8cbb9 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/bzip2/Bzip2Command.kt @@ -10,7 +10,7 @@ import dev.openrs2.compress.bzip2.Bzip2 public class Bzip2Command : CliktCommand(name = "bzip2") { 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() { input.use { input -> diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt index bb3f7cd5..78199f0a 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/DeflateCommand.kt @@ -14,7 +14,7 @@ import java.util.zip.DeflaterOutputStream public class DeflateCommand : CliktCommand(name = "deflate") { 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 { require(it >= Deflater.NO_COMPRESSION && it <= Deflater.BEST_COMPRESSION) { "--level must be between ${Deflater.NO_COMPRESSION} and ${Deflater.BEST_COMPRESSION} inclusive" diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/InflateCommand.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/InflateCommand.kt index 433f57be..e429caae 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/InflateCommand.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/deflate/InflateCommand.kt @@ -11,7 +11,7 @@ import java.util.zip.InflaterInputStream public class InflateCommand : CliktCommand(name = "inflate") { 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() { InflaterInputStream(input, Inflater(true)).use { input -> diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt index edd67178..bca04bec 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GunzipCommand.kt @@ -10,7 +10,7 @@ import dev.openrs2.compress.gzip.Gzip public class GunzipCommand : CliktCommand(name = "gunzip") { 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() { Gzip.createHeaderlessInputStream(input).use { input -> diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt index bbd653d2..becca157 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/gzip/GzipCommand.kt @@ -14,7 +14,7 @@ import java.util.zip.Deflater public class GzipCommand : CliktCommand(name = "gzip") { 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 { require(it >= Deflater.NO_COMPRESSION && it <= Deflater.BEST_COMPRESSION) { "--level must be between ${Deflater.NO_COMPRESSION} and ${Deflater.BEST_COMPRESSION} inclusive" diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt index aad1b45c..42a06a42 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/LzmaCommand.kt @@ -14,7 +14,7 @@ import org.tukaani.xz.LZMA2Options public class LzmaCommand : CliktCommand(name = "lzma") { 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 { require(it >= LZMA2Options.PRESET_MIN && it <= LZMA2Options.PRESET_MAX) { "--level must be between ${LZMA2Options.PRESET_MIN} and ${LZMA2Options.PRESET_MAX} inclusive" diff --git a/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt b/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt index 2fb8f172..ab6a1173 100644 --- a/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt +++ b/compress-cli/src/main/java/dev/openrs2/compress/cli/lzma/UnlzmaCommand.kt @@ -13,7 +13,7 @@ import dev.openrs2.compress.lzma.Lzma public class UnlzmaCommand : CliktCommand(name = "unlzma") { private val input by option().inputStream().defaultStdin() 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() { Lzma.createHeaderlessInputStream(input, length).use { input ->