Dim compres As IO.Compression.CompressionMode TextBox1.Text = IO.Compression.CompressionMode.Compress = IO.Compression.CompressionMode.Compress = 1
And I dont understand how to use the compression
(This is the complete code I cant work this out lol)




Posted 26 February 2009 - 11:26 AM
Dim compres As IO.Compression.CompressionMode TextBox1.Text = IO.Compression.CompressionMode.Compress = IO.Compression.CompressionMode.Compress = 1
Posted 26 February 2009 - 11:43 AM
Posted 26 February 2009 - 11:48 AM
Public Function CompressFile(ByRef file As String, ByRef destination As String) As Boolean
Dim source() As Byte
Dim compressed() As Byte
' Validate paths
If IO.File.Exists(file) = False Then
MessageBox.Show("Please specify the valid file path to compress")
Return False
Exit Function
Else
If IO.Directory.Exists(destination) = False Then
MessageBox.Show("Please specify the valid path of destination folder")
Return False
Exit Function
End If
End If
Try
Dim name As String = file.Substring(file.LastIndexOf("\") + 1)
source = System.IO.File.ReadAllBytes(file)
compressed = Compress(source)
System.IO.File.WriteAllBytes(destination & "\" & name & ".zip", compressed)
MessageBox.Show("Compression Successful!")
Return True
Catch ex As Exception
MessageBox.Show("Compression Error: " & ex.ToString())
End Try
End Function
Public Function Compress(ByVal byteSource() As Byte) As Byte()
' Create a GZipStream object and memory stream object to store compressed stream
Dim memoryStream As New MemoryStream()
Dim gZipStream As New GZipStream(memoryStream, CompressionMode.Compress, True)
gZipStream.Write(byteSource, 0, byteSource.Length)
gZipStream.Dispose()
memoryStream.Position = 0
' Write compressed memory stream into byte array
Dim buffer(memoryStream.Length) As Byte
memoryStream.Read(buffer, 0, buffer.Length)
memoryStream.Dispose()
Return buffer
End Function
Posted 26 February 2009 - 12:00 PM
This post has been edited by Asscotte: 26 February 2009 - 12:06 PM
Posted 26 February 2009 - 12:06 PM
Public Function CompressFile(ByRef file As String, ByRef destination As String) As String
Dim source() As Byte
Dim compressed() As Byte
Dim message as String = string.Empty
' Validate paths
If IO.File.Exists(file) = False Then
message "Please specify the valid file path to compress"
Exit Function
Else
If IO.Directory.Exists(destination) = False Then
message "Please specify the valid path of destination folder"
Exit Function
End If
End If
Try
Dim name As String = file.Substring(file.LastIndexOf("\") + 1)
source = System.IO.File.ReadAllBytes(file)
compressed = Compress(source)
System.IO.File.WriteAllBytes(destination & "\" & name & ".zip", compressed)
message "Compression Successful!"
Catch ex As Exception
message "Compression Error: " & ex.ToString()
End Try
return message
End Function
Public Function Compress(ByVal byteSource() As Byte) As Byte()
' Create a GZipStream object and memory stream object to store compressed stream
Dim memoryStream As New MemoryStream()
Dim gZipStream As New GZipStream(memoryStream, CompressionMode.Compress, True)
gZipStream.Write(byteSource, 0, byteSource.Length)
gZipStream.Dispose()
memoryStream.Position = 0
' Write compressed memory stream into byte array
Dim buffer(memoryStream.Length) As Byte
memoryStream.Read(buffer, 0, buffer.Length)
memoryStream.Dispose()
Return buffer
End Function
MessageBox.Show(CompressFile(TextBox1.Text, TextBox2.Text)
Posted 26 February 2009 - 12:54 PM
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
