Search code examples
c#rar

C# : choosing the title and the extension of the archived file


I'm trying to copy a file to a rar archive. it works with this code,

            using (FileStream fStream = File.Open(dest, FileMode.Create))
            {
                GZipStream obj = new GZipStream(fStream, CompressionMode.Compress);

                byte[] bt = File.ReadAllBytes(src);
                obj.Write(bt, 0, bt.Length);

                obj.Close();
                obj.Dispose();
            }

but i need to choose the name/extension of the file in the archive independently What do i need to?


Solution

  • That's not possible, just because you're not creating a rar archive at all, it's instead a gzip, which is a very simple compresed stream and very little extra metadata, unless more serious formats like rar, zip or 7z.

    You'll most likely want to control the name of the compressed file by adding a .gz extension. For example, if the original is "SomeText.txt", output it as "SomeText.txt.gz".