I search a lot of material, how to do; I got some code. I modify that code according to my requirement and develop two function; one compress data and other decompress it. You just need to pass your data file with complete path and it will compress the file & decompress too. Even you may use your own extension and embed it in your application.
System.IO.Compression is package and using GZip Compression & decompression method.
Use it and Enjoy!
Compression
Public Shared Sub Compress(ByVal strPath As String)
Dim current As DateTime
Dim dstFile As String = ""
' "C:\\temp\\compressed-file.gzip";
Dim fsIn As FileStream = Nothing
Dim fsOut As FileStream = Nothing
Dim gzip As GZipStream = Nothing
Dim buffer As Byte()
Dim count As Integer = 0
Try
current = DateTime.Now
dstFile = Application.StartupPath + "\" + "Request" + current.Day.ToString() + current.Month.ToString() + current.Year.ToString() + current.Hour.ToString() + current.Minute.ToString() + current.Second.ToString() + ".zip"
' may use own extension
fsOut = New FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None)
gzip = New GZipStream(fsOut, CompressionMode.Compress, True)
fsIn = New FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.Read)
buffer = New Byte(fsIn.Length - 1) {}
count = fsIn.Read(buffer, 0, buffer.Length)
fsIn.Close()
fsIn = Nothing
' compress to the destination file
gzip.Write(buffer, 0, buffer.Length)
Catch ex As Exception
' handle or display the error
System.Diagnostics.Debug.Assert(False, ex.ToString())
Finally
If gzip IsNot Nothing Then
gzip.Close()
gzip = Nothing
End If
If fsOut IsNot Nothing Then
fsOut.Close()
fsOut = Nothing
End If
If fsIn IsNot Nothing Then
fsIn.Close()
fsIn = Nothing
End If
End Try
End Sub
Decompression
Public Shared Sub Decompress(ByVal strPath As String)
Dim current As DateTime
Dim dstFile As String = ""
Dim fsIn As FileStream = Nothing
Dim fsOut As FileStream = Nothing
Dim gzip As GZipStream = Nothing
Const bufferSize As Integer = 4096
Dim buffer As Byte() = New Byte(bufferSize - 1) {}
Dim count As Integer = 0
Try
current = DateTime.Now
dstFile = Application.StartupPath + "\" + current.Day.ToString() + current.Month.ToString() + current.Year.ToString() + current.Hour.ToString() + current.Minute.ToString() + current.Second.ToString() + ".txt"
fsIn = New FileStream(strPath, FileMode.Open, FileAccess.Read, FileShare.Read)
fsOut = New FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None)
gzip = New GZipStream(fsIn, CompressionMode.Decompress, True)
While True
count = gzip.Read(buffer, 0, bufferSize)
If count <> 0 Then
fsOut.Write(buffer, 0, count)
End If
If count <> bufferSize Then
' have reached the end
Exit While
End If
End While
Catch ex As Exception
' handle or display the error
System.Diagnostics.Debug.Assert(False, ex.ToString())
Finally
If gzip IsNot Nothing Then
gzip.Close()
gzip = Nothing
End If
If fsOut IsNot Nothing Then
fsOut.Close()
fsOut = Nothing
End If
If fsIn IsNot Nothing Then
fsIn.Close()
fsIn = Nothing
End If
End Try
End Sub