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

Add support for Original filename field in gzip header #175

Closed
afonsoft opened this issue Apr 13, 2017 · 2 comments · Fixed by #351
Closed

Add support for Original filename field in gzip header #175

afonsoft opened this issue Apr 13, 2017 · 2 comments · Fixed by #351
Assignees
Labels
enhancement Feature request or other improvements of existing functionality

Comments

@afonsoft
Copy link

afonsoft commented Apr 13, 2017

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
@afonsoft
Copy link
Author

afonsoft commented Apr 13, 2017

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); 
}

@piksel piksel changed the title Set and Get a file name internal gzip Add support for Original filename field in gzip header May 12, 2018
@piksel
Copy link
Member

piksel commented May 12, 2018

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.

@piksel piksel added the enhancement Feature request or other improvements of existing functionality label May 12, 2018
@piksel piksel added this to Preparation in Feature Requests Nov 22, 2020
@piksel piksel moved this from Preparation to In progress in Feature Requests Nov 22, 2020
@piksel piksel self-assigned this Nov 22, 2020
Feature Requests automation moved this from In progress to Done Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or other improvements of existing functionality
Projects
2 participants