Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

Set a internal file name of gzip file.

$
0
0

Hi, I need set a file name internal of gzip.

I re-compiler ICSharpCode.SharpZipLib.csproj 

I modifided a class GZipOutputStream

Create a new method 

private string _fname = "";

/// <summary>

/// Sets the name of internal file of gzip

/// Create by Afonso Dutra

/// </summary>

/// <param name="name">name of internal file in de gzip</param>

public void SetFileName(string name)

{

_fname = name;

}

And I modifided a exist method WriteHeader()

                         //AFONSO 

byte[ fname = { 0 };

if (!string.IsNullOrEmpty(_fname))

{

fname = Encoding.GetEncoding("ISO-8859-1").GetBytes(_fname);

Array.Resize<byte>(ref fname, fname.Length + 1);

fname[fname.Length - 1] = 0;

}

//END AFONSO

And modifided de byte of Header

 

byte[ gzipHeader = {

// The two magic bytes

(byte) (GZipConstants.GZIP_MAGIC >> 8),

(byte) (GZipConstants.GZIP_MAGIC & 0xff),

// The compression type

(byte) Deflater.DEFLATED,

// The flags (not set)

(byte) (!string.IsNullOrEmpty(_fname) ?  GZipConstants.FNAME : 0), 

// The modification time

(byte) mod_time,

(byte) (mod_time >> 8),

(byte) (mod_time >> 16),

(byte) (mod_time >> 24),

// The extra flags

0,

// 255 The OS type (unknown)

// 0 FAT filesystem (MS-DOS, OS/2, NT/Win32)

(byte) 0 //255

};

 

For incluide a real file name in gzip, include is function after "baseOutputStream_.Write(gzipHeader, 0, gzipHeader.Length);"

                            //AFONSO

if (!string.IsNullOrEmpty(_fname))

baseOutputStream_.Write(fname, 0, fname.Length);

//END AFONSO

 

It´s possible incluide this code for future release?

 

Thanks.

 


Viewing all articles
Browse latest Browse all 1764

Trending Articles