VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Use GZIP Stream In .Net

by Gehan Fernando. (13 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Fri 8th June 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Use GZIP Stream In .Net

API Declarations


.Compression
.Compression.GZipStream


Rate Use GZIP Stream In .Net




        Dim sourcefile As FileStream = File.OpenRead("c:\Friends.jpg")
        Dim desfile As FileStream = File.Create("d:\Friends.gz")

        Dim compstream As New GZipStream(desfile, CompressionMode.Compress)

        Dim theByte As Integer = sourcefile.ReadByte()

        While theByte <> -1
            compstream.WriteByte(CType(theByte, Byte))
            theByte = sourcefile.ReadByte()
        End While

        sourcefile.Dispose()
        desfile.Dispose()

    End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim sourcefile As FileStream = File.OpenRead("d:\Friends.gz")
        Dim desfile As FileStream = File.Create("c:\Friends.jpg")

        Dim compstream As New GZipStream(sourcefile, CompressionMode.Decompress)

        Dim theByte As Integer = compstream.ReadByte()

        While theByte <> -1
            desfile.WriteByte(CType(theByte, Byte))
            theByte = compstream.ReadByte()
        End While

        sourcefile.Dispose()
        desfile.Dispose()

    End Sub

Download this snippet    Add to My Saved Code

Use GZIP Stream In .Net Comments

No comments have been posted about Use GZIP Stream In .Net. Why not be the first to post a comment about Use GZIP Stream In .Net.

Post your comment

Subject:
Message:
0/1000 characters