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?
Yes, these routines can read/write/create standard zip files. I will work up some examples and post later.
Thanks a lot, Fred.
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?
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.
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
That is great, Fred. Thanks a lot!
Hello,
Is there a way one can unzip a zipped file using the technique Fred posted a while ago?
Best regards,
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
Hello CJ,
Cool. Really cool.
I would take a closer look later.
Thank you, CJ.
I know there are also some routines that call SqliteningZlib.dll the same way SQLitening does using AuxRuts if you need them.
Hello CJ,
Where are these keywords from:
arZipFile...
Don't think they are in the SQLitening help file.
Regards,
They are from the routines in the download link to zipper.zip
CJ,
I just tried downloading the zipper.zip and I got:
"404 - Attachment Not Found"
I just downloaded the one you uploaded.
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.
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,
Try putting only a text file into a zip file.
It looks like you are displaying an executable binary file using messagebox.
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?
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
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
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
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
Thanks CJ.
Just got back from a short trip.
Would try out the links you provided later on.
Best regards,
CJ,
I tried the link you provided above.
Still can't unzip my exe file.
Can't unzip an executable. Is it a zip file?
Yes. It's a zipped exe file.
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.
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
zLib doesn't use standard .zip format so this is a good read.
https://stackoverflow.com/questions/11611950/unzip-a-zip-file-using-zlib
CJ, thank you for the link.
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,