1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| Public Sub compression(ByVal fi As FileInfo)
Using inFile As FileStream = fi.OpenRead()
If (File.GetAttributes(fi.FullName) And FileAttributes.Hidden) _
<> FileAttributes.Hidden And fi.Extension <> ".gz" Then
' Creation des fichiers compressés.
Using outFile As FileStream = File.Create(fi.FullName + ".gz")
Using Compress As GZipStream = New GZipStream(outFile, CompressionMode.Compress)
'Copie dans le setream.
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 |
Partager