GZipStream Class : Stream « File Directory « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » File Directory » Stream 




GZipStream Class
 

Imports System
Imports System.IO
Imports System.IO.Compression

Public Class GZipTest
   Public Shared Function ReadAllBytesFromStream(stream As Stream, buffer() As ByteAs Integer
      Dim offset As Integer = 0
      Dim totalCount As Integer = 0
      While True
         Dim bytesRead As Integer = stream.Read(buffer, offset, 100)
         If bytesRead = Then
            Exit While
         End If
         offset += bytesRead
         totalCount += bytesRead
      End While
      Return totalCount
   End Function
    Public Shared Sub Main(ByVal args() As String)
       Dim infile As FileStream
       infile = New FileStream("c:\\", FileMode.Open, FileAccess.Read, FileShare.Read)
       Dim buffer(infile.Length - 1As Byte
       Dim count As Integer = infile.Read(buffer, 0, buffer.Length)
       infile.Close()
       Dim ms As New MemoryStream()
       Dim compressedzipStream As New GZipStream(ms, CompressionMode.Compress, True)
       compressedzipStream.Write(buffer, 0, buffer.Length)
       compressedzipStream.Close()
       ms.Position = 0
       Dim zipStream As New GZipStream(ms, CompressionMode.Decompress)
       Dim decompressedBuffer(buffer.Length + 100As Byte
       Dim totalCount As Integer = GZipTest.ReadAllBytesFromStream(zipStream, decompressedBuffer)
       zipStream.Close()
    End Sub
End Class 

   
  














Related examples in the same category
1.Stream.CanRead Property tells whether the current stream supports reading.
2.Stream.CanWrite Property tells whether the current stream supports writing.
3.Stream.CopyTo Method reads all the bytes from the current stream and writes them to the destination stream.
4.Reads a maximum of count characters from the current stream into buffer
5.Stream.Read Method reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
6.Open a stream as ASCII
7.Compress streams
8.Decompress streams.
9.Stream.CanWrite Property tells whether the current stream supports writing.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.