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 33 34 35 36 37 38 39 40 41 42
   |  
 Public Shared Function compresFile(ByVal source As String, ByVal destination As String) As Boolean
            Try
 
                Dim flstream As New FileStream(source, FileMode.Open)
                Dim outputFile As FileStream = File.Create(destination)
                Dim bufer(CInt(flstream.Length - 1)) As Byte
                flstream.Read(bufer, 0, CInt(flstream.Length))
                flstream.Close()
                Dim gzip As New GZipStream(outputFile, CompressionMode.Compress)
                gzip.Write(bufer, 0, bufer.Length)
                gzip.Close()
                Return True
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
 
 
        End Function
 
        Public Shared Function downloadFile(ByVal sourceFile As String, ByVal destinationFile As String) As Boolean
            Dim localStream As Stream
            Dim response As WebResponse
            Dim textWriter As StreamWriter
            'Dim fileinf As New FileInfo(destinationFile)
            'textWriter = fileinf.CreateText()
 
            Dim Request As WebRequest = WebRequest.Create(sourceFile)
 
            If Not Request Is Nothing Then
                response = Request.GetResponse()
                If Not response Is Nothing Then
                    localStream = response.GetResponseStream()
                    textWriter = New StreamWriter(destinationFile)
                    textWriter.AutoFlush = True
                    Dim strReader As New StreamReader(localStream)
                    Dim Query As String = strReader.ReadToEnd()
                    textWriter.Write(Query)
                End If
            End If
            textWriter.Close()
        End Function | 
Partager