This code uncompresses 1/4 of the gzipped file. & I took it directely from the help file sample function codes.
Any idea why is it doing this or how to fix it? gz file is attached below & it is not damaged.
Edit: I read some stuff hire & there & found this: tutorial that says that MSDN doesn’t set the size of the array and uses a default size of 4086 bytes. But I have no clue how to implement it into my code.
In this gz file there are only around 50 lines but there are files with over 1000 lines. So I tested & indeed this seems to be the problem, because if I increase the buffer(4096) more lines are extracted.
PHP Code:Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.IO.Compression
Public Class CompressionSnippet
Private Sub CompressionSnippet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Hide()
UncompressFile("1.gz") ' Name of the compressed file
Me.Close()
End Sub
Public Shared Sub UncompressFile(ByVal path As String)
Dim sourceFile As FileStream = File.OpenRead(path)
Dim destinationFile As FileStream = File.Create(path + ".txt") ' Outputs test.gz.txt
' Because the uncompressed size of the file is unknown,
' we are imports an arbitrary buffer size.
Dim buffer(4096) As Byte
Dim n As Integer
Using input As New GZipStream(sourceFile, _
CompressionMode.Decompress, False)
n = input.Read(buffer, 0, buffer.Length)
destinationFile.Write(buffer, 0, n)
End Using
' Close the files.
sourceFile.Close()
destinationFile.Close()
End Sub
End Class





Reply With Quote