Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.IO.Compression
- Public Class Form1
- Private Sub tsComprimir_Click(sender As Object, e As EventArgs) Handles tsComprimir.Click
- Dim sv As New SaveFileDialog
- sv.Filter = "Archivo ZIP|*.zip"
- Try
- If sv.ShowDialog Then
- 'Creando el archivo zip
- Dim fs As New FileStream(lblRuta.Text, FileMode.Open)
- Dim arreglo(fs.Length) As Byte
- fs.Read(arreglo, 0, arreglo.Length)
- fs.Close()
- 'guardando dentro del archivo zipeado
- Using fsZip As New FileStream(sv.FileName, FileMode.Create)
- Using gZip As New GZipStream(fsZip, CompressionMode.Compress)
- gZip.Write(arreglo, 0, arreglo.Length)
- End Using
- End Using
- End If
- Catch ex As Exception
- End Try
- End Sub
- Private Sub tsAbrir_Click(sender As Object, e As EventArgs) Handles tsAbrir.Click
- Dim op As New OpenFileDialog
- Try
- If op.ShowDialog Then
- Using fs As New FileStream(op.FileName, FileMode.Open, FileAccess.Read)
- Using fr As New StreamReader(fs)
- txtEditor.Text = fr.ReadToEnd
- lblRuta.Text = op.FileName
- End Using
- End Using
- End If
- Catch ex As Exception
- End Try
- End Sub
- Private Sub tsDescomprimir_Click(sender As Object, e As EventArgs) Handles tsDescomprimir.Click
- Dim op As New OpenFileDialog
- Try
- If op.ShowDialog Then
- Using fsZip As New FileStream(op.FileName, FileMode.Open)
- Using uZip As New GZipStream(fsZip, CompressionMode.Decompress)
- Dim ms As New MemoryStream(10000)
- Dim b As Integer = uZip.ReadByte
- While b <> -1
- ms.WriteByte(CByte(b))
- b = uZip.ReadByte
- End While
- ms.Position = 0
- Using sr As New StreamReader(ms)
- txtEditor.Text = sr.ReadToEnd
- End Using
- End Using
- End Using
- End If
- Catch ex As Exception
- End Try
- End Sub
- Private Sub tsSalir_Click(sender As Object, e As EventArgs) Handles tsSalir.Click
- End
- End Sub
- Private Sub tsNuevo_Click(sender As Object, e As EventArgs) Handles tsNuevo.Click
- txtEditor.Clear()
- txtEditor.Focus()
- lblRuta.Text = ""
- End Sub
- Private Sub tsGuardar_Click(sender As Object, e As EventArgs) Handles tsGuardar.Click
- Try
- Dim sv As New SaveFileDialog
- sv.Filter = "Archivo de Text|*.txt"
- If sv.ShowDialog Then
- Using fs As New FileStream(sv.FileName, FileMode.Create, FileAccess.Write)
- Using fw As New StreamWriter(fs)
- fw.Write(txtEditor.Text)
- lblRuta.Text = sv.FileName
- End Using
- End Using
- End If
- Catch ex As Exception
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement