Advertisement
hoscanoa

Compress

Mar 28th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.37 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.IO.Compression
  3.  
  4. Public Class Form1
  5.  
  6.  
  7.     Private Sub tsComprimir_Click(sender As Object, e As EventArgs) Handles tsComprimir.Click
  8.         Dim sv As New SaveFileDialog
  9.         sv.Filter = "Archivo ZIP|*.zip"
  10.         Try
  11.             If sv.ShowDialog Then
  12.                 'Creando el archivo zip
  13.                 Dim fs As New FileStream(lblRuta.Text, FileMode.Open)
  14.                 Dim arreglo(fs.Length) As Byte
  15.  
  16.                 fs.Read(arreglo, 0, arreglo.Length)
  17.                 fs.Close()
  18.  
  19.                 'guardando dentro del archivo zipeado
  20.                 Using fsZip As New FileStream(sv.FileName, FileMode.Create)
  21.                     Using gZip As New GZipStream(fsZip, CompressionMode.Compress)
  22.                         gZip.Write(arreglo, 0, arreglo.Length)
  23.                     End Using
  24.                 End Using
  25.             End If
  26.         Catch ex As Exception
  27.  
  28.         End Try
  29.     End Sub
  30.  
  31.     Private Sub tsAbrir_Click(sender As Object, e As EventArgs) Handles tsAbrir.Click
  32.         Dim op As New OpenFileDialog
  33.         Try
  34.             If op.ShowDialog Then
  35.                 Using fs As New FileStream(op.FileName, FileMode.Open, FileAccess.Read)
  36.                     Using fr As New StreamReader(fs)
  37.                         txtEditor.Text = fr.ReadToEnd
  38.                         lblRuta.Text = op.FileName
  39.                     End Using
  40.                 End Using
  41.             End If
  42.         Catch ex As Exception
  43.  
  44.         End Try
  45.     End Sub
  46.  
  47.     Private Sub tsDescomprimir_Click(sender As Object, e As EventArgs) Handles tsDescomprimir.Click
  48.         Dim op As New OpenFileDialog
  49.         Try
  50.             If op.ShowDialog Then
  51.                 Using fsZip As New FileStream(op.FileName, FileMode.Open)
  52.                     Using uZip As New GZipStream(fsZip, CompressionMode.Decompress)
  53.                         Dim ms As New MemoryStream(10000)
  54.                         Dim b As Integer = uZip.ReadByte
  55.                         While b <> -1
  56.                             ms.WriteByte(CByte(b))
  57.                             b = uZip.ReadByte
  58.                         End While
  59.  
  60.                         ms.Position = 0
  61.  
  62.                         Using sr As New StreamReader(ms)
  63.                             txtEditor.Text = sr.ReadToEnd
  64.                         End Using
  65.                     End Using
  66.                 End Using
  67.             End If
  68.         Catch ex As Exception
  69.         End Try
  70.     End Sub
  71.  
  72.     Private Sub tsSalir_Click(sender As Object, e As EventArgs) Handles tsSalir.Click
  73.         End
  74.     End Sub
  75.  
  76.     Private Sub tsNuevo_Click(sender As Object, e As EventArgs) Handles tsNuevo.Click
  77.         txtEditor.Clear()
  78.         txtEditor.Focus()
  79.         lblRuta.Text = ""
  80.     End Sub
  81.  
  82.     Private Sub tsGuardar_Click(sender As Object, e As EventArgs) Handles tsGuardar.Click
  83.         Try
  84.             Dim sv As New SaveFileDialog
  85.             sv.Filter = "Archivo de Text|*.txt"
  86.             If sv.ShowDialog Then
  87.                 Using fs As New FileStream(sv.FileName, FileMode.Create, FileAccess.Write)
  88.                     Using fw As New StreamWriter(fs)
  89.                         fw.Write(txtEditor.Text)
  90.                         lblRuta.Text = sv.FileName
  91.                     End Using
  92.                 End Using
  93.             End If
  94.  
  95.         Catch ex As Exception
  96.  
  97.         End Try
  98.        
  99.  
  100.     End Sub
  101. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement