This is my first question here, so bear with me.
What I'm going to do is just create a basic .zip archive in C #. I tried using the built-in GZipStream
.NET class and was able to accomplish this, but then I have a problem that I cannot name the file "usercode.zip" without losing its extension. Due to limitations, I cannot force my program to create these files as "usercode.trf.zip", which is the only way I found to leave the file extension unchanged inside the archive.
I tried using a number of other zipping libraries, and I cannot get them to work properly or the way I want.
I came across the SevenZipHelper
library, which provides some useful functions for using the LZMA (or 7-zip) library to compress a file.
The code I use is as follows:
//Take the BF file and zip it, using 7ZipHelper BinaryReader bReader = new BinaryReader(File.Open(pFileName, FileMode.Open)); byte[] InBuf = new byte[Count]; bReader.Read(InBuf, 0, InBuf.Length); Console.WriteLine("ZIP: read for buffer length:" + InBuf.Length.ToString()); byte[] OutBuf = SevenZip.Compression.LZMA.SevenZipHelper.Compress(InBuf); FileStream BZipFile = new FileStream(pZipFileName, FileMode.OpenOrCreate, FileAccess.Write); BZipFile.Seek(0, SeekOrigin.Begin); BZipFile.Write(OutBuf, 0, OutBuf.Length); BZipFile.Close();
This creates the compressed file neatly using the 7-zip algorithm. The problem is that I can not guarantee that clients using this program will have access to 7-zip, so the file should be in the usual zip algorithm. I went through the assistant, as well as the 7-zip libraries, and it looks like this library can be used to compress the file using the usual "ZIP" algorithm. I just can't figure out how to do this. I noticed property settings in several places, but I can not find the documentation or google search to tell me where to set it.
I understand that there are probably better ways to do this, and that I just missed something, but I canβt sit and fight such a simple task forever. Any help would be greatly appreciated.