
I dont remark that gnozal hasn´t made any choice to change compression mode......
If you read the explanation for the Zipfile you see Zipfiles are very easy to made. (i done it yesterday in a quickhack)
Read the
appnote-xxxxxxxxx-pk.zip at:
ftp://ftp.info-zip.org/pub/infozip/doc and Code youre own ZIPfiles
Here is my solution of making Zipfiles without compression.
NOT TESTED VERY WELL !! only tested on WinXP.
Code: Select all
; example to make (uncompressed) Zipfiles
; For ZIP-Documention see ftp://ftp.info-zip.org/pub/infozip/doc (the appnote-pk.txt)
; author PAMKKKKK 25.March.2006
; PB 3.93
Structure ZipFileHeader
exV.w ;Version needed To extract 2 bytes
gpbFl.w ;general purpose bit flag 2 bytes
cM.w ;compression method 2 bytes
lMod.l ;last mod File time 2 bytes last mod File Date 2 bytes
Crc32.l ;crc-32 4 bytes
cSz.l ;compressed size 4 bytes
uncSz.l ;uncompressed size 4 bytes
Flen.w ;FileName length 2 bytes
extra.w ;extra field length 2 bytes
lenComnt.w ; File comment length 2 bytes
Disk.w ; disk number start 2 bytes
inFAttr.w ; internal File attributes 2 bytes
exFAttr.l ; external File attributes 4 bytes
Offs.l ; relative offset of local header 4 bytes
Comment.s; File comment (variable size)
Fname.s ;filename (variable size)
Fextra.s ;extra field (variable size)
OFilename.s ; Original Filename
EndStructure
NewList LocalFile.ZipFileHeader()
; WIN-API !!!!!!
Procedure.l FileDateToDosDate(File.s)
; Converts the last writetime to a Dos-Formated Time
; THE TIME CAN BE INCORRECT, IN CONTRYS WITH SUMMER AND WINTER TIME !!!
Handle=CreateFile_(@File.s,#GENERIC_READ,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,#FILE_ATTRIBUTE_NORMAL,0)
If Handle<>#INVALID_HANDLE_VALUE
GetFileTime_(Handle,0,0,FT.FILETIME) ; Last Writetime
Else
ProcedureReturn -1 ; Error File dosnt exist or not accesable
EndIf
FileTimeToDosDateTime_(FT,@FatDate.w,@FatTime.w)
CloseHandle_(Handle) ; Close the File
ProcedureReturn FatDate<<16 + FatTime
EndProcedure
;-Add_to_Locallist***********************************************
Procedure Add_to_Locallist(FileToAdd.s,Flags)
; Store Path relative or not...
If Flags&%1
FileName.s = FileToAdd
Else
FileName.s = GetFilePart(FileToAdd)
EndIf
; Filling LocalList
AddElement(LocalFile())
;WriteLong($04034B50) ; local File header signature 4 bytes (0x04034b50)
LocalFile()\exV = $000A ; Hardcoded Version need to be extract
LocalFile()\gpbFl = $0000 ; Hardcoded Flags
LocalFile()\cM = $0000 ; Hardcoded compression methode, cause no compression used yet!
LocalFile()\lMod = FileDateToDosDate(FileToAdd) ; Last mod FileDat in Dos Format (big-endian)
;LocalFile()\Crc32 = CRC32FileFingerprint(FileToAdd) CRC calculation made in Make_Zip (for performance)
LocalFile()\cSz = FileSize(FileToAdd) ; We dont compress so the Filesize is = compressionsize
LocalFile()\uncSz = FileSize(FileToAdd) ; simple the Uncompressed Filesize
LocalFile()\Flen = Len(FileName) ; length of the Filename
LocalFile()\extra = 0 ; Not used yet !
LocalFile()\lenComnt = 0 ; Not used yet ! ; File comment length 2 bytes
LocalFile()\Disk = 0 ; Not used yet ! ; disk number start 2 bytes
LocalFile()\inFAttr = 0 ; Not used yet ! ; internal File attributes 2 bytes
LocalFile()\exFAttr = 0 ; Not used yet ! ; external File attributes 4 bytes
;Offs.l ; Not used here ! relative offset is set by file writing.
LocalFile()\Comment = "" ; Not used yet ! ; File comment (variable size)
LocalFile()\Fname = FileName ; Path relative or not was made at the start of these Procedure
LocalFile()\Fextra = "" ; Not used yet !
LocalFile()\OFilename = FileToAdd ; Original File Path where the File is taken from
EndProcedure
;-Add_End_of_central_dir_record ********************************************
Procedure Add_End_of_central_dir_record(ZipFile.s,DirSz.l,headOffset.l)
ResetList(LocalFile())
HFile = OpenFile(#PB_Any, ZipFile)
If HFile
FileSeek(Lof()) ; append the header
WriteLong($06054B50) ;End of central dir signature 4 bytes (0x06054b50)
WriteWord(0) ;number of this Disk 2 bytes
WriteWord(0) ;number of the Disk with the start of the central Directory 2 bytes
WriteWord(CountList(LocalFile())) ;total number of entries in the central dir on this Disk 2 bytes
WriteWord(CountList(LocalFile())) ;total number of entries in the central dir 2 bytes
WriteLong(DirSz) ;size of the central Directory 4 bytes
WriteLong(headOffset) ;offset of start of central Directory with respect To the starting Disk number 4 bytes
WriteWord(0) ;ZipFile Comment length 2 bytes
WriteString("") ;ZipFile comment (variable size)
CloseFile(HFile)
EndIf
EndProcedure
;-Add_Central_Directory_Structure ********************************************
Procedure Add_Central_Directory_Structure(ZipFile.s)
ResetList(LocalFile())
HFile = OpenFile(#PB_Any, ZipFile)
If HFile
FileSeek(Lof()) ; append the header
headOffset = Lof()
While NextElement(LocalFile())
WriteLong($02014B50) ; central File header signature 4 bytes (0x02014b50)
WriteWord($0014) ;Version made by 2 bytes
WriteWord(LocalFile()\exV)
WriteWord(LocalFile()\gpbFl)
WriteWord(LocalFile()\cM)
WriteLong(LocalFile()\lMod)
WriteLong(LocalFile()\Crc32)
WriteLong(LocalFile()\cSz)
WriteLong(LocalFile()\uncSz)
WriteWord(LocalFile()\Flen)
WriteWord(LocalFile()\extra)
WriteWord(LocalFile()\lenComnt)
WriteWord(LocalFile()\Disk)
WriteWord(LocalFile()\inFAttr)
WriteLong($00000020);LocalFile()\exFAttr)
WriteLong(LocalFile()\Offs) ; relative offset of local header 4 bytes
WriteString(LocalFile()\Fname)
WriteString(LocalFile()\Fextra); extra field (variable size)
WriteString(LocalFile()\Comment); File comment (variable size)
Wend
DirSz.l = Lof() - headOffset
CloseFile(HFile)
EndIf
Add_End_of_central_dir_record(ZipFile,DirSz,headOffset)
EndProcedure
;- Make_Zip **************************************************
Procedure Make_Zip(ZipFile.s)
ResetList(LocalFile())
HFile = CreateFile(#PB_Any, ZipFile)
If HFile
While NextElement(LocalFile())
LocalFile()\Offs = Lof()
WriteLong($04034B50) ; local File header signature 4 bytes (0x04034b50)
WriteWord(LocalFile()\exV)
WriteWord(LocalFile()\gpbFl)
WriteWord(LocalFile()\cM)
WriteLong(LocalFile()\lMod)
; open File and do CRC32
FileSz=FileSize(LocalFile()\OFilename)
If FileSz
FileBuffer = AllocateMemory(FileSz); Buffer error dosn´t catch !
If FileBuffer
HAddFile = ReadFile(#PB_Any,LocalFile()\OFilename)
If HAddFile
L0 = ReadData(FileBuffer, FileSz) ; Buffer error dosn´t catch !
LocalFile()\Crc32 = CRC32Fingerprint(FileBuffer, FileSz)
CloseFile(HAddFile) ;closing File, File is in Buffer now
EndIf
EndIf
EndIf
WriteLong(LocalFile()\Crc32)
; compression is not used yet!
;if you want to compress do it here with the FileBuffer !!
WriteLong(LocalFile()\cSz)
WriteLong(LocalFile()\uncSz)
WriteWord(LocalFile()\Flen)
WriteWord(LocalFile()\extra)
WriteString(LocalFile()\Fname)
WriteString(LocalFile()\Fextra)
; writing File from Buffer to Zipfile
UseFile(HFile)
FileSeek(Lof()) ; append mode
WriteData( FileBuffer, FileSz)
FreeMemory(FileBuffer) ; clean up ;-)
Wend
CloseFile(HFile)
EndIf
; Adding the global header
Add_Central_Directory_Structure(ZipFile)
EndProcedure
; **************************************************
; MAIN
; **************************************************
; First add the files to the list
; Flag is only used for pathrelative or not at this time
; 0 = store filename only, 1 = store absolut path
Add_to_Locallist("C:\temp\Text1.txt",0)
Add_to_Locallist("C:\temp\Text2.txt",0)
Add_to_Locallist("C:\temp\Text3.txt",0)
Add_to_Locallist("C:\Windows\notepad.exe",0)
Add_to_Locallist("C:\temp\example.pdf",0)
; if the List is ready make the Zipfile
Make_Zip("C:\temp\ziptest.zip")
; Note
; at this time compression, diskspanning or other is not supported !!!
; if you want to compress see Note in Procedure Make_Zip()