Compress streams : 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 Tutorial
VB.Net by API
VB.Net » File Directory » StreamScreenshots 
Compress streams
 

Imports System.IO
Imports System.IO.Compression
Module Module1
    Sub Main()
        Dim dirpath As String = "c:\users\public\reports"
        Dim di As DirectoryInfo = New DirectoryInfo(dirpath)
        For Each fi As FileInfo In di.GetFiles()
            Compress(fi)
        Next
    End Sub
    Private Sub Compress(ByVal fi As FileInfo)
        Using inFile As FileStream = fi.OpenRead()
            If (File.GetAttributes(fi.FullNameAnd FileAttributes.Hidden_
                <> FileAttributes.Hidden And fi.Extension <> ".gz" Then
                Using outFile As FileStream = File.Create(fi.FullName + ".gz")
                    Using Compress As GZipStream = New GZipStream(outFile, CompressionMode.Compress)
                        Dim buffer As Byte() = New Byte(4096) {}
                        Dim numRead As Integer
                        numRead = inFile.Read(buffer, 0, buffer.Length)
                        Do While numRead <> 0
                            Compress.Write(buffer, 0, numRead)
                            numRead = inFile.Read(buffer, 0, buffer.Length)
                        Loop
                    End Using
                End Using
            End If
        End Using
    End Sub
End Module

   
  
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.GZipStream Class
8.Decompress streams.
9.Stream.CanWrite Property tells whether the current stream supports writing.
w__w__w__.__j__av___a_2___s___.co___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.