Analisis Perbandingan Zero Compresion Dengan Difference Coding Pada Kompresi File Audio
1. Menu
ByVal e As System. EventArgs ) Handles AboutToolStripMenuItem.Click
Case
ByVal e As System. EventArgs ) Handles comboOperasi.SelectedIndexChanged Select Case comboOperasi.SelectedIndex
System. Object , _
Const PJG_BUFFER As Integer = 4096 Dim sfdTitle, ofdTitle, sfdFilter, ofdFilter As String Dim fsInput, fsOutput As FileStream Dim csObj As CryptStream Dim compressObj As ZERO.Zero. Compressor Dim decompressObj As ZERO.Zero. Decompressor Dim pesan As New Pesan () Dim Lama As Single Dim fileHslKompresi As String = "" Dim fileHslDekompresi As String = "" Dim fileHslEnkripsi As String = "" Dim fileHslDekripsi As String = "" Private Sub comboOperasi_SelectedIndexChanged( ByVal sender As
Imports System.IO Public Class frmZeroKom
2. ZeroKompresi
End Sub End Class
frmAbt .Show()
End Sub Private Sub AboutToolStripMenuItem_Click( ByVal sender As System. Object , _
Public Class frmMenu Private Sub HelpToolStripMenuItem_Click( ByVal sender As System. Object ,
System. Object , ByVal e As System. EventArgs ) Handles _ DifferenceCodingToolStripMenuItem.Click KomDekom .Show()
End Sub Private Sub DifferenceCodingToolStripMenuItem_Click( ByVal sender As _
System. Object , ByVal e As System. EventArgs ) Handles _ ZeroCompressionToolStripMenuItem.Click frmZeroKom .Show()
End Sub Private Sub ZeroCompressionToolStripMenuItem_Click( ByVal sender As _
ByVal e As System. EventArgs ) Handles QuitToolStripMenuItem.Click End
End Sub Private Sub QuitToolStripMenuItem_Click( ByVal sender As System. Object , _
frmHelp .Show()
ByVal e As System. EventArgs ) Handles HelpToolStripMenuItem.Click
sfdTitle = "Simpan file hasil Kompresi" ofdTitle = "Cari File yang akan diKompresi" ofdFilter = "File (*.wav)|*.wav" sfdFilter = "File hasil Kompresi (*.zc)|*.zc"
Case
1 sfdTitle = "Simpan file hasil deKompresi" ofdTitle = "Cari file yang akan dideKompresi" sfdFilter = "Semua file (*.wav)|*.wav" ofdFilter = "File hasil DeKompresi (*.zc)|*.zc"
End Select If comboOperasi.SelectedIndex >= 0 Then
aktifkanKomponen() 'kosongkanTextBox() cmdFileAsal.Focus()
End If End Sub Private Sub cmdProses_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdProses.Click
Dim LenKunci As Integer
LenKunci = Len(txtKunci.Text)
If LenKunci >= 5 Then Dim JamAwal As String Dim JamAkhir As String
JamAwal = Format(Now, "hh:mm:ss tt" ) proses()
Dim fileName1 As String = txtFileAsal.Text Dim fileName2 As String = txtFileTujuan.Text
'Dim fileData As String
Dim rasio As Single , Size1 As Single , Size2 As Single Dim fileDetails1 As System.IO. FileInfo = New
System.IO. FileInfo (fileName1)
Dim fileDetails2 As System.IO. FileInfo = New
System.IO. FileInfo (fileName2) Size1 = fileDetails1.Length.ToString Size2 = fileDetails2.Length.ToString rasio = ( Math .Abs(Size1 - Size2) / Size1) * 100 lblSize1.Text = Size1 & " Bytes" lblSize2.Text = Size2 & " Bytes" lblRasio.Text = rasio & " %"
List.Items.Add( " Ukuran File Asli Proses: " & comboOperasi.Text & "
"_ & Size1)List.Items.Add( " Ukuran File Hasil Proses: " & comboOperasi.Text &
" "_ & Size2) List.Items.Add( " Rasio Kompresi: " & rasio & " %" ) JamAkhir = Format(Now, "hh:mm:ss tt" ) Lama = (DateDiff( "s" , JamAkhir, JamAwal)) List.Items.Add( "Waktu: " & Lama & " Detik" ) lblLama.Text = Format( Math .Abs(Lama), "00" ) & " Detik"Else
MsgBox( "Panjang Password Harus > 5 char" ) txtKunci.Focus()
End If End Sub Private Sub cmdFileAsal_Click( ByVal sender As System. Object , ByVal e _
As System. EventArgs ) Handles cmdFileAsal.Click
openDialog.Title = ofdTitle openDialog.Filter = ofdFilter openDialog.ShowDialog()
If openDialog.FileName.Trim <> "" Then
txtFileAsal.Text = openDialog.FileName List.Items.Add( " Nama File Asli:" & (openDialog.FileName)) cmdFileTujuan.Focus()
End If End Sub Private Sub cmdFileTujuan_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdFileTujuan.Click saveDialog.Title = sfdTitle saveDialog.Filter = sfdFilter saveDialog.ShowDialog()
If saveDialog.FileName.Trim <> "" Then
txtFileTujuan.Text = saveDialog.FileName List.Items.Add( " Nama File Proses:" & (saveDialog.FileName)) txtKunci.Focus()
End If End Sub Private Sub txtKunci_KeyPress( ByVal sender As Object , ByVal e As _
System.Windows.Forms. KeyPressEventArgs ) Handles txtKunci.KeyPress
If Asc(e.KeyChar) = 13 Then
proses()
End If End Sub Private Sub cmdBatal_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdBatal.Click nonAktifkanKomponen() kosongkanTextBox()
End Sub Private Sub cmdKeluar_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdKeluar.Click
Me .Close() End Sub
#Region "Fungsi dan prosedur" Private Sub proses()
If comboOperasi.SelectedIndex >= 0 And cekMasukanLengkap() Then Select Case comboOperasi.SelectedIndex
Case
List.Items.Add( "Sedang melakukan kompresi..." ) kompresiDekompresiBerkas() List.Items.Add( "-----> Selesai <-----" ) pesan.pesanInfo( "Kompresi telah dilakukan." , "Informasi" )
Case
1 List.Items.Add( "Sedang melakukan dekompresi..." ) kompresiDekompresiBerkas() List.Items.Add( "-----> Selesai <-----" )
pesan.pesanInfo( "Dekompresi telah dilakukan." , "Informasi" )
End Select
List.Items.Add( "Ok" ) hapusFileTemporer() nonAktifkanKomponen()
End If End Sub Private Sub hapusFileTemporer()
Select Case comboOperasi.SelectedIndex Case
Dim fileDihapus As New FileInfo (fileHslEnkripsi)
fileDihapus.Delete()
Case
fileHslEnkripsi = arrFileTujuan(arrFileTujuan.Length - 2) & ".tmp"
fsOutput = New FileStream (fileHslEnkripsi, FileMode .OpenOrCreate_, FileAccess .Write)bytKunci(ctr) = Convert .ToByte(chrKunci(ctr)) ctr = ctr + 1
Dim chrKunci() As Char = txtKunci.Text.ToCharArray() Dim bytKunci(chrKunci.Length - 1) As Byte Dim ctr As Int32 = 0 While ctr < chrKunci.Length
fsOutput.SetLength(0)
Exit Sub End If
pesan.pesanError( "Ukuran maksimal berkas yang dapat diproses adalah
_sebesar 2.147.483.647 bit." , _ "Ukuran berkas terlalu besar" )Exit Sub End Try Dim lngPanjangBerkas As Long = fsInput.Length If lngPanjangBerkas > 2147483647 Then
IOException pesan.pesanError(ex.Message, "Akses berkas ditolak" )
Catch ex As
fsOutput = New FileStream(txtFileTujuan.Text, FileMode.OpenOrCreate,_ FileAccess.Write)
End Select
1 fsOutput = New FileStream (txtFileTujuan.Text, _ FileMode .OpenOrCreate, FileAccess .Write)
Case
Dim arrFileTujuan() As String = Split(txtFileAsal.Text, "." )
1 Dim fileDihapus As New FileInfo (fileHslDekompresi) fileDihapus.Delete()
Select Case comboOperasi.SelectedIndex Case
Exit Sub End Try Try
IOException pesan.pesanError(ex.Message, "Akses berkas ditolak" )
Catch ex As
fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _ FileAccess.Read)
End Select
FileAccess .Read)
1
fsInput = New FileStream (fileHslDekompresi, FileMode .Open,
_Case
fsInput = New FileStream (txtFileAsal.Text, FileMode .Open, _
FileAccess .Read)Case
Try Select Case comboOperasi.SelectedIndex
End Select End Sub Private Sub enkripsiDekripsiBerkas()
End While csObj = New CryptStream (fsOutput, fsInput.Length, bytKunci)
Dim bytBuffer(PJG_BUFFER - 1) As Byte Dim lngByteDiproses As Long = 0 Dim intJmlBlok As Integer = 0
ctr = 0
While lngByteDiproses < lngPanjangBerkas
intJmlBlok = fsInput.Read(bytBuffer, 0, PJG_BUFFER)
Select Case comboOperasi.SelectedIndex Case
csObj.tulisHasilEnkripsi(bytBuffer, intJmlBlok, PJG_BUFFER,
ctr)Case
1
csObj.tulisHasilDekripsi(bytBuffer, intJmlBlok, PJG_BUFFER,
ctr)End Select
ctr = ctr + 1 lngByteDiproses = lngByteDiproses + intJmlBlok
End While
fsInput.Close() fsOutput.Close()
End Sub Private Sub kompresiDekompresiBerkas()
Select Case comboOperasi.SelectedIndex Case
compressObj = New ZERO.Zero. Compressor (fileHslEnkripsi, _ txtFileTujuan.Text) compressObj.Kompresi()
Case
1 Dim arrFileTujuan() As String = Split(txtFileAsal.Text, "." )
fileHslDekompresi = arrFileTujuan(arrFileTujuan.Length - 1) &
".tmp"decompressObj = New ZERO.Zero. Decompressor (txtFileAsal.Text, _
fileHslDekompresi) decompressObj.dekompresi()End Select End Sub Private Sub aktifkanKomponen()
txtFileAsal.Enabled = True txtFileTujuan.Enabled = True txtKunci.Enabled = True cmdFileAsal.Enabled = True cmdFileTujuan.Enabled = True cmdProses.Enabled = True
End Sub Private Sub nonAktifkanKomponen()
txtFileAsal.Enabled = False txtFileTujuan.Enabled = False txtKunci.Enabled = False cmdFileAsal.Enabled = False cmdFileTujuan.Enabled = False cmdProses.Enabled = False
End Sub Private Sub kosongkanTextBox()
txtFileAsal.Clear() txtFileTujuan.Clear() txtKunci.Clear() lblSize1.Text = "" lblSize2.Text = "" lblRasio.Text = "" List.Items.Clear() Lama = 0 lblLama.Text = ""
End Sub Private Function cekMasukanLengkap() As Boolean
If txtFileAsal.Text.Trim() = "" Then
pesan.pesanError( "Nama berkas awal belum diisi." , "Masukan tidak lengkap." ) txtFileAsal.Focus()
Return False ElseIf txtFileTujuan.Text.Trim() = "" Then
pesan.pesanError( "Nama berkas tujuan belum diisi." , "Masukan tidak _lengkap." ) txtFileTujuan.Focus()
Return False ElseIf txtKunci.Text.Trim() = "" Then
pesan.pesanError( "Kata kunci belum diisi." , "Masukan tidak lengkap." ) txtKunci.Focus()
Return False ElseIf txtKunci.Text.Length < 5 Then
pesan.pesanError( "Kata kunci harus terdiri dari minimal karakter." ,
_ "Masukan tidak lengkap." ) txtKunci.Focus()Return False Else
Return True End If
End Function #End Region
Private Sub txtKunci_TextChanged( ByVal sender As System. Object , ByVal e As
System. EventArgs ) Handles txtKunci.TextChanged cmdProses.Enabled = True
End Sub End Class
Imports System.IO Public Class frmDiffCoding
Const PJG_BUFFER As Integer = 4096 Dim sfdTitle, ofdTitle, sfdFilter, ofdFilter As String Dim fsInput, fsOutput As FileStream Dim csObj As CryptStream Dim compressObj As DIFF.Diff. Compressor Dim decompressObj As DIFF.Diff. Decompressor Dim pesan As New Pesan () Dim fileHslKompresi As String = "" Dim fileHslDekompresi As String = "" Dim fileHslEnkripsi As String = "" Dim fileHslDekripsi As String = ""
Dim Lama As Single Private Sub comboOperasi_SelectedIndexChanged( ByVal sender As
System. Object , _
ByVal e As System. EventArgs ) Handles comboOperasi.SelectedIndexChanged Select Case comboOperasi.SelectedIndex
Case
sfdTitle = "Simpan file hasil Kompresi" ofdTitle = "Cari File yang akan diKompresi" ofdFilter = "File (*.wav)|*.wav" sfdFilter = "File hasil Kompresi (*.dc)|*.dc"
Case
1 sfdTitle = "Simpan file hasil deKompresi" ofdTitle = "Cari file yang akan dideKompresi" sfdFilter = "Semua file (*.wav)|*.wav" ofdFilter = "File hasil DeKompresi (*.dc)|*.dc"
End Select If comboOperasi.SelectedIndex >= 0 Then
aktifkanKomponen() kosongkanTextBox() cmdFileAsal.Focus()
End If End Sub Private Sub cmdProses_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdProses.Click
Dim LenKunci As Integer
LenKunci = Len(txtKunci.Text)
If LenKunci >= 5 Then Dim JamAwal As String
Dim JamAkhir As String
JamAwal = Format(Now, "hh:mm:ss tt" ) proses()
Dim fileName1 As String = txtFileAsal.Text Dim fileName2 As String = txtFileTujuan.Text Dim rasio As Single , Size1 As Single , Size2 As Single Dim fileDetails1 As System.IO. FileInfo = New
System.IO. FileInfo (fileName1)
Dim fileDetails2 As System.IO. FileInfo = New
System.IO. FileInfo (fileName2) Size1 = fileDetails1.Length.ToString Size2 = fileDetails2.Length.ToString rasio = ( Math .Abs(Size1 - Size2) / Size1) * 100 lblSize1.Text = Size1 & " Bytes" lblSize2.Text = Size2 & " Bytes" lblRasio.Text = rasio & " %"
List.Items.Add( " Ukuran File Asli Proses: " & comboOperasi.Text & "
" & _Size1)List.Items.Add( " Ukuran File Hasil Proses: " & comboOperasi.Text &
" " & _Size2) List.Items.Add( " Rasio Kompresi: " & rasio & " %" ) JamAkhir = Format(Now, "hh:mm:ss tt" ) Lama = (DateDiff( "s" , JamAkhir, JamAwal)) lblLama.Text = Format( Math .Abs(Lama), "00" ) & " Detik"Else
MsgBox( "Panjang Password Harus > 5 char" ) txtKunci.Focus()
End If End Sub Private Sub cmdFileAsal_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdFileAsal.Click openDialog.Title = ofdTitle openDialog.Filter = ofdFilter openDialog.ShowDialog()
If openDialog.FileName.Trim <> "" Then
txtFileAsal.Text = openDialog.FileName cmdFileTujuan.Focus()
End If End Sub Private Sub cmdFileTujuan_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdFileTujuan.Click saveDialog.Title = sfdTitle saveDialog.Filter = sfdFilter saveDialog.ShowDialog()
If saveDialog.FileName.Trim <> "" Then
txtFileTujuan.Text = saveDialog.FileName txtKunci.Focus()
End If End Sub Private Sub txtKunci_KeyPress( ByVal sender As Object , ByVal e As _
System.Windows.Forms. KeyPressEventArgs ) Handles txtKunci.KeyPress
If Asc(e.KeyChar) = 13 Then
proses()
End If End Sub Private Sub cmdBatal_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdBatal.Click nonAktifkanKomponen() kosongkanTextBox()
End Sub Private Sub cmdKeluar_Click( ByVal sender As System. Object , ByVal e As _
System. EventArgs ) Handles cmdKeluar.Click
Me .Close() End Sub
#Region "Fungsi dan prosedur" Private Sub proses()
If comboOperasi.SelectedIndex >= 0 And cekMasukanLengkap() Then Select Case comboOperasi.SelectedIndex
Case
enkripsiDekripsiBerkas() List.Items.Add( "Sedang melakukan kompresi..." ) kompresiDekompresiBerkas() List.Items.Add( "Proses selesai." ) pesan.pesanInfo( "Kompresi telah dilakukan." , "Informasi" )
Case
1 List.Items.Add( "Sedang melakukan dekompresi..." ) kompresiDekompresiBerkas() enkripsiDekripsiBerkas() List.Items.Add( "Proses selesai." )
pesan.pesanInfo( "Dekompresi telah dilakukan." , "Informasi" )
End Select
List.Items.Add( "Aplikasi siap." ) hapusFileTemporer() nonAktifkanKomponen()
End If End Sub Private Sub hapusFileTemporer()
Select Case comboOperasi.SelectedIndex Case
Dim arrFileTujuan() As String = Split(txtFileAsal.Text, "." )
End While
bytKunci(ctr) = Convert .ToByte(chrKunci(ctr)) ctr = ctr + 1
Dim chrKunci() As Char = txtKunci.Text.ToCharArray() Dim bytKunci(chrKunci.Length - 1) As Byte Dim ctr As Int32 = 0 While ctr < chrKunci.Length
fsOutput.SetLength(0)
Exit Sub End If
pesan.pesanError( "Ukuran berkas terlalu besar" )
Exit Sub End Try Dim lngPanjangBerkas As Long = fsInput.Length If lngPanjangBerkas > 2147483647 Then
IOException pesan.pesanError(ex.Message, "Akses berkas ditolak" )
End Select Catch ex As
1 fsOutput = New FileStream (txtFileTujuan.Text, _ FileMode .OpenOrCreate, FileAccess .Write)
Case
fileHslEnkripsi = arrFileTujuan(arrFileTujuan.Length - 2) ".tmp"
fsOutput = New FileStream (fileHslEnkripsi, FileMode ._ OpenOrCreate, FileAccess .Write)Select Case comboOperasi.SelectedIndex Case
Dim fileDihapus As New FileInfo (fileHslEnkripsi)
Exit Sub End Try Try
IOException pesan.pesanError(ex.Message, "Akses berkas ditolak" )
End Select Catch ex As
FileAccess .Read)
1
fsInput = New FileStream (fileHslDekompresi, FileMode .Open,
_Case
fsInput = New FileStream (txtFileAsal.Text, FileMode .Open, _
FileAccess .Read)Case
Try Select Case comboOperasi.SelectedIndex
End Select End Sub Private Sub enkripsiDekripsiBerkas()
1 Dim fileDihapus As New FileInfo (fileHslDekompresi) fileDihapus.Delete()
Case
fileDihapus.Delete()
csObj = New CryptStream (fsOutput, fsInput.Length, bytKunci)
Dim bytBuffer(PJG_BUFFER - 1) As Byte Dim lngByteDiproses As Long = 0 Dim intJmlBlok As Integer = 0
ctr = 0
While lngByteDiproses < lngPanjangBerkas
intJmlBlok = fsInput.Read(bytBuffer, 0, PJG_BUFFER)
Select Case comboOperasi.SelectedIndex Case
csObj.tulisHasilEnkripsi(bytBuffer, intJmlBlok, PJG_BUFFER,ctr)
Case
1 csObj.tulisHasilDekripsi(bytBuffer, intJmlBlok, PJG_BUFFER,ctr)
End Select
ctr = ctr + 1 lngByteDiproses = lngByteDiproses + intJmlBlok
End While
fsInput.Close() fsOutput.Close()
End Sub Private Sub kompresiDekompresiBerkas()
Select Case comboOperasi.SelectedIndex Case
compressObj = New DIFF.Diff. Compressor (fileHslEnkripsi, txtFileTujuan.Text) compressObj.Kompresi()
Case
1 Dim arrFileTujuan() As String = Split(txtFileAsal.Text, "." )
fileHslDekompresi = arrFileTujuan(arrFileTujuan.Length - 1) &
"._tmp"decompressObj = New DIFF.Diff. Decompressor (txtFileAsal.Text, _
fileHslDekompresi) decompressObj.dekompresi()End Select End Sub Private Sub aktifkanKomponen()
txtFileAsal.Enabled = True txtFileTujuan.Enabled = True txtKunci.Enabled = True cmdFileAsal.Enabled = True cmdFileTujuan.Enabled = True cmdProses.Enabled = True
End Sub Private Sub nonAktifkanKomponen()
txtFileAsal.Enabled = False txtFileTujuan.Enabled = False txtKunci.Enabled = False cmdFileAsal.Enabled = False cmdFileTujuan.Enabled = False cmdProses.Enabled = False
End Sub Private Sub kosongkanTextBox()
txtFileAsal.Clear() txtFileTujuan.Clear() txtKunci.Clear() lblSize1.Text = "" lblSize2.Text = "" txtKunci.Clear() lblRasio.Text = "" lama = 0 lblLama.Text = ""
End Sub Private Function cekMasukanLengkap() As Boolean
If txtFileAsal.Text.Trim() = "" Then
pesan.pesanError( "Nama berkas awal belum diisi." , _ "Masukan tidak lengkap." ) txtFileAsal.Focus()
Return False ElseIf txtFileTujuan.Text.Trim() = "" Then
pesan.pesanError( "Nama berkas tujuan belum diisi." , _ "Masukan tidak lengkap." ) txtFileTujuan.Focus()
Return False ElseIf txtKunci.Text.Trim() = "" Then
pesan.pesanError( "Kata kunci belum diisi." , _ "Masukan tidak lengkap." ) txtKunci.Focus()
Return False ElseIf txtKunci.Text.Length < 5 Then
pesan.pesanError( "Kata kunci harus terdiri dari minimal 5 karakter." ,_ "Masukan tidak lengkap." ) txtKunci.Focus()
Return False Else
Return True End If
End Function #End Region End Class
Namespace ZERO #Region " NAMESPACE : ZERO "
Namespace Zero #Region " CLASS : Compressor "
Public Class Compressor Private Overloads Function Equals( ByVal objA As Object , ByVal
objB As_
Object ) As Boolean End Function Private Overloads Function ReferenceEquals( ByVal objA As Object ,
_
ByVal objB As Object ) As Boolean End Function Public ReadOnly Property Value() As Long
Get Dim lngValue As Long If Not ( Me .fsInput Is Nothing ) Then
Try
lngValue = Me .fsInput.Position
Catch ex As Exception End Try
End If Return lngValue End Get End Property Public ReadOnly Property Length() As Long
Get Static lngLength As Long = -1 If lngLength = -1 Then
Loop Dim bytXmlLength() As Byte = _
Me .bsOutput = New
IO. BufferedStream ( Me .fsOutput, _ Zero. Internal .pjgBuffer)
Dim strXML As String =
Zero. Internal .NodesToString( Me .TreeNodes)
Dim bytXML() As Byte = _
System.Text. Encoding .Default.GetBytes(strXML) 'tulis panjang XML, dalam 10 byte.
Dim xmlLength As String = bytXML.Length.ToString Do Until xmlLength.Length = 10 : xmlLength = " " & xmlLength : _
System.Text. Encoding .Default.GetBytes(xmlLength)
Me .bsInput = New
Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim strZerro As String Dim readByte As Integer Dim JumZerro As Integer Dim KodingZerro As String Do Until readByte = 0
readByte = Me .bsInput.ReadByte
If Not readByte = 0 Then
strZerro = strZerro & "0"
End If
JumZerro = Len(strZerro) KodingZerro = "0" & JumZerro
IO. BufferedStream ( Me .fsInput, _ Zero. Internal .pjgBuffer)
IO. FileMode .Create)
Dim fileInfo As New
Private bsOutput As
IO. FileInfo ( Me .Input) lngLength = fileInfo.Length
End If Return lngLength
End Get End Property Private Input As String Private Output As String Private fsInput As
IO. FileStream
Private fsOutput As
IO. FileStream
Private bsInput As
IO. BufferedStream
IO. BufferedStream
IO. FileStream ( Me .Output,
Private TreeNodes() As Internal . ZeroTreeNode Public Sub New ( ByVal Input As String , ByVal Output As String )
Me .Input = Input Me .Output = Output
End Sub Public Sub ZerroKomp()
Me .TreeNodes = Zero. Internal .ambilZeroTreeNodes( Me .Input)
Zero. Internal .GetZeroTree( Me .TreeNodes)
Me .fsInput = New
IO. FileStream ( Me .Input, IO. FileMode .Open)
Me .fsOutput = New
If strZerro.Length > 8 Then Dim byteOut As Byte = _
CByte (binaryDecimalConverter.GetDecimal(strZerro._
Substring(0, 8)))
Me .bsOutput.WriteByte(byteOut)
strZerro = strZerro.Remove(0, 8)
End If Loop
End Sub Public Sub ZerroDekom()
Me .TreeNodes = Zero. Internal .ambilZeroTreeNodes( Me .Input)
Zero. Internal .GetZeroTree( Me .TreeNodes)
Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim readByte As Integer Dim DekodingZerro As String Dim DekodingAllZerro As String Dim ByteZerro As Integer Do Until readByte = "0"
readByte = Me .bsInput.ReadByte
If readByte = "0" Then
ByteZerro = Right(readByte, 1)
End If
DekodingZerro = ByteZerro * "0"
Loop
DekodingAllZerro = DekodingAllZerro & DekodingZerro
End Sub Public Sub Kompresi()
Me .TreeNodes = Zero. Internal .ambilZeroTreeNodes( Me .Input)
Zero. Internal .GetZeroTree( Me .TreeNodes)
Me .fsInput = New
IO. FileStream ( Me .Input, IO. FileMode .Open)
Me .fsOutput = New
IO. FileStream ( Me .Output,
IO. FileMode .Create)
Me .bsInput = New
IO. BufferedStream ( Me .fsInput, _ Zero. Internal .pjgBuffer)
Me .bsOutput = New
IO. BufferedStream ( Me .fsOutput, _ Zero. Internal .pjgBuffer)
Dim strXML As String =
Zero. Internal .NodesToString( Me .TreeNodes)
Dim bytXML() As Byte = _
System.Text. Encoding .Default.GetBytes(strXML)
Dim xmlLength As String = bytXML.Length.ToString Do Until xmlLength.Length = 10 : xmlLength = " " _
& xmlLength : Loop
Dim bytXmlLength() As Byte = _
System.Text. Encoding .Default.GetBytes(xmlLength)
Me .bsOutput.Write(bytXmlLength, 0, bytXmlLength.Length) Me .bsOutput.Position += 10 Me .bsOutput.Write(bytXML, 0, bytXML.Length) Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim strBinary As String Dim readByte As Integer Do Until readByte = -1
readByte = Me .bsInput.ReadByte
If Not readByte = -1 Then Dim strPath As String = Me .TreeNodes(readByte).Path
strBinary = strBinary & strPath
End If If strBinary.Length > 8 Then
Dim byteOut As Byte = _ CByte (binaryDecimalConverter.GetDecimal(strBinary.Substring(0, 8))) Me .bsOutput.WriteByte(byteOut)
strBinary = strBinary.Remove(0, 8)
Catch ex As Exception End Try
IO. BufferedStream
Private bsOutput As
IO. BufferedStream
Private bsInput As
IO. FileStream
Private fsOutput As
IO. FileStream
End Get End Property Private Input As String Private Output As String Private fsInput As
End If Return lngLength
IO. FileInfo ( Me .Input) lngLength = fileInfo.Length
Dim fileInfo As New
Get Static lngLength As Long = -1 If lngLength = -1 Then
End Get End Property Public ReadOnly Property Length() As Long
End If Return lngValue
lngValue = Me .fsInput.Position
End If Loop
Try
Get Dim lngValue As Long If Not ( Me .fsInput Is Nothing ) Then
ByVal objB As Object ) As Boolean End Function Public ReadOnly Property Value() As Long
End Function Private Overloads Function ReferenceEquals( ByVal objA As Object ,
objB As Object ) As Boolean
Public Class Decompressor Private Overloads Function Equals( ByVal objA As Object , ByVal
#End Region #Region " CLASS : Decompressor "
End Sub End Class
End If Me .bsInput.Close() Me .bsOutput.Close() Me .fsInput.Close() Me .fsOutput.Close()
Me .bsOutput.Position = 10 Me .bsOutput.Write(bytLeftovers, 0, bytLeftovers.Length)
System.Text. Encoding .Default.GetBytes(strBinary)
Dim bytLeftovers() As Byte = _
strBinary : Loop
If Not strBinary = "" Then Do Until strBinary.Length = 10 : strBinary = " " & _
Private Tree As Internal . ZeroTreeNode
Private currentNode As Internal . ZeroTreeNode Public Sub New ( ByVal Input As String , ByVal Output As String )
Me .Input = Input Me .Output = Output
End Sub Public Sub dekompresi()
Me .fsInput = New
IO. FileStream ( Me .Input, IO. FileMode .Open)
Me .fsOutput = New
IO. FileStream ( Me .Output,
IO. FileMode .Create)
Me .bsInput = New
IO. BufferedStream ( Me .fsInput, _ Zero. Internal .pjgBuffer)
Me .bsOutput = New
IO. BufferedStream ( Me .fsOutput, _ Zero. Internal .pjgBuffer)
Dim bytTreeNodesAsStringLength(9) As Byte Me .bsInput.Read(bytTreeNodesAsStringLength, 0, _
bytTreeNodesAsStringLength.Length)
Dim treeNodesAsStringLength As Integer = Integer .Parse(System.Text. Encoding .Default.GetString _
(bytTreeNodesAsStringLength).Replace( " " , "" ))
Dim bytLeftOvers(9) As Byte Me .bsInput.Read(bytLeftOvers, 0, bytLeftOvers.Length) Dim strLeftovers As String =
System.Text. Encoding .Default.GetString(bytLeftOvers).Replace( " " , "" )
Dim bytXml(treeNodesAsStringLength - 1) As Byte Me .bsInput.Read(bytXml, 0, treeNodesAsStringLength) Dim strXML As String =
System.Text. Encoding .Default.GetString(bytXml)
Dim TreeNodes() As Internal . ZeroTreeNode =
Zero. Internal .StringToNodes(strXML)
Me .Tree = Zero. Internal .GetZeroTree(TreeNodes) Me .currentNode = Me .Tree Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim readByte As Integer Do Until (readByte = -1)
readByte = Me .bsInput.ReadByte
If Not readByte = -1 Then Dim strBinary As String = _
binaryDecimalConverter.GetBinary(readByte)
Me .dekripsiBits(strBinary) End If
Loop Me .dekripsiBits(strLeftovers) Me .bsInput.Close() Me .bsOutput.Close() Me .fsInput.Close() Me .fsOutput.Close()
End Sub Private Sub dekripsiBits( ByVal Bits As String )
Dim x As Integer For x = 0 To (Bits.Length - 1)
Select Case Bits.Chars(x).ToString Case "0"
Me .currentNode = Me .currentNode.Left Case "1"
Me .currentNode = Me .currentNode.Right End Select If Not ( Me .currentNode.Character = -1) Then
Me .bsOutput.WriteByte( CByte ( Me .currentNode.Character)) Me .currentNode = Me .Tree
End If Next x
End Sub End Class
#End Region #Region " CLASS : Internal "
Friend Class Internal Public Const pjgBuffer As Integer = (1024) * 4
#Region " FUNCTION : GetZeroTreeNodes " Public Shared Function ambilZeroTreeNodes( ByVal File As String )
As _
ZeroTreeNode ()
Dim ZeroTreeNodes(255) As ZeroTreeNode Dim x As Integer For x = 0 To 255
ZeroTreeNodes(x) = New ZeroTreeNode ZeroTreeNodes(x).Character = x
Next x Dim fileStream As New
IO. FileStream (File, IO. FileMode .Open)
Dim readByte As Integer Do Until readByte = -1
readByte = fileStream.ReadByte
If Not readByte = -1 Then
ZeroTreeNodes(readByte).Weight += 1
End If Loop
fileStream.Close()
Return ZeroTreeNodes End Function
#End Region #Region " FUNCTION : GetZeroTree "
Public Shared Function GetZeroTree( ByVal TreeNodes() As _
ZeroTreeNode ) As ZeroTreeNode
Dim tempTreeNodes() As ZeroTreeNode = CType (TreeNodes.Clone,
_ ZeroTreeNode ())
Do Until tempTreeNodes.Length = 1
Array .Sort(tempTreeNodes, New ZeroTreeNodeComparer )
Dim node1 As ZeroTreeNode =
tempTreeNodes(tempTreeNodes._ Length - 1)
Dim node2 As ZeroTreeNode =
tempTreeNodes(tempTreeNodes._ Length - 2)
Dim newNode As New ZeroTreeNode
newNode.Character = -1 newNode.Weight = node1.Weight + node2.Weight newNode.Left = node1 newNode.Right = node2 node1.Parent = newNode node2.Parent = newNode
ReDim Preserve tempTreeNodes(tempTreeNodes.Length - 3) ReDim Preserve tempTreeNodes(tempTreeNodes.Length)
tempTreeNodes(tempTreeNodes.Length - 1) = newNode
Loop Return tempTreeNodes(0)
End Function #End Region #Region " FUNCTION : NodesToString/StringToNodes "
Public Shared Function NodesToString( ByVal TreeNodes() As _
ZeroTreeNode ) As String
Dim characters(255) As String Dim weights(255) As String Dim x As Integer For x = 0 To 255
characters(x) = CStr (TreeNodes(x).Character) weights(x) = CStr (TreeNodes(x).Weight)
Next x Return String .Join( "#" , characters) & "%" & String .Join( "#" ,
weights)
End Function Public Shared Function StringToNodes( ByVal Xml As String ) As _
ZeroTreeNode ()
Dim characters() As String = _
Xml.Split( "%" .ToCharArray)(0).Split( "#" .ToCharArray)
Dim weights() As String = _
Xml.Split( "%" .ToCharArray)(1).Split( "#" .ToCharArray)
Dim TreeNodes(255) As ZeroTreeNode Dim x As Integer For x = 0 To 255
TreeNodes(x) = New ZeroTreeNode TreeNodes(x).Character = CInt (characters(x)) TreeNodes(x).Weight = CLng (weights(x))
Next x Return TreeNodes
End Function #End Region #Region " CLASS : ZeroTreeNode "
Public Class ZeroTreeNode Public Sub New () End Sub Private Shadows Function Equals() As Boolean
Return False End Function Private Shadows Function ReferenceEquals() As Boolean
Return False End Function Public Character As Integer = -1 Public Weight As Long = 0
<System.Xml.Serialization. XmlIgnore ()> Public Parent As ZeroTreeNode <System.Xml.Serialization. XmlIgnore ()> Public Left As ZeroTreeNode <System.Xml.Serialization. XmlIgnore ()> Public Right As _
ZeroTreeNode <System.Xml.Serialization. XmlIgnore ()> Public ReadOnly Property Path() As String 'the binary path to the node.
Get Static strPath As String If strPath Is Nothing Then
If Not ( Me .Parent Is Nothing ) Then If ( Me .Parent.Left Is Me ) Then strPath = "0" If ( Me .Parent.Right Is Me ) Then strPath = "1"
strPath = Parent.Path & strPath
End If End If Return strPath
End Get End Property
End Class #End Region #Region " CLASS : ZeroTreeNodeComparer "
Public Class ZeroTreeNodeComparer Implements
IComparer
Public Sub New () End Sub Public Function Compare( ByVal x As Object , ByVal y As Object ) As Integer Implements System.Collections.
IComparer .Compare
Dim returnVal As Integer = -1 Dim a As Double = CType (x, ZeroTreeNode ).Weight Dim b As Double = CType (y, ZeroTreeNode ).Weight If a > b Then
returnVal = 1
ElseIf a < b Then
returnVal = -1
ElseIf a = b Then
returnVal = 0
End If
returnVal *= -1
Return returnVal End Function
End Class #End Region #Region " CLASS : BinaryDecimalConverter "
Public Class BinaryDecimalConverter Private hashGetDecimal As Hashtable Private hashGetBinary As Hashtable Public Function GetDecimal( ByVal strBinary As String ) As
Integer If Me .hashGetDecimal Is Nothing Then
Me .hashGetDecimal = New Hashtable Dim x As Integer For x = 0 To 255
Me .hashGetDecimal( Me .GetBinaryInternal(x)) = x Next x
End If Return CInt ( Me .hashGetDecimal(strBinary))
End Function Public Function GetBinary( ByVal intDecimal As Integer ) As
String If Me .hashGetBinary Is Nothing Then
Me .hashGetBinary = New Hashtable Dim x As Integer For x = 0 To 255
Me .hashGetBinary(x) = Me .GetBinaryInternal(x) Next x
End If Return CStr ( Me .hashGetBinary(intDecimal)) End Function Private Function GetBinaryInternal( ByVal intDecimal AS Integer )
As String Dim Y As Integer Dim strBinary As String While (intDecimal \ 2) > 0
Y = intDecimal \ 2
If intDecimal > 1 Then
strBinary = Val( CStr (intDecimal - (Y * 2))) & _
strBinaryEnd If
intDecimal = Y
End While
strBinary = intDecimal & strBinary
Do Until strBinary.Length = 8
strBinary = "0" & strBinary
Loop Return strBinary
End Function Private Function GetDecimalInternal( ByVal strBinary As String )
As Integer Dim sngNumber As Integer Dim x As Integer Dim Tmp As Integer Dim Output As Integer
sngNumber = CInt (strBinary)
For x = 0 To Len( CStr (sngNumber)) - 1
Tmp = CInt (Right( CStr (sngNumber), 1))
If Tmp = 1 Then
Tmp = CInt (Tmp * Math .Pow(2, x))
End If
Output = Output + Tmp Tmp = 1
If Len( CStr (sngNumber)) > 1 Then
sngNumber = CInt (Left( CStr (sngNumber), _
Len( CStr (sngNumber)) - 1))
Else
sngNumber = 0
End If Next Return Output
End Function Private Function GetPowerInternal( ByRef Value As Integer , _
ByRef Power As Integer ) As Integer Dim result As Integer If Power > 1 Then
Dim x As Integer For x = 2 To Power
Value = Value * 2
Next
result = Value
Else If Power = 0 Then result = 1 If Power = 1 Then result = Value
End If Return result
End Function End Class
#End Region End Class
IO. FileInfo ( Me .Input) lngLength = fileInfo.Length
Me .TreeNodes = Diff. Internal .ambilDIFFTreeNodes( Me .Input)
End Sub Public Sub KompresiDiff()
Me .Input = Input Me .Output = Output
Private TreeNodes() As Internal . DIFFTreeNode Public Sub New ( ByVal Input As String , ByVal Output As String )
IO. BufferedStream
Private bsOutput As
IO. BufferedStream
Private bsInput As
IO. FileStream
Private fsOutput As
IO. FileStream
End Get End Property Private Input As String Private Output As String Private fsInput As
End If Return lngLength
Dim fileInfo As New
#End Region End Namespace
Get Static lngLength As Long = -1 If lngLength = -1 Then
End Get End Property Public ReadOnly Property Length() As Long
End If Return lngValue
Catch ex As Exception End Try
lngValue = Me .fsInput.Position
Try
Get Dim lngValue As Long If Not ( Me .fsInput Is Nothing ) Then
ByVal objB As Object ) As Boolean End Function Public ReadOnly Property Value() As Long
As Object ) As Boolean End Function Private Overloads Function ReferenceEquals( ByVal objA As Object , _
_
Public Class Compressor Private Overloads Function Equals( ByVal objA As Object , ByVal objB
Namespace Diff #Region " CLASS : Compressor "
#End Region End Namespace 6. ModDifference Namespace DIFF #Region " NAMESPACE : DIFF "
Diff. Internal .GetDIFFTree( Me .TreeNodes)
Me .fsInput = New
IO. FileStream ( Me .Input, IO. FileMode .Open)
Me .fsOutput = New
IO. FileStream ( Me .Output, IO. FileMode .Create)
Me .bsInput = New
IO. BufferedStream ( Me .fsInput, _ Diff. Internal .pjgBuffer)
Me .bsOutput = New
IO. BufferedStream ( Me .fsOutput, _ Diff. Internal .pjgBuffer)
Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim readByte As Integer Dim readBit1 As Integer Dim readBit2 As Integer Dim DiffReadBit As Integer Dim IntPosisi As Integer Dim KodingByte As String Dim KodingAllByte As String Do Until readByte = -1
IntPosisi = IntPosisi + 1 readByte = Me .bsInput.ReadByte readBit1 = Left(readByte, 1) readBit2 = Mid(readByte, IntPosisi, 1) DiffReadBit = readBit2 - readBit1 KodingByte = readBit1 & DiffReadBit
Loop
KodingAllByte = KodingAllByte & KodingByte
End Sub Public Sub DeKompresiDiff()
Me .TreeNodes = Diff. Internal .ambilDIFFTreeNodes( Me .Input)
Diff. Internal .GetDIFFTree( Me .TreeNodes)
Me .fsInput = New
IO. FileStream ( Me .Input, IO. FileMode .Open)
Me .fsOutput = New
IO. FileStream ( Me .Output, IO. FileMode .Create)
Me .bsInput = New
IO. BufferedStream ( Me .fsInput, _ Diff. Internal .pjgBuffer)
Me .bsOutput = New
IO. BufferedStream ( Me .fsOutput, _ Diff. Internal .pjgBuffer)
Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim readByte As Integer Dim readBit1 As Integer Dim readBit2 As Integer Dim DiffReadBit As Integer Dim IntPosisi As Integer Dim DeKodingByte As String Dim DeKodingAllByte As String Do Until readByte = -1
IntPosisi = IntPosisi + 1 readByte = Me .bsInput.ReadByte readBit1 = Left(readByte, 1) readBit2 = Mid(readByte, IntPosisi, 1) DiffReadBit = readBit2 + readBit1 DeKodingByte = DiffReadBit
Loop
DeKodingAllByte = DeKodingAllByte & DeKodingByte
End Sub Public Sub Kompresi()
Me .TreeNodes = Diff. Internal .ambilDIFFTreeNodes( Me .Input)
Diff. Internal .GetDIFFTree( Me .TreeNodes)
Me .fsInput = New
IO. FileStream ( Me .Input, IO. FileMode .Open)
Me .fsOutput = New
IO. FileStream ( Me .Output, IO. FileMode .Create) Me .bsInput = New
IO. BufferedStream ( Me .fsInput, _ Diff. Internal .pjgBuffer)
Me .bsOutput = New
IO. BufferedStream ( Me .fsOutput, _ Diff. Internal .pjgBuffer)
Dim strXML As String =
Diff. Internal .NodesToString( Me .TreeNodes)
Dim bytXML() As Byte =
System.Text. Encoding .Default.GetBytes(strXML)
Dim xmlLength As String = bytXML.Length.ToString Do Until xmlLength.Length = 10 : xmlLength = " " & xmlLength :
Loop Dim bytXmlLength() As Byte = _
System.Text. Encoding .Default.GetBytes(xmlLength)
Me .bsOutput.Write(bytXmlLength, 0, bytXmlLength.Length) Me .bsOutput.Position += 10 Me .bsOutput.Write(bytXML, 0, bytXML.Length) Dim binaryDecimalConverter As New
Internal . BinaryDecimalConverter
Dim strBinary As String Dim readByte As Integer Do Until readByte = -1
readByte = Me .bsInput.ReadByte