• Sábado 4 de Mayo de 2024, 12:11

Autor Tema:  Zip  (Leído 1960 veces)

casi62

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Zip
« en: Martes 27 de Octubre de 2009, 00:47 »
0
Saludos...

Nuevamente molestando...

Estoy usando las librerias para zipear archivos...

ICSharpCode.SharpZipLib.Zip;
ICSharpCode.SharpZipLib.Checksums;

En una aplicacion C# lo unico que quiero es compactar un par de archivos PDF con un .zip con contraseña... cosa que ya realizo sin ningun problema...

Mi duda es por que al querer descompactar el .zip por medio de la forma habitual es decir... click derecha del raton "extraer aqui..." y obviamente teclear al contraseña previamente definida... se queda bloqueado el archivo... es decir.... no permite el extracion... claro esta... la contraseña es correcta.

Adjunto la funcion del zip....

 public void Comprimir(string[] fileNames, string zipFic, string password)
        {
            // comprimir los ficheros del array en el zip indicado
            Crc32 objCrc32 = new Crc32();
            ZipOutputStream strmZipOutputStream;
           
            strmZipOutputStream = new ZipOutputStream(File.Create(zipFic));
            strmZipOutputStream.SetLevel(1);
            //Asignamos la contraseña
            if (password != null && password != String.Empty)
                strmZipOutputStream.Password = password;

            strmZipOutputStream.SetLevel(6);
            //
            foreach (string strFile in fileNames)
            {  
               FileStream strmFile = File.OpenRead(strFile);
                byte[] abyBuffer = new byte[(Convert.ToInt32(strmFile.Length))];
                //
                strmFile.Read(abyBuffer, 0, abyBuffer.Length);
               
                string sFile = Path.GetFileName(strFile);
                ZipEntry theEntry = new ZipEntry(sFile);
                // guardar la fecha y hora de la última modificación
                FileInfo fi = new FileInfo(strFile);
                theEntry.DateTime = fi.LastWriteTime;
                //
                theEntry.Size = strmFile.Length;
                theEntry.IsCrypted = false;
                strmFile.Close();
                objCrc32.Reset();
                objCrc32.Update(abyBuffer);
                theEntry.Crc = objCrc32.Value;
                strmZipOutputStream.PutNextEntry(theEntry);
                strmZipOutputStream.Write(abyBuffer, 0, abyBuffer.Length);
            }
            strmZipOutputStream.Finish();
            strmZipOutputStream.Close();
        }

Espero puedan auxiliarme...

Que tengas buen día....

tannke

  • Miembro MUY activo
  • ***
  • Mensajes: 152
  • Nacionalidad: es
    • Ver Perfil
Re: Zip
« Respuesta #1 en: Martes 27 de Octubre de 2009, 15:44 »
0
prueba si este link te puede solucionar algo, sino avisa y miraremos haber que podemos hacer.

http://www.picacodigos.com/CategoryView,category,Art%C3%ADculos.aspx

esta en la entrada de dia 4

casi62

  • Nuevo Miembro
  • *
  • Mensajes: 6
    • Ver Perfil
Re: Zip
« Respuesta #2 en: Martes 27 de Octubre de 2009, 17:15 »
0
Saludos...

Agradezco la informacion...

En efecto encontre el problema.. tiene que ver con el buffer y el tamaño del archivo asi es que envio la actualizacion del codigo... funcional...

Si algien lo necesita adelante...

public void Comprimir(string[] fileNames, string zipFic, string password)
        {
            // comprimir los ficheros del array en el zip indicado
            using (ZipOutputStream strmZipOutputStream = new ZipOutputStream(File.Create(zipFic)))
            {
                //Asignamos la contraseña
                if (password != null && password != String.Empty)
                    strmZipOutputStream.Password = password;

                Crc32 crc = new Crc32();

                // Compression Level: 0-9
                // 0: no(Compression) - 9: maximum compression
                strmZipOutputStream.SetLevel(6);

                foreach (string strFile in fileNames)
                {
                    FileStream fs = File.OpenRead(strFile);
                    string sFile = Path.GetFileName(strFile);
                    ZipEntry zE = new ZipEntry(sFile);
                    int bytesRead;
                    byte[] mBuffer = new byte[fs.Length];
                    crc.Reset();
                    strmZipOutputStream.PutNextEntry(zE);
                    while (fs.Position < fs.Length)
                    {
                        bytesRead = fs.Read(mBuffer, 0, mBuffer.Length);
                        strmZipOutputStream.Write(mBuffer, 0, bytesRead);
                        crc.Update(mBuffer, 0, bytesRead);
                    }
                    zE.Crc = crc.Value;
                    zE.DateTime = File.GetCreationTime(strFile);
                    zE.Size = fs.Length;
                    fs.Close();
                }
                strmZipOutputStream.Finish();
                strmZipOutputStream.Close();
            }
        }