vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
SEPA-Dateien erstellen inkl. IBAN-, BLZ-/Kontonummernprüfung  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Fortgeschrittene
Re: GZIP in Steam oder als String 
Autor: rub
Datum: 24.07.07 16:06

Hab was gefunden
    Public Function Compress(ByVal data() As Byte) As Byte()
        Try
            '---the ms is used for storing the compressed data---
            Dim ms As New MemoryStream()
            Dim zipStream As Stream = Nothing
 
            zipStream = New System.IO.Compression.GZipStream(ms, _
              System.IO.Compression.CompressionMode.Compress, True)
            '---or---
            'zipStream = New DeflateStream(ms, CompressionMode.Compress, True)
 
            '---compressing using the info stored in data---
            zipStream.Write(data, 0, data.Length)
            zipStream.Close()
 
            ms.Position = 0
            '---used to store the compressed data (byte array)---
            Dim compressed_data(ms.Length - 1) As Byte
 
            '---read the content of the memory stream into 
            '   the byte array---
            ms.Read(compressed_data, 0, ms.Length)
 
            Return compressed_data
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
 
    Public Function Decompress(ByVal data() As Byte) As Byte()
        Try
            '---copy the data (compressed) into ms---
            Dim ms As New MemoryStream(data)
            Dim zipStream As Stream = Nothing
 
            '---decompressing using data stored in ms---
            zipStream = New System.IO.Compression.GZipStream(ms, _
              System.IO.Compression.CompressionMode.Decompress)
            '---or---
            'zipStream = New DeflateStream(ms, CompressionMode.Decompress, True)
 
            '---used to store the decompressed data---
            Dim dc_data() As Byte
 
            '---the decompressed data is stored in zipStream; 
            ' extract them out into a byte array---
            dc_data = ExtractBytesFromStream(zipStream, data.Length)
 
            Return dc_data
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
 
    Public Function ExtractBytesFromStream( _
       ByVal stream As Stream, _
       ByVal dataBlock As Integer) _
       As Byte()
 
        '---extract the bytes from a stream object---
        Dim data() As Byte
        Dim totalBytesRead As Integer = 0
        Try
            While True
                '---progressively increase the size 
                ' of the data byte array---
                ReDim Preserve data(totalBytesRead + dataBlock)
                Dim bytesRead As Integer = _
                   stream.Read(data, totalBytesRead, dataBlock)
                If bytesRead = 0 Then
                    Exit While
                End If
                totalBytesRead += bytesRead
            End While
            '---make sure the byte array contains exactly the number 
            ' of bytes extracted---
            ReDim Preserve data(totalBytesRead - 1)
            Return data
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
GZIP in Steam oder als String1.245rub24.07.07 15:38
Re: GZIP in Steam oder als String886rub24.07.07 16:06

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel