Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression Format 7zip Unless Explicitly Defined When Extension Provided for Archive #24

Closed
onyxhat opened this issue Sep 12, 2016 · 2 comments

Comments

@onyxhat
Copy link

onyxhat commented Sep 12, 2016

I noticed that the archives always seemed to be using the 7z packaging regardless of what I specified saving the archive as (e.g. .zip, .bzip, .tar, etc.). I implemented a basic switch that correctly infers the archive format based on the archive extension - the ArchiveFormat flag can still be used as an override, but otherwise seems unnecessary and this reduced instances where the flag isn't passed and other extraction utilities think they have a .tar.gz but are in fact needing to decompress a 7z archive which they may be unable to handle correctly.

Quick and dirty implementation, but worked in my fork;

                switch (System.IO.Path.GetExtension(archiveFileName).ToLowerInvariant()) {
                    case ".7z":
                        _cmdlet.Format = OutArchiveFormat.SevenZip;
                        break;
                    case ".zip":
                        _cmdlet.Format = OutArchiveFormat.Zip;
                        break;
                    case ".gz":
                        _cmdlet.Format = OutArchiveFormat.GZip;
                        break;
                    case ".bz2":
                        _cmdlet.Format = OutArchiveFormat.BZip2;
                        break;
                    case ".tar":
                        _cmdlet.Format = OutArchiveFormat.Tar;
                        break;
                    case ".xz":
                        _cmdlet.Format = OutArchiveFormat.XZ;
                        break;
                }
@thoemmi
Copy link
Owner

thoemmi commented Sep 12, 2016

I like the idea. I think I'll introduce a new enum for the output format with the same members as OutArchiveFormat plus Auto. If Auto is passed (which would be the default), it would try to infer the format from the archive file name, otherwise as specified.

private OutArchiveFormat GetInferredOutArchiveFormat() {
    switch (Format) {
        case OutputFormat.Auto:
            switch (System.IO.Path.GetExtension(ArchiveFileName).ToLowerInvariant()) {
                case ".zip":
                    return OutArchiveFormat.Zip;
                case ".gz":
                    return OutArchiveFormat.GZip;
                case ".bz2":
                    return OutArchiveFormat.BZip2;
                case ".tar":
                    return OutArchiveFormat.Tar;
                case ".xz":
                    return OutArchiveFormat.XZ;
                default:
                    return OutArchiveFormat.SevenZip;
            }
        case OutputFormat.SevenZip:
            return OutArchiveFormat.SevenZip;
        case OutputFormat.Zip:
            return OutArchiveFormat.Zip;
        case OutputFormat.GZip:
            return OutArchiveFormat.GZip;
        case OutputFormat.BZip2:
            return OutArchiveFormat.BZip2;
        case OutputFormat.Tar:
            return OutArchiveFormat.Tar;
        case OutputFormat.XZ:
            return OutArchiveFormat.XZ;
        default:
            throw new ArgumentOutOfRangeException();
    }
}

@thoemmi
Copy link
Owner

thoemmi commented Oct 16, 2016

This change is included in V1.7, released today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants