Is there a problem with IO.Compression?

I just started compressing a file in VB.Net using the following code. Since I am targeting Fx 2.0, I cannot use the method Stream.CopyTo.

My code, however, gives very poor results compared to the gzip compression profile Normalin 7-zip. For example, my code was compressing the archive of the appearance of 630 MB to 740 MB, and 7-zip makes it 490 MB.

Here is the code. Is there a blatant mistake (or a lot?)

Using Input As New IO.FileStream(SourceFile, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
    Using outFile As IO.FileStream = IO.File.Create(DestFile)
        Using Compress As IO.Compression.GZipStream = New IO.Compression.GZipStream(outFile, IO.Compression.CompressionMode.Compress)
            'TODO: Figure out the right buffer size.'
            Dim Buffer(524228) As Byte
            Dim ReadBytes As Integer = 0

            While True
                ReadBytes = Input.Read(Buffer, 0, Buffer.Length)
                If ReadBytes <= 0 Then Exit While
                Compress.Write(Buffer, 0, ReadBytes)
            End While
        End Using
    End Using
End Using

I tried with several buffer sizes, but I get a similar compression time and exactly the same compression ratio.

+3
source share
3 answers

EDIT or actually rewrite: It seems that BCL coders have decided to call it .

System.dll 2.0 , ASCII, , . ( GZip/Deflate ). , , , , Microsoft , !

, .

+5

IO. . XPS XML Paper Specificatin. , .

+1

, . () , IO.Compression.GZipStream.

Ionic.Zip, .

, , , Ionic.Zip 25% , 3-4 ( ), 3 , 1,6 0,5 .

Since the GZipStream standard is standard, although the built-in IO.Compression.GZipStream in .NET was much less compressed in terms of space, it was decompressed much faster.

Therefore, I use both Ionic.Zip Librarys ZLib.GZipStream "for Compressing Files and IO.Compression. GZipStream " until Decompressing files is much faster in production.

0
source

Source: https://habr.com/ru/post/1791609/


All Articles