como determino error en archivo zip

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
jucar_es
Posts: 82
Joined: Thu Nov 13, 2008 11:12 pm

como determino error en archivo zip

Post by jucar_es »

Hola todos

en mi aplicacion debo descomprimir archivos

algunas veces el archivo esta corrupto

y genera el error

hb_unzipfilefirst(0) y detiene el proceso

existe alguna forma de determinar que ese archivo esta corrupto?

para ignorarlo

gracias a todos
ClaudioGalera
Posts: 47
Joined: Tue Jul 14, 2009 1:14 pm
Location: Mar del Plata, Argentina

Re: como determino error en archivo zip

Post by ClaudioGalera »

Google Translate
[quote]
[b]Subject : Error as determined in zipfile[/b]

Hello all
in my application I need to decompress files
sometimes the file is corrupted
and generates the error
hb_unzipfilefirst (0) and stops the process
there is any way to determine that the file is corrupt?
to ignore
thank all
[/quote]
Last edited by ClaudioGalera on Wed Jul 29, 2009 9:25 pm, edited 1 time in total.
ClaudioGalera
Posts: 47
Joined: Tue Jul 14, 2009 1:14 pm
Location: Mar del Plata, Argentina

Re: como determino error en archivo zip

Post by ClaudioGalera »

Hola Jucar_es, una solucion que se puede implementar es comprobando el CRC (MD5) por medio de la funcion HB_MD5FILE.
La explicacion es a grandes rasgos, que esta funcion calcula un string (checksum) que identifica unicamente a ese archivo.
Como lo usamos ?
1) La aplicacion que crea el archivo zip crea tambien un segundo archivo conteniendo el checksum ej :
clientes.zip y clientes.md5 conteniendo el un string dentro parecido a esto : be8f69d2a2f93c2f9ccb4e7462e2bc22

Code: Select all

...
if file("clientes.zip")
  md5string := hb_md5file("clientes.zip")
  x := fcreate("clientes.md5")
   fwrite(x,md5string)
   fclose(x)
endif
COPY FILE  clientes.zip  TO  a:\clientes.zip
COPY FILE clientes.md5 TO a:\clientes.md5
...
2) al recibir el archivo la aplicacion que va a descomprimir el archivo zip calculara el md5 del archivo zip y lo compara con el contenido del segundo archivo y si no son iguales quiere decir que el archivo llego corrupto.

Code: Select all

...
if ! file("clientes.md5")
    msginfo("Error")
else
     md5string := hb_md5file("clientes.zip")
     x := fopen("clientes.md5")
     md5read := freadstr(x,32)
     fclose(x)
      if md5read <> md5string
          msginfo("Error in file clientes.zip")
...
Espero que te sea util la idea.
Saludos
Claudio

Google Translation

Hello Jucar_es, a solution that can be implemented by checking the CRC is (MD5) through HB_MD5FILE function.
The reason is roughly that this function generates a string (checksum) that unique identifier to that file.
As we use?
1) The application that creates the zip file also creates a second file containing the checksum example:
clientes.zip and clientes.md5 containing a string inside like this: be8f69d2a2f93c2f9ccb4e7462e2bc22[/ b]

Code: Select all

...
if file("clientes.zip")
  md5string := hb_md5file("clientes.zip")
  x := fcreate("clientes.md5")
   fwrite(x,md5string)
   fclose(x)
endif
COPY FILE  clientes.zip  TO  a:\clientes.zip
COPY FILE clientes.md5 TO a:\clientes.md5
...
2) upon receiving the application file which will unzip the zip file cheksum calculate the MD5 of the zip file and compares it with the contents of the second file, and if they are not equal means that the file get corrupted.

Code: Select all

...
if ! file("clientes.md5")
    msginfo("Error")
else
     md5string := hb_md5file("clientes.zip")
     x := fopen("clientes.md5")
     md5read := freadstr(x,32)
     fclose(x)
      if md5read <> md5string
          msginfo("Error in file clientes.zip")
...

I hope you find the idea useful.
Greetings
Claudio
jucar_es
Posts: 82
Joined: Thu Nov 13, 2008 11:12 pm

Re: como determino error en archivo zip

Post by jucar_es »

Muchas Gracias

probaré
Post Reply