Adhitama, G. 2009. Perbandingan Algoritma Huffman dengan Algoritma Shannon- Fano.Skripsi.Institut Teknologi Bandung.
Binanto, I. 2010. Multimedia Digital, Dasar Teori + Pengembangan, ANDI: Yogyakarta.
Dangarwala, Kruti Mrs. & Shah, Jigar Mr. 2010. Implementation & Comparisonof Companding & Silence Audio Compression Techniques. International Journal of Computer Science Department of Computer Engineering, Sri S’ad Vidya Mandal Institute of Technology Bharuch 7 (2): H79 - H84.
Gozali, F. & Mervyn. 2008. Analisis Perbandingan Kompresi Data Dengan Teknik Arithmetic Coding Dan Run Length Encoding. Jurnal JETri.4(1):37-52.
Gunawan, I. & Gunadi, K. 2010. Pembuatan Perangkat Lunak Wave Manipulator Untuk Memanipulasi File WAV. Jurnal informatika. 6(1): 41 – 50.
Hasibuan, N.S, 2008. Studi Perbandingan Algoritma Huffman dan Shannon Fano
Dalam Pemampatan File Teks. Skripsi .Universitas Sumatera Utara.
Kadhim,I.J.2012. A New Audio Steganography SystemBased on Auto-Key Generator. Al-Khwarizmi Engineering Journal,Department ofElectric Power Engineering Techniques/College of Electric & Electronic Techniques 8(1):27-36
Kodituwakku, S.R. & Amarasinghe, U. S., 2010. Comparison Of Lossless Data Compression Algorithms for text data. Indian Journal of Computer Science and Engineering 1( 4): 416-425.
Nadarajan, K. & Zukarnain, Z.A. 2008. Analysis of String Matching Compression Algorithms. Journal of Computer Science. Faculty of Computer Science and Information Technology 4 (3): 205-210.
Putra, D.2010. Pengolahan Citra Digital.ANDI:Yogyakarta.
Salomon, David & Giovanni. 2010. Handbook of Data Compression. Fifth.
Santi, R. 2010. Perancangan Perangkat Lunak Kompresi File Citra dengan Menggunakan Algoritma Run Length Encoding (RLE).Skripsi.Universitas Sumatera Utara.
Wibowo,A,2012. Kompresi Data Menggunakan Metode Huffman. Skripsi.Politeknik Negri Batam.
Wiryadinata, R. 2007. Data Compression Coding Using Static and Dynamic Method of Shannon-Fano Algorithm. Jurnal ilmiah Universitas Gadjah Mada, Yogyakarta.5(2):129-139.
LISTING PROGRAM
1. Menu
Public Class frmMenu
Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click frmHelp.Show()
End Sub
Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click End
End Sub
Private Sub ZeroCompressionToolStripMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _
ZeroCompressionToolStripMenuItem.Click frmZeroKom.Show()
End Sub
Private Sub DifferenceCodingToolStripMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _
DifferenceCodingToolStripMenuItem.Click KomDekom.Show()
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click frmAbt.Show()
End Sub End Class
2.ZeroKompresi Imports System.IO
Public Class frmZeroKom
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
System.Object, _
ByVal e As System.EventArgs) Handles comboOperasi.SelectedIndexChanged Select Case comboOperasi.SelectedIndex
Case 0
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()
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 0
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 0
Dim fileDihapus As New FileInfo(fileHslEnkripsi) fileDihapus.Delete()
Case 1
Dim fileDihapus As New FileInfo(fileHslDekompresi) fileDihapus.Delete()
End Select
End Sub
Private Sub enkripsiDekripsiBerkas() Try
Select Case comboOperasi.SelectedIndex Case 0
fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _
FileAccess.Read)
Case 1
fsInput = New FileStream(fileHslDekompresi, FileMode.Open, _
FileAccess.Read)
End Select
fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _
FileAccess.Read)
Catch ex As IOException
pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub
End Try
Try
Select Case comboOperasi.SelectedIndex Case 0
Dim arrFileTujuan() As String = Split(txtFileAsal.Text,".") fileHslEnkripsi = arrFileTujuan(arrFileTujuan.Length - 2) & ".tmp" fsOutput = New
FileStream(fileHslEnkripsi,FileMode.OpenOrCreate_,FileAccess.Write)
Case 1
fsOutput = New FileStream(txtFileTujuan.Text, _
FileMode.OpenOrCreate, FileAccess.Write)
End Select
fsOutput = New FileStream(txtFileTujuan.Text,
FileMode.OpenOrCreate,_
FileAccess.Write)
Catch ex As IOException
pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub
End Try
Dim lngPanjangBerkas As Long = fsInput.Length If lngPanjangBerkas > 2147483647 Then
pesan.pesanError("Ukuran maksimal berkas yang dapat diproses adalah
_sebesar 2.147.483.647 bit.", _"Ukuran berkas terlalu besar")
Exit Sub
End If
fsOutput.SetLength(0)
Dim chrKunci() As Char = txtKunci.Text.ToCharArray() Dim bytKunci(chrKunci.Length - 1) As Byte
Dim ctr As Int32 = 0
While ctr < chrKunci.Length
bytKunci(ctr) = Convert.ToByte(chrKunci(ctr)) ctr = ctr + 1
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 0
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 0
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
3. Difference Coding 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 0
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
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 0
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 0
Dim fileDihapus As New FileInfo(fileHslEnkripsi) fileDihapus.Delete()
Case 1
Dim fileDihapus As New FileInfo(fileHslDekompresi) fileDihapus.Delete()
End Select
End Sub
Private Sub enkripsiDekripsiBerkas() Try
Select Case comboOperasi.SelectedIndex Case 0
fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _
FileAccess.Read)
Case 1
fsInput = New FileStream(fileHslDekompresi, FileMode.Open, _
FileAccess.Read)
End Select
Catch ex As IOException
pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub
End Try
Try
Select Case comboOperasi.SelectedIndex Case 0
Dim arrFileTujuan() As String = Split(txtFileAsal.Text,".") fileHslEnkripsi = arrFileTujuan(arrFileTujuan.Length - 2) ".tmp" fsOutput = New FileStream(fileHslEnkripsi, FileMode._
OpenOrCreate, FileAccess.Write) Case 1
fsOutput = New FileStream(txtFileTujuan.Text, _
FileMode.OpenOrCreate, FileAccess.Write)
End Select
Catch ex As IOException
pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub
End Try
Dim lngPanjangBerkas As Long = fsInput.Length If lngPanjangBerkas > 2147483647 Then
pesan.pesanError("Ukuran berkas terlalu besar") Exit Sub
End If
fsOutput.SetLength(0)
Dim chrKunci() As Char = txtKunci.Text.ToCharArray() Dim bytKunci(chrKunci.Length - 1) As Byte
Dim ctr As Int32 = 0
While ctr < chrKunci.Length
bytKunci(ctr) = Convert.ToByte(chrKunci(ctr)) ctr = ctr + 1
End While
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 0 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 0
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
Dim fileInfo As New 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
Private bsOutput As IO.BufferedStream
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 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) 'tulis panjang XML, dalam 10 byte.
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) 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 If strZerro.Length > 8 Then
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
CByte(binaryDecimalConverter.GetDecimal(strBinary.Substring(0, 8))) Me.bsOutput.WriteByte(byteOut)
strBinary = strBinary.Remove(0, 8) End If
Loop
If Not strBinary = "" Then
Do Until strBinary.Length = 10 : strBinary = " " & _ strBinary : Loop
Dim bytLeftovers() As Byte = _
System.Text.Encoding.Default.GetBytes(strBinary) Me.bsOutput.Position = 10 Me.bsOutput.Write(bytLeftovers, 0, bytLeftovers.Length) End If Me.bsInput.Close() Me.bsOutput.Close() Me.fsInput.Close() Me.fsOutput.Close() End Sub End Class #End Region
#Region " CLASS : Decompressor " Public Class Decompressor
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
Dim fileInfo As New 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
Private bsOutput As IO.BufferedStream
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