Added option to compress file backups by Pesekjak · Pull Request #8396 · SkriptLang/Skript

Conversation

@Pesekjak

Problem

Backups of variables.csv can take up a lot of space for some users.

Solution

There is now an option in config to turn on automatic compression of those files. This also applies to other file backups (lang and config). I also refactored the backup method to replace the legacy code.

Testing Completed

I tested this manually, I believe we don't need automated test for this.


Completes: #8083
Related: none
AI assistance: none

@3add

iirc Skript's contribution requirements requires that all {} are placed after if, else, for, etc

Edit: just for for appearantly

@sovdeeth

iirc Skript's contribution requirements requires that all {} are placed after if, else, for, etc

They can be omitted for single line ifs without elses

sovdeeth

@sovdeeth sovdeeth added the enhancement

Feature request, an issue about something that could be improved, or a PR improving something.

label

Jan 22, 2026

Efnilite

String newFileName = name + "_" + getBackupSuffix() + ext;
boolean compress = SkriptConfig.compressBackups.value();
if (compress)
newFileName += ".gz";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.zip is more accessible, why pick gz?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are they not both equally accessible?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with fusezion, also gzip is better suited for compression of single files

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mojang uses .gz for the log files

# Whether Skript should log the usage of effect commands.
# They will be logged as [INFORMATION] in this format: '<player> issued effect command: <command>'

compress backups: false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the downsides of setting this to true by default?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none (except you don't have to decompress to access) but I mainly wanted to keep the default behaviour the same as before. would you change it to true by default?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change it true by default, if you're trying to access and/or modify the variables file you'd have to know what you're doing in which case unzipping the file isn't an issue.

Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>

@TheLimeGlass

I recommend throwing some compression onto the GZip because the default compression isn't going to do much.

private static class GZIPOutputStreamWithLevel extends GZIPOutputStream {
	public GZIPOutputStreamWithLevel(OutputStream out, int level) throws IOException {
		super(out);
		this.def.setLevel(level);
	}
}
try (OutputStream os = Files.newOutputStream(backup); GZIPOutputStreamWithLevel gzipOs = new GZIPOutputStreamWithLevel(os, Deflater.BEST_COMPRESSION)) {
	Files.copy(source, gzipOs);
}

You can also use Apache's GzipCompressorOutputStream or TarArchiveOutputStream

Mojang uses the TarArchiveOutputStream for large files

Reviewers

@sovdeeth sovdeeth sovdeeth approved these changes

@Absolutionism Absolutionism Awaiting requested review from Absolutionism Absolutionism is a code owner automatically assigned from SkriptLang/core-developers

@TheMug06 TheMug06 Awaiting requested review from TheMug06 TheMug06 is a code owner automatically assigned from SkriptLang/core-developers

@Efnilite Efnilite Awaiting requested review from Efnilite

@TheLimeGlass TheLimeGlass Awaiting requested review from TheLimeGlass

+2 more reviewers

@Fusezion Fusezion Fusezion left review comments

@3add 3add 3add left review comments

Reviewers whose approvals may not affect merge requirements

Requested changes must be addressed to merge this pull request.

Labels

enhancement

Feature request, an issue about something that could be improved, or a PR improving something.