Skip to content

Add support for Original filename field in gzip header #175

Closed

Description

@afonsoft

Steps to reproduce

  1. Compress file foo.txt using gzip to foo.txt.gz
  2. Rename foo.txt.gz to bar.txt.gz
  3. Decompress file bar.txt.gz

Expected behavior

Output filename should be foo.txt

Actual behavior

Output filename is bar.txt

Version of SharpZipLib

Obtained from (place an x between the brackets for all that apply)

  • Compiled from source
  • Downloaded DLL from GitHub

Activity

  1. afonsoft commented on Apr 13, 2017

    @afonsoft
    Author

    Change this file ICSharpCode.SharpZipLib.GZip.GZipOutputStream.cs

    Create a two property

            /// <summary>
            /// Get the current compression level.
            /// </summary>
            /// <returns>The current compression level.</returns>
            public int GetLevel()
            {
                return deflater_.GetLevel();
            }
            
            /// <summary>
            /// Set a file name internal gzip
            /// </summary>
            /// <param name="filename">name of file zipped</param>
            public void SetFileName(string filename)
            {
                _fileName = filename;
            }

    On "Support Routines" modify the method WriteHeader().

    After the code baseOutputStream_.Write(gzipHeader, 0, gzipHeader.Length);

    Inlude a code

    if (!string.IsNullOrEmpty(_fileName)) 
    { 
        var fileNameBytes = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(_fileName); 
        Array.Resize<byte>(ref fileNameBytes, fileNameBytes.Length + 1); 
        fileNameBytes[fileNameBytes.Length - 1] = 0; 
        baseOutputStream_.Write(fileNameBytes, 0, fileNameBytes.Length); 
    }
  2. changed the title [-]Set and Get a file name internal gzip[/-] [+]Add support for Original filename field in gzip header[/+] on May 12, 2018
  3. piksel commented on May 12, 2018

    @piksel
    Member

    I've updated the question and the proposed solution to what I understand is the issue, please correct me if I misunderstood.

    A filename can be added to the gzip header if the flag FNAME is set.
    Reference: https://tools.ietf.org/html/rfc1952#section-2.3.1

    This could be made into a PR.

  4. added
    enhancement
    on May 12, 2018
  5. self-assigned this
    on Nov 22, 2020
  6. linked a pull request that will close this issueAdd support for Filename field in GZip #351on Nov 22, 2020
  7. linked a pull request that will close this issueSet and Get a file name internal gzip #366on Nov 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions