ZIP / UnZip simple

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2062
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

ZIP / UnZip simple

Post by AUGE_OHR »

hi,

i know HMG have COMPRESS and there also other Way e.g. 7ZIP

i like to show what is "behind" xCommand on Sample how to ZIP
Windows have build-in ZIP Support since XP and it is easy to use it

1.) create file and write "Header"

Code: Select all

LOCAL aHead := {80,75,5,6,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

   // create ZIP and write Header
   //
   nHandle := FCreate( cZipFile, FC_NORMAL )
   iMax := LEN(aHead)
   FOR i := 1 TO iMax
      FWrite( nHandle, CHR( aHead[i]) )
   NEXT
   FClose( nHandle )
2.) create "Shell.Application" Object and "access ZIP" as virtual Folder

Code: Select all

   // create COM Object
   //
   oShell   := CreateObject("Shell.Application")
   oZIP     := oShell:NameSpace(cZipFile)
3.) use COPYHERE() to "stream" file to virtual ZIP Folder

Code: Select all

      FOR i := 1 TO nFiles
         cFile := aFiles[i]
         oZIP:CopyHere(cFile,xFlag)              // copy one file

         // wait until all file are written
         //
         xCount := 0
         DO WHILE .T.
            nCount := oZIP:items():Count()
            IF nCount >= i
               EXIT
            ENDIF
            SLEEP(10)
            xCount++
            IF xCount > 50
               EXIT
            ENDIF
         ENDDO
      NEXT
while COPYHERE() work as own Thread you have to wait until finish before next.

4.) clean up COM Connection

Code: Select all

   oZIP := NIL
   oShell := NIL
---

more simple to un-zip ( Xbase++ Code )

Code: Select all

FUNCTION Unzip(cZipFile, cDestFolder)
LOCAL oShell, oZIP, oNameDest

   oShell    := CreateObject("Shell.Application")
   oZIP  := oShell:NameSpace(cZipFile)
   oNameDest := oShell:NameSpace(cDestFolder)
   oNameDest:CopyHere(oZIP:items(), 0x10)

   oShell:destroy()  // HMG -> oShell := NIL

RETURN NIL
have fun
Jimmy
Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: ZIP / UnZip simple

Post by Red2 »

Hi Jimmy,

Thank you very much for your example compression code. Regarding UN-zip I have a question. Do you have any an idea how, in HMG, to read the contents of a disk .ZIP file and UN-compress it directly into a memory variable?

The conventional steps:
  • 1) UN-compress a .ZIP to a temporary disk file.
    2) Read this temporary UN-compressed disk file into HMG memory.
    3) Delete this temporary disk file.
The goal is to completely bypass the temporary file and I could to to do this quite simply in Visual FoxPro. (https://www.sweetpotatosoftware.com/blo ... al-foxpro/). I really miss this ability in HMG.

QUESTION: Do you know of a similar solution in HMG/Harbour?

Kind regards, Red2
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: ZIP / UnZip simple

Post by andyglezl »

to read the contents of a disk .ZIP file and UN-compress it directly into a memory variable?
mmmmm...

Se ve simple como lo comentas, pero hay muchas preguntas por responder, como:

* Necesariamente tienen que ser archivos .zip ?
* Todos son archivos de texto ? , cantidad de archivos ?
* tamaño de dichos archivos ? , los quieres pasar a campos MEMO ? o a otro tipo de variables ?
* etc, etc.
Ya has tratado con archivos .MEM ?
*------------------------------------------------------------------------------------------------------------------
mmmmm ...

It looks simple as you say, but there are many questions to answer, such as:

* Do they necessarily have to be .zip files?
* Are they all text files? , how many files?
* size of these files? Do you want to pass them to MEMO fields? or to other types of variables?
* etc etc.
  Have you already dealt with .MEM files?


* Quieres acelerar el tiempo de descompresión ?
*----------------------------------------------------------------
* Do you want to speed up the decompression time?

https://www.profesionalreview.com/2018/12/12/ramdisk/
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
AUGE_OHR
Posts: 2062
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: ZIP / UnZip simple

Post by AUGE_OHR »

hi,

sure it is possible ... but done ask me how ...

i just want to show how using COPYHERE() and virtual Folder can be used to ZIP / un-ZIP file

btw. it is not possible to "add" or "update" a ZIP this Way (delete old and create new)
have fun
Jimmy
Post Reply