Ver Mensaje Individual
  #3 (permalink)  
Antiguo 28/10/2008, 08:54
Malyssia
 
Fecha de Ingreso: septiembre-2008
Mensajes: 4
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Problema para zipear usando SharpZipLib

A mi lo que me pasa es que la compresión no la hace bien.


Si lo comprimo con el winzip, me lo descomprime de puta madre pero comprimiendolo con el código siguiente, me da errores "Size mismatch".


Public Sub Comprimir(ByVal strFileNames() As String, ByVal strZipFic As String, _
Optional ByVal crearAuto As Boolean = False)
' comprimir los ficheros del array en el zip indicado
' si crearAuto = True, zipfile será el directorio en el que se guardará
' y se generará automáticamente el nombre con la fecha y hora actual
Dim objCrc32 As New Crc32
Dim oZipOutputStream As ZipOutputStream

If strZipFic = "" Then
strZipFic = "."
crearAuto = True
End If
If crearAuto Then
' Si se crea el nombre del fichero, path + fecha
strZipFic &= "\ZIP" & DateTime.Now.ToString("yyMMddHHmmss") & ".zip"
End If
oZipOutputStream = New ZipOutputStream(File.Create(strZipFic))
' SetLevel -> 0: no compression
' SetLevel -> 9: maximum compression
oZipOutputStream.SetLevel(6)

Dim strFile As String
For Each strFile In strFileNames
Dim strmFile As FileStream = File.OpenRead(strFile)
Dim bytBuffer(Convert.ToInt32(strmFile.Length - 1)) As Byte

strmFile.Read(bytBuffer, 0, bytBuffer.Length)

'------------------------------------------------------------------
' para guardar sin el primer path
'Dim sFile As String = strFile
'Dim i As Integer = sFile.IndexOf("\")
'If i > -1 Then
' sFile = sFile.Substring(i + 1).TrimStart
'End If
'------------------------------------------------------------------
'
'------------------------------------------------------------------
' para guardar sólo el nombre del fichero
' esto sólo se debe hacer si no se procesan directorios
' que puedan contener nombres repetidos
'Dim sFile As String = Path.GetFileName(strFile)
'Dim theEntry As ZipEntry = New ZipEntry(sFile)
'------------------------------------------------------------------
'
' se guarda con el path completo
Dim theEntry As ZipEntry = New ZipEntry(strFile)
'
' guardar la fecha y hora de la última modificación
Dim fi As New FileInfo(strFile)
theEntry.DateTime = fi.LastWriteTime
'theEntry.DateTime = DateTime.Now
'
theEntry.Size = strmFile.Length
strmFile.Close()
objCrc32.Reset()
objCrc32.Update(bytBuffer)
theEntry.Crc = objCrc32.Value
oZipOutputStream.PutNextEntry(theEntry)
oZipOutputStream.Write(bytBuffer, 0, bytBuffer.Length)
Next
oZipOutputStream.Finish()
oZipOutputStream.Close()
End Sub


Si tras comprimir con este método, lo abro con el Winzip e intento extraer sólo un fichero me dice:
"The compressed size stored in the local header for this file is not the same as the compressed size stored in the central header"
Si los extraigo todos no hay problema.

No entiendo nada :S