Hi Jyoti,
You could create a zip archive while streaming by using the ZipWriter that wraps your Stream, fileStream1, class as follow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using Xceed.Zip.ReaderWriter;
namespace WriteToZip
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 2)
{
string tempPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
using (FileStream fileStream1 = new FileStream(tempPath + @"\" + args[0], FileMode.Create, FileAccess.Write))
{
//Create the ZipWriter object around the stream.
Xceed.Zip.ReaderWriter.ZipWriter zipWriter1 =
new Xceed.Zip.ReaderWriter.ZipWriter(fileStream1);
//Create ZipItemLocalHeader for current item and write to archive.
ZipItemLocalHeader zipItemLocalHeader1 = new ZipItemLocalHeader
("zipItem.txt",Xceed.Compression.CompressionMethod.Deflated,Xceed.Compression.CompressionLevel.Highest);
zipWriter1.WriteItemLocalHeader(zipItemLocalHeader1);
byte[] buffer = new byte[1024];
int bufferIndex = 0;
for (int words = 1; words < args.Length; words++)
{
for (int i = 0; i < args[words].Length; i++)
buffer[bufferIndex++] = (byte)args[words]
;
if(words<args.Length-1)
buffer[bufferIndex++] = 32;
}
int read = 0;
//Write the current item's data to the Zip archive
zipWriter1.WriteItemData(buffer, 0, bufferIndex);
Console.WriteLine("Writing {0}. {1} bytes written.",
zipItemLocalHeader1.FileName, bufferIndex);
//Close the Zip archive. Writes the archive's central header.
zipWriter1.CloseZipFile();
Console.WriteLine("Zip archive created.");
}
} else
{
Console.WriteLine("Usage: " + Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName) + " ZipFileToCreate.Zip TextToEncode");
}
}
}
}
Xceed - Software Developer and Technical Support