JumpyNET
Well-known member
- Joined
- Apr 4, 2005
- Messages
- 151
I tried using "System.IO.Compression" to compress a stream I am saving to harddisk. It reduced the file size a bit, but when I recompressed the files again with an arhiving software the results amazed me. The uncompressed files squeezed in to much smaller files.
Here are the file sizes:
Uncompressed 256 KB
Uncompressed --> rar --> 64 KB
Uncompressed --> zip --> 75 KB
GZipStreamed 197 KB
GZipStreamed --> rar --> 107 KB
GZipStreamed --> zip --> 110 KB
What do you suggest? Should I save the files uncompressed and compress the files with some algorithm? Or do you know a better way to compress a FileStream?
Here is the code I am using:
[VB]
Public Sub SaveAllFunctionsToFile(ByVal SavePath As String, Optional ByVal Compress As Boolean = False)
Select Case Compress
Case True
Dim fs As New System.IO.FileStream(SavePath, IO.FileMode.Create)
Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim Compresser As New System.IO.Compression.GZipStream(fs, IO.Compression.CompressionMode.Compress, False)
s.Serialize(Compresser, AllFunctions)
Compresser.Close()
fs.Close()
Case False
Dim fs As New System.IO.FileStream(SavePath, IO.FileMode.Create)
Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
s.Serialize(fs, AllFunctions)
fs.Close()
End Select
End Sub
[/VB]
PS: I am using VB 2005 Express.
Here are the file sizes:
Uncompressed 256 KB
Uncompressed --> rar --> 64 KB
Uncompressed --> zip --> 75 KB
GZipStreamed 197 KB
GZipStreamed --> rar --> 107 KB
GZipStreamed --> zip --> 110 KB
What do you suggest? Should I save the files uncompressed and compress the files with some algorithm? Or do you know a better way to compress a FileStream?
Here is the code I am using:
[VB]
Public Sub SaveAllFunctionsToFile(ByVal SavePath As String, Optional ByVal Compress As Boolean = False)
Select Case Compress
Case True
Dim fs As New System.IO.FileStream(SavePath, IO.FileMode.Create)
Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
Dim Compresser As New System.IO.Compression.GZipStream(fs, IO.Compression.CompressionMode.Compress, False)
s.Serialize(Compresser, AllFunctions)
Compresser.Close()
fs.Close()
Case False
Dim fs As New System.IO.FileStream(SavePath, IO.FileMode.Create)
Dim s As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
s.Serialize(fs, AllFunctions)
fs.Close()
End Select
End Sub
[/VB]
PS: I am using VB 2005 Express.