Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Zip{} does not compress files without SelectiveCompression enabled  #418

@hevav

Description

@hevav

What version of the package or command are you using?

743ede3

What are you trying to do?

I'm trying to make a zip archive with compression.

What steps did you take?

format := archiver.Zip{
	Compression:          zip.Deflate,
}
format.Archive(context.Background(), writer, file)

What did you expect to happen, and what actually happened instead?

Expected: the files should be compressed.
Actual: the files are not compressed at all.

How do you think this should be fixed?

We should append the else-clause in zip.go (last 3 lines in the code snippet below):

	if file.IsDir() {
		if !strings.HasSuffix(hdr.Name, "/") {
			hdr.Name += "/" // required
		}
		hdr.Method = zip.Store
	} else if z.SelectiveCompression {
		// only enable compression on compressable files
		ext := strings.ToLower(path.Ext(hdr.Name))
		if _, ok := compressedFormats[ext]; ok {
			hdr.Method = zip.Store
		} else {
			hdr.Method = z.Compression
		}
	} else {
	        hdr.Method = z.Compression
	}

Workaround

It works as expected when I enable SelectiveCompression:

format := archiver.Zip{
	SelectiveCompression: true,
	Compression:          zip.Deflate,
}
format.Archive(context.Background(), writer, file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions