IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Discussion :

Webservice et decompression Gzip VB.NET Framework 2.0


Sujet :

Services Web

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 23
    Par défaut Webservice et decompression Gzip VB.NET Framework 2.0
    Bonjour a tout le monde.

    J'ai un webservice en php qui compresse des fichiers dans une archive gzip.

    Je les télécharge mais quand je veux les décompresser en VB.NET j'ai l'erreur suivante:
    BAD MAGIC NUMBER

    voici les code que j'utilise :

    compression en php

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    $fl = fopen($path.$file,"rb");
    $content = fread($fl, filesize($path.$file));
    $gzData = gzcompress($content,9);
    $fp = fopen($path.$file.".gz","wb");
    fwrite($fp,$gzData);
    fclose($fp);
    return $file.".gz";
    le code en VB pour decompresser et compresser

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    je ne vois pas trop ou il y a une erreur. Pouvez vous m'aider merci.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 23
    Par défaut
    Personne ne peux me donner des pistes de réponse ou une autre méthode pour télécharger des fichier compresser depuis php vers mon poste windows pour une application en .NET??

  3. #3
    Membre éprouvé
    Inscrit en
    Avril 2007
    Messages
    124
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 124
    Par défaut
    j'utilise ca pour compresser et decompresser des fichiers :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
     
     Public Class ZipUtil
            Public Function CompressFile(ByVal sourceFile As String, ByVal destinationFile As String) As String
                ' make sure the source file is there
                If File.Exists(sourceFile) = False Then
                    Throw New FileNotFoundException
                End If
                ' Create the streams and byte arrays needed
                Dim buffer As Byte() = Nothing
                Dim sourceStream As FileStream = Nothing
                Dim destinationStream As FileStream = Nothing
                Dim compressedStream As GZipStream = Nothing
                Dim ReturnValue As String = Nothing
                Try
                    ' Read the bytes from the source file into a byte array
                    sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read)
                    ' Read the source stream values into the buffer
                    buffer = New Byte(sourceStream.Length) {}
                    Dim checkCounter As Integer = sourceStream.Read(buffer, 0, buffer.Length)
                    ' Open the FileStream to write to
                    destinationStream = New FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write)
                    ' Create a compression stream pointing to the destiantion stream
                    compressedStream = New GZipStream(destinationStream, CompressionMode.Compress, True)
                    'Now write the compressed data to the destination file
                    compressedStream.Write(buffer, 0, buffer.Length)
                    ReturnValue = "Success"
                Catch ex As ApplicationException
                    ReturnValue = ex.Message
                Finally
                    ' Make sure we allways close all streams
                    If Not (sourceStream Is Nothing) Then
                        sourceStream.Close()
                    End If
                    If Not (compressedStream Is Nothing) Then
                        compressedStream.Close()
                    End If
                    If Not (destinationStream Is Nothing) Then
                        destinationStream.Close()
                    End If
                End Try
                Return ReturnValue
            End Function
            Public Function DecompressFile(ByVal sourceFile As String, ByVal destinationFile As String) As String
                Dim ReturnValue As String = Nothing
                ' make sure the source file is there
                If File.Exists(sourceFile) = False Then
                    Throw New FileNotFoundException
                End If
                ' Create the streams and byte arrays needed
                Dim sourceStream As FileStream = Nothing
                Dim destinationStream As FileStream = Nothing
                Dim decompressedStream As GZipStream = Nothing
                Dim quartetBuffer As Byte() = Nothing
                Try
                    ' Read in the compressed source stream
                    sourceStream = New FileStream(sourceFile, FileMode.Open)
                    ' Create a compression stream pointing to the destiantion stream
                    decompressedStream = New GZipStream(sourceStream, CompressionMode.Decompress, True)
                    ' Read the footer to determine the length of the destiantion file
                    quartetBuffer = New Byte(4) {}
                    Dim position As Integer = CType(sourceStream.Length, Integer) - 4
                    sourceStream.Position = position
                    sourceStream.Read(quartetBuffer, 0, 4)
                    sourceStream.Position = 0
                    Dim checkLength As Integer = BitConverter.ToInt32(quartetBuffer, 0)
                    Dim buffer(checkLength + 100) As Byte
                    Dim offset As Integer = 0
                    Dim total As Integer = 0
                    ' Read the compressed data into the buffer
                    While True
                        Dim bytesRead As Integer = decompressedStream.Read(buffer, offset, 100)
                        If bytesRead = 0 Then
                            Exit While
                        End If
                        offset += bytesRead
                        total += bytesRead
                    End While
                    ' Now write everything to the destination file
                    destinationStream = New FileStream(destinationFile, FileMode.Create)
                    destinationStream.Write(buffer, 0, total)
                    ' and flush everyhting to clean out the buffer
                    destinationStream.Flush()
                    ReturnValue = "Success"
                Catch ex As ApplicationException
                    ReturnValue = ex.Message
                Finally
                    ' Make sure we allways close all streams
                    If Not (sourceStream Is Nothing) Then
                        sourceStream.Close()
                    End If
                    If Not (decompressedStream Is Nothing) Then
                        decompressedStream.Close()
                    End If
                    If Not (destinationStream Is Nothing) Then
                        destinationStream.Close()
                    End If
                End Try
                Return ReturnValue
            End Function
            Protected Overrides Sub Finalize()
                MyBase.Finalize()
            End Sub
        End Class
    Fournis dans les samples de Microsoft..
    J'espere que ca t'aidera.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 23
    Par défaut
    Désolé de cette réponse tardive mais mes fonction fonctionne très bien dans un enviromment .NET uniquement.

    Le problème se situe après la réception du fichier xml compressé en php.

    Si qq'un voit une astuce merci de la posté.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    23
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 23
    Par défaut
    UP

Discussions similaires

  1. [VS.Net][Framework] creer un setup incluant le framework
    Par plasticgoat dans le forum Visual Studio
    Réponses: 13
    Dernier message: 18/03/2007, 19h00
  2. MFC et .Net Framework
    Par ihssen dans le forum MFC
    Réponses: 2
    Dernier message: 26/03/2005, 15h34
  3. Réponses: 8
    Dernier message: 22/11/2004, 12h27
  4. decompression gzip
    Par ma2th dans le forum Autres éditeurs
    Réponses: 2
    Dernier message: 11/05/2004, 13h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo