Skip to content

ZipWriter compression level cannot be customised #3

Closed

Description

@ansell

The ZipWriter compression level looks like it could be theoretically customised, but any settings for it, from 2-9, fail with the following error:

java.lang.IllegalArgumentException: Invalid compression level: -5
at org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.setLevel(ZipArchiveOutputStream.java:712)
at gov.loc.repository.bagit.writer.impl.ZipWriter.startBag(ZipWriter.java:70)
at gov.loc.repository.bagit.impl.AbstractBag.accept(AbstractBag.java:430)
at gov.loc.repository.bagit.writer.impl.ZipWriter.write(ZipWriter.java:158)

The error is due to the following call that uses whatever level the user sent in, and modifies it to be a negative number, which is always going to be invalid:

this.zipOut.setLevel(this.compressionLevel * -1);

Trying to set compressionLevel to be a negative number to fix this fails with the following error:

java.lang.RuntimeException: Valid compression levels are 0-9.
at gov.loc.repository.bagit.writer.impl.ZipWriter.setCompressionLevel(ZipWriter.java:55)

The reason that the default, 1, seems to work is that -1 is apparently a special value, although I am not sure what it represents.

Activity

  1. ansell commented on Feb 11, 2014

    @ansell
    ContributorAuthor

    This code does not seem to have been modified since it was first added, and the only test for it uses the default, 1 as the parameter.

    d8dd9ec#diff-17

  2. added a commit that references this issue on Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions