SQLitening Support Forum

SQLitening Support => You've got Questions? We've got Answers! => Topic started by: Rolf Brandt on February 23, 2011, 11:08:56 am

Title: ZLib Wrapper Routines
Post by: Rolf Brandt on February 23, 2011, 11:08:56 am
Hello Fred,
I was just toying with those routines:
http://www.sqlitening.com/support/index.php?topic=3254.0

Can they be used to create zip files from existing files or directories also?
Is there an example?
Title: Re: ZLib Wrapper Routines
Post by: Fred Meier on February 23, 2011, 11:37:52 am
Yes, these routines can read/write/create standard zip files.  I will work up some examples and post later.
Title: Re: ZLib Wrapper Routines
Post by: Rolf Brandt on February 23, 2011, 11:38:46 am
Thanks a lot, Fred.
Title: Re: ZLib Wrapper Routines
Post by: Fred Meier on February 24, 2011, 11:25:47 am
I downloaded and reviewed Zipper.Zip and found that Zipper.Bas is a
program that if you compile and run it will create a standard .Zip file
called Test.Zip and then unzip from it.  Let me know if you need more
examples? 
Title: Re: ZLib Wrapper Routines
Post by: Rolf Brandt on February 24, 2011, 11:38:28 am
Hello Fred,

what I really need is to programmatically zip an existing file - let's say a .bas or .exe file - or even a complete directory with several files. I could not find out how to do that with the zipper bas ruts.
Title: Re: ZLib Wrapper Routines
Post by: Fred Meier on February 24, 2011, 12:40:47 pm
This snippet will zip the Ziipper.Bas file to Test.Zip.  Replace
PbMain in Ziipper.Bas with this snippet. 

I just now noticed that there are two i's in "Zipper", my mistake. 

   Local lsA as String
   Local lsZCB as String

   arZipFileInsertOpen "Test.Zip", lsZCB
   open "Ziipper.Bas" for binary lock shared as #1
   get$ #1, lof(#1), lsA
   close #1
   arZipFileInsertPut lsZCB, "Ziipper.Bas", lsA
   arZipFileInsertClose lsZCB


To do a folder, you would have to do someting like following:
   arZipFileInsertOpen "Test.Zip", lsZCB
   for each file in folder
      open file_name for binary lock shared as #1
      get$ #1, lof(#1), lsA
      close #1
      arZipFileInsertPut lsZCB, file_name, lsA
   next
   arZipFileInsertClose lsZCB


Title: Re: ZLib Wrapper Routines
Post by: Rolf Brandt on February 24, 2011, 01:05:17 pm
That is great, Fred. Thanks a lot!
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 11, 2017, 08:36:01 pm
Hello,

Is there a way one can unzip a zipped file using the technique Fred posted a while ago?

Best regards,
Title: Re: ZLib Wrapper Routines
Post by: cj on July 11, 2017, 10:31:36 pm
Yes.  I'm not sure this is from his code.                       https://forum.powerbasic.com/forum/user-to-user-discussions/third-party-addons/29121-litezip-liteunzip/page2?t=28376&page=2
copy sqliteningzlib.dll to zlib.dll or change calls.

FUNCTION PBMAIN

   LOCAL lsA, lsB AS STRING
   LOCAL lsZCB AS STRING

   ' zip it
   arZipFileInsertOpen "Text.Zip", lsZCB
   lsA = "This is some data to put in zip file."
   arZipFileInsertPut lsZCB, "MyFile.Txt", lsA
   arZipFileInsertClose lsZCB

   ' unzip it
   arZipFileGetFile "Text.Zip", 1, lsB
   ? lsB
END FUNCTION     
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 12, 2017, 08:53:43 am
Hello CJ,

Cool. Really cool.

I would take a closer look later.

Thank you, CJ.
Title: Re: ZLib Wrapper Routines
Post by: cj on July 12, 2017, 08:57:59 am
I know there are also some routines that call SqliteningZlib.dll the same way SQLitening does using AuxRuts if you need them.
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 12, 2017, 09:02:01 am
Hello CJ,

Where are these keywords from:

arZipFile...

Don't think they are in the SQLitening help file.

Regards,

Title: Re: ZLib Wrapper Routines
Post by: cj on July 12, 2017, 10:30:05 am
They are from the routines in the download link to zipper.zip
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 12, 2017, 12:18:37 pm
CJ,

I just tried downloading the zipper.zip and I got:

"404 - Attachment Not Found"
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 12, 2017, 12:20:16 pm
I just downloaded the one you uploaded.
Title: Re: ZLib Wrapper Routines
Post by: cj on July 12, 2017, 12:23:09 pm
I went back to that link by Fred at http://www.sqlitening.com/support/index.php?topic=3254.0 and got not found, too.
Glad you downloaded the one I posted, but not sure it was the same thing.
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 13, 2017, 02:14:35 pm
Hello CJ,

Here is what I have done so far.


#COMPILE EXE
#DIM ALL
#DEBUG ERROR ON
#INCLUDE "Win32API.inc"

' ==========>>> Equates
   %prZipFileFileLength = 30
   %prZipFileDirLength = 46
   %prZipFileEndDirLength = 22
   %ZLibZip_NO_COMPRESSION         = 0
   %ZLibZip_BEST_SPEED             = 1
   %ZLibZip_BEST_COMPRESSION       = 9
   %ZLibZip_DEFAULT_COMPRESSION    = (-1)
   %ZLibZip_DEFLATED               = 8
   %MaxPath = 260
   $WrdMrk = CHR$(&HF2)    'Word Mark(Words)       - &HF2
   $SegMrk = CHR$(&HFB)    'Segment Mark(Segments) - &HFB

   ' ==========>>> Types
TYPE DateTime_TYPE
  hSecond    AS DWORD
  hMinute      AS DWORD
  hHour      AS DWORD
  hDay      AS DWORD
  hMonth     AS DWORD
  hYear     AS DWORD
END TYPE
TYPE FileInfo_TYPE
  uDateTime    AS DateTime_TYPE
  hDosDate     AS DWORD
  hAttribute   AS DWORD
  hAttribute2  AS DWORD
END TYPE
TYPE FileInfoX_TYPE
  version               AS DWORD
  version_needed        AS DWORD
  flag                  AS DWORD
  compression_method    AS DWORD
  dosDate               AS DWORD
  crc                   AS DWORD
  compressed_size       AS DWORD
  uncompressed_size     AS DWORD
  size_filename         AS DWORD
  size_file_extra       AS DWORD
  size_file_comment     AS DWORD
  disk_num_start        AS DWORD
  internal_fa           AS DWORD
  external_fa           AS DWORD
  tmu_date              AS DateTime_TYPE
END TYPE

   ' ==========>>> Declares
DECLARE FUNCTION ZLibUnzOpen LIB "sqliteningzlib.dll" ALIAS "unzOpen" (rsFileName AS ASCIZ) AS DWORD
DECLARE FUNCTION ZLibUnzClose LIB "sqliteningzlib.dll" ALIAS "unzClose" (BYVAL rhFileHand AS DWORD) AS DWORD
DECLARE FUNCTION ZLibUnzGoToFirstFile LIB "sqliteningzlib.dll" ALIAS "unzGoToFirstFile"(BYVAL rhFileHand AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzGoToNextFile LIB "sqliteningzlib.dll" ALIAS "unzGoToNextFile"(BYVAL rhFileHand AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzGetCurrentFileInfo LIB "sqliteningzlib.dll" ALIAS "unzGetCurrentFileInfo"(BYVAL rhFileHand AS DWORD, BYREF pFile_Info AS FileInfoX_TYPE, BYREF szFileName AS ASCIIZ, _
                              BYVAL FileNameBufLen AS DWORD, BYREF pExtra AS ANY, BYVAL pExtraLen AS DWORD, BYREF szComment AS ASCIIZ, BYVAL szCommentLen AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzOpenCurrentFile LIB "sqliteningzlib.dll" ALIAS "unzOpenCurrentFile"(BYVAL fh AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzCloseCurrentFile LIB "sqliteningzlib.dll" ALIAS "unzCloseCurrentFile"(BYVAL fh AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzReadCurrentFile LIB "sqliteningzlib.dll" ALIAS "unzReadCurrentFile"(BYVAL fh AS LONG, BYREF buf AS ANY, BYVAL bufLen AS DWORD) AS LONG
DECLARE FUNCTION ZLibZipOpen LIB "sqliteningzlib.dll" ALIAS "zipOpen" (rsFileName AS ASCIZ, BYVAL rlAppend AS LONG) AS DWORD
DECLARE FUNCTION ZLibZipClose LIB "sqliteningzlib.dll" ALIAS "zipClose" (BYVAL rhFileHand AS DWORD, rsGlobalComment AS ASCIZ) AS LONG
DECLARE FUNCTION ZLibZipOpenNewFileInZip LIB "sqliteningzlib.dll" ALIAS "zipOpenNewFileInZip" (BYVAL rhFileHand AS DWORD, BYREF rsFileName AS ASCIZ, _
BYREF ruFileInfo AS FileInfo_TYPE, BYREF rsExtraLocal AS ANY, BYVAL rlExtraSize  AS LONG, BYREF rsExtraGlobal  AS _
ANY, _
                              BYVAL rlExtraSize AS LONG, BYREF rsComment AS ASCIZ, BYVAL rlMethod AS LONG, BYVAL rlLevel AS LONG)AS LONG
DECLARE FUNCTION ZLibZipWriteInFileInZip LIB "sqliteningzlib.dll" ALIAS "zipWriteInFileInZip"(BYVAL rhFileHand AS DWORD, BYREF rsBuffer AS ANY, BYVAL rlBufferSize AS LONG)AS LONG
DECLARE FUNCTION ZLibZipCloseFileInZip LIB "sqliteningzlib.dll" ALIAS "zipCloseFileInZip"(BYVAL rhFileHand AS DWORD)AS LONG
DECLARE FUNCTION FileTimeToSystemTimeMine LIB "KERNEL32.DLL" ALIAS "FileTimeToSystemTime" (lpFileTime AS QUAD, lpSystemTime AS SYSTEMTIME) AS LONG
DECLARE FUNCTION SystemTimeToFileTimeMine LIB "KERNEL32.DLL" ALIAS "SystemTimeToFileTime" (lpSystemTime AS SYSTEMTIME, lpFileTime AS QUAD) AS LONG

SUB axErrorAt (BYVAL rlLineNumber AS LONG)
   MSGBOX "Severe error at line number " & FORMAT$(rlLineNumber)
   ExitProcess 8
END SUB

SUB arZipFileGetFile(rsZipFileName AS STRING, BYVAL rlFileNumber AS LONG, wsFileData AS STRING)
'   Returns, in FileData, uncompressed data from FileNumber in ZipFileName.

   LOCAL lhUnZipFileHandle AS DWORD
   LOCAL luFI AS FileInfoX_TYPE
   LOCAL lzA AS ASCIZ * 1

   lhUnZipFileHandle = ZLibUnzOpen(BYCOPY rsZipFileName)
   DO
      DECR rlFileNumber
      IF rlFileNumber = 0 THEN

         ' This is the file they want
         ZLibUnzGetCurrentFileInfo lhUnZipFileHandle, luFI, lzA, 0, lzA, 0, lzA, 0
         ZLibUnzOpenCurrentFile lhUnZipFileHandle

         wsFileData = SPACE$(luFI.uncompressed_size)
         IF ZLibUnzReadCurrentFile(lhUnZipFileHandle, BYVAL STRPTR(wsFileData), LEN(wsFileData)) <> LEN(wsFileData) THEN axErrorAt 1236
         ZLibUnzCloseCurrentFile lhUnZipFileHandle
         EXIT DO

      END IF
   LOOP WHILE ZLibUnzGoToNextFile(lhUnZipFileHandle) = 0
   IF rlFileNumber THEN axErrorAt 1242

   ' Close it and were done
   ZLibUnzClose lhUnZipFileHandle

END SUB

FUNCTION PBMAIN () AS LONG

    LOCAL lsB AS STRING

    arZipFileGetFile "HopewellHospitalPro.zip", 1, lsB

    ? lsB
END FUNCTION


The output from the messagebox gives MZ. But I can't see the unzipped file.

Any ideas?

Best regards,

Title: Re: ZLib Wrapper Routines
Post by: cj on July 13, 2017, 02:23:41 pm
Try putting only a text file into a zip file.
It looks like you are displaying an executable binary file using messagebox.
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 13, 2017, 02:55:30 pm
CJ,

Quote
Try putting only a text file into a zip file.
It looks like you are displaying an executable binary file using messagebox.


Did that. It displays the content of the text zipped file.

I want to unzip the zipped executable binary file.

Not possible?
Title: Re: ZLib Wrapper Routines
Post by: cj on July 13, 2017, 04:22:16 pm
FUNCTION PBMAIN

LOCAL sData AS STRING, hFile AS LONG

FileToZip "myzip.zip","test.exe"    'put into myzip.zip,text.exe
sData$ = FileFromZip("myzip.zip",1) 'get first file in zip

END FUNCTION

FUNCTION FileToZip(sZipFile AS STRING, sFileIntoZip AS STRING) AS LONG
LOCAL sZipControlBlock AS STRING
LOCAL sGetBuffer       AS STRING
LOCAL sPutBuffer       AS STRING
LOCAL hFile AS LONG
hfile = FREEFILE
OPEN sFileIntoZip FOR BINARY AS hFile
IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
GET$ hfile,LOF(hFile),sPutBuffer
IF ERR THEN ? "get error":CLOSE #hfile:FUNCTION = ERR:EXIT FUNCTION
CLOSE #hFile
arZipFileInsertOpen sZipFile, sZipControlBlock
arZipFileInsertPut sZipControlBlock, sFileIntoZip, sPutBuffer
arZipFileInsertClose sZipControlBlock
END FUNCTION

FUNCTION FileFromZip(sZipFile AS STRING, FileNumber AS LONG) AS STRING
LOCAL sGetBuffer AS STRING
arZipFileGetFile sZipFile, 1, sGetBuffer
FUNCTION = sGetBuffer
END FUNCTION

Title: Re: ZLib Wrapper Routines
Post by: cj on July 14, 2017, 06:20:23 am
Looks like the code for the library came from Jim Dunn at PowerBASIC site (not the code I created in the previous post using it.)
It looks like he posted the code after someone used Jose Roca code and had trouble updating/adding archives with multiple files.
https://forum.powerbasic.com/forum/user-to-user-discussions/third-party-addons/29121-litezip-liteunzip/page2?t=28376&page=2
Title: Re: ZLib Wrapper Routines
Post by: Bern Ertl on July 14, 2017, 12:16:11 pm
See also:

https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/14208-creating-a-standard-zip-file-with-zlib-v1-2-3-0
Title: Re: ZLib Wrapper Routines
Post by: cj on July 16, 2017, 02:54:59 am
Another link using same dll as Sqlitening:
https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/62095-looking-for-a-pb-compression-or-zip-program
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 16, 2017, 01:03:48 pm
Thanks CJ.

Just got back from a short trip.

Would try out the links you provided later on.

Best regards,
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 16, 2017, 08:02:11 pm
CJ,

I tried the link you provided above.

Still can't unzip my exe file.
Title: Re: ZLib Wrapper Routines
Post by: cj on July 16, 2017, 09:22:59 pm
Can't unzip an executable.  Is it a zip file?
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on July 16, 2017, 10:26:40 pm
Yes. It's a zipped exe file.
Title: Re: ZLib Wrapper Routines
Post by: cj on July 17, 2017, 12:00:14 am
What is the call statement?
Is there an error message?
Check that the downloaded DLL is not blocked in properties or use SQLiteningZlib.DLL.
Archive file must be closed when you access it.
Title: Re: ZLib Wrapper Routines
Post by: cj on July 21, 2017, 08:27:21 pm
I see you created another thread.

Same questions,  does your call statement look like this?
> Not seeing unzipped file
It returns a string


FUNCTION PBMAIN

LOCAL sData AS STRING, hFile AS LONG

FileToZip "myzip.zip","test.exe"    'put into myzip.zip,test.exe
sData$ = FileFromZip("myzip.zip",1) 'get first file in zip

END FUNCTION

FUNCTION FileToZip(sZipFile AS STRING, sFileIntoZip AS STRING) AS LONG
LOCAL sZipControlBlock AS STRING
LOCAL sGetBuffer       AS STRING
LOCAL sPutBuffer       AS STRING
LOCAL hFile AS LONG
hfile = FREEFILE
OPEN sFileIntoZip FOR BINARY AS hFile
IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
GET$ hfile,LOF(hFile),sPutBuffer
IF ERR THEN ? "get error":CLOSE #hfile:FUNCTION = ERR:EXIT FUNCTION
CLOSE #hFile
arZipFileInsertOpen sZipFile, sZipControlBlock
arZipFileInsertPut sZipControlBlock, sFileIntoZip, sPutBuffer
arZipFileInsertClose sZipControlBlock
END FUNCTION

FUNCTION FileFromZip(sZipFile AS STRING, FileNumber AS LONG) AS STRING
LOCAL sGetBuffer AS STRING
arZipFileGetFile sZipFile, 1, sGetBuffer
FUNCTION = sGetBuffer
END FUNCTION

Title: Re: ZLib Wrapper Routines
Post by: cj on July 25, 2017, 12:17:07 pm
zLib doesn't use standard .zip format so this is a good read.

https://stackoverflow.com/questions/11611950/unzip-a-zip-file-using-zlib
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on August 01, 2017, 04:02:28 pm
CJ, thank you for the link.
Title: Re: ZLib Wrapper Routines
Post by: Fredrick Ughimi on August 06, 2017, 01:13:46 pm
Hello CJ,

I took the time out today to work on this.

LiteZip worked well for me. Both zip and unzip worked great!

https://forum.powerbasic.com/forum/user-to-user-discussions/third-party-addons/29121-litezip-liteunzip/page2?t=28376&page=2

Best regards,