扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极开发 2007年11月3日
关键字:
Private Sub btnCompress_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnCompress.Click '---用来存储压缩的数据--- Dim compressedData() As Byte '---压缩数据--- If rbGZipStream.Checked Then compressedData = Compress("Gzip",System.Text.Encoding.ASCII.GetBytes(txtBefore.Text)) Else compressedData = Compress("Deflate",System.Text.Encoding.ASCII.GetBytes(txtBefore.Text)) End If '---把压缩的数据复制到一个字符串中--- Dim i As Integer Dim s As New System.Text.StringBuilder() For i = 0 To compressedData.Length - 1 If i <> compressedData.Length - 1 Then s.Append(compressedData(i) & " ") Else s.Append(compressedData(i)) End If Next '---显示压缩的数据为一个字符串--- txtAfter.Text = s.ToString End Sub |
Private Sub btnDecompress_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDecompress.Click '---把压缩的字符串格式化成一个字节数组--- Dim eachbyte() As String = txtAfter.Text.Split(" ") Dim data(eachbyte.Length - 1) As Byte For i As Integer = 0 To eachbyte.Length - 1 data(i) = Convert.ToByte(eachbyte(i)) Next '---解压数据并且显示解压的数据--- If rbGZipStream.Checked Then txtBefore.Text = System.Text.Encoding.ASCII.GetString(Decompress("Gzip", data)) Else txtBefore.Text = System.Text.Encoding.ASCII.GetString(Decompress("Deflate", data)) End If End Sub |
Private Sub btnSelectFile_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnSelectFile.Click '---让用户选择一个要压缩的文件-- Dim openFileDialog1 As New OpenFileDialog() 'openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "All files (*.*)|*.*" openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then '---把文件的内容读入字节数组--- Dim fileContents As Byte() fileContents = My.Computer.FileSystem.ReadAllBytes(openFileDialog1.FileName) '---创建gzip文件--- Dim filename As String = openFileDialog1.FileName & ".gzip" If File.Exists(filename) Then File.Delete(filename) Dim fs As FileStream = New FileStream(filename, FileMode.CreateNew, FileAccess.Write) '---压缩文件的内容--- Dim compressed_Data As Byte() If rbGZipStream.Checked Then compressed_Data = Compress("Gzip", fileContents) Else compressed_Data = Compress("Deflate", fileContents) End If If compressed_Data IsNot Nothing Then '---把压缩的内容写进压缩的文件中--- fs.Write(compressed_Data, 0, compressed_Data.Length) fs.Close() End If End If End Sub |
Private Sub btnDecompressFile_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDecompressFile.Click '---让用户选择一个要解压的文件--- Dim openFileDialog1 As New OpenFileDialog() ' openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "All GZIP files (*.gzip)|*.gzip" openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then '---把压缩的文件的内容读入到字节数组--- Dim fileContents As Byte() fileContents = My.Computer.FileSystem.ReadAllBytes(openFileDialog1.FileName) '---解压文件的内容--- Dim uncompressed_Data As Byte() If rbGZipStream.Checked Then uncompressed_Data = Decompress("Gzip", fileContents) Else uncompressed_Data = Decompress("Deflat", fileContents) End If '---创建解压的文件--- Dim filename As String = openFileDialog1.FileName.Substring(0, openFileDialog1.FileName.Length - 5) If File.Exists(filename) Then File.Delete(filename) Dim fs As FileStream = New FileStream(filename,FileMode.CreateNew, FileAccess.Write) If uncompressed_Data IsNot Nothing Then '---把解压内容写入到文件中--- fs.Write(uncompressed_Data, 0, uncompressed_Data.Length) fs.Close() End If End If End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者