[SOLVED] Packer compression level?

Just starting out? Need help? Post your questions and find answers here.
ergrull0
User
User
Posts: 23
Joined: Sat Mar 08, 2014 4:45 pm

[SOLVED] Packer compression level?

Post by ergrull0 »

Hi! Does anybody know how to set up the compression level when using the packer library (UseZipPacker in my case...)?

Thanks!
Last edited by ergrull0 on Sat Mar 22, 2014 1:49 pm, edited 1 time in total.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Packer compression level?

Post by idle »

You can use this with the zip packer

Code: Select all

EnableExplicit

CompilerIf #PB_Compiler_OS = #PB_OS_Windows 
  ImportC "zlib.lib"
    compress2(*dest,*destlen,*source,sourcelen,level)
 EndImport 
CompilerElse 
  ImportC "-lz"   
    compress2(*dest,*destlen,*source,sourcelen,level)
  EndImport 
CompilerEndIf 

Procedure AddPackFile2(Pack,FileName$,PackedFilename$,level=9)
   Protected fn,*output,*input,outlen,filelen,result 
   
   fn = ReadFile(#PB_Any,FileName$) 
   If fn 
      filelen = Lof(fn)
      outlen = filelen * 1.5
      *input = AllocateMemory(filelen)
      *output = AllocateMemory(outlen)
       If *input And *output  
          If  ReadData(fn,*Input,Filelen) = filelen 
             If Compress2(*output,@outlen,*Input,Filelen,level) = 0  
                Result =  AddPackMemory(Pack, *output, outlen, PackedFilename$)
             EndIf   
          EndIf 
          FreeMemory(*input)
          FreeMemory(*output)
       EndIf   
      CloseFile(fn) 
   EndIf
   
   ProcedureReturn Result 
   
EndProcedure    

UseZipPacker()

Define file.s,packfile.s,extn.s,pack.i
file = OpenFileRequester("Choosefile","","*.*",1) 
extn = GetExtensionPart(file)
packfile = Left(file,Len(file)-Len(extn)) + "zip"
pack = CreatePack(#PB_Any,packfile,#PB_PackerPlugin_Zip )  
AddPackFile2(pack,file,packfile,9)
ClosePack(pack) 


Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Packer compression level?

Post by ts-soft »

To store, without compressing, you can use this:

Code: Select all

EnableExplicit

UseZipPacker()

Import ""
  PB_Object_IsObject(object, id)
  PB_Packer_Objects
EndImport

#ZIP_CM_DEFAULT   = -1
#ZIP_CM_STORE     = 0

ImportC ""
  zip_set_file_compression(hZip.i, index.q, comp.l, comp_flags.l = 0)
EndImport

Procedure PackerID(id)
  Protected obj, hZip
  obj = PB_Object_IsObject(PB_Packer_Objects, id) 
  If obj
    hZip = PeekI(PeekI(obj + SizeOf(Integer)))
  EndIf
  ProcedureReturn hZip 
EndProcedure

If CreatePack(1, GetTemporaryDirectory() + "test.zip")
  AddPackFile(1, #PB_Compiler_Home + "SDK\Readme.txt", "Readme.txt")
  zip_set_file_compression(PackerID(1), 0, #ZIP_CM_STORE)
  ClosePack(1)
EndIf
Windows x86, x64 and Linux x64 only.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
ergrull0
User
User
Posts: 23
Joined: Sat Mar 08, 2014 4:45 pm

Re: Packer compression level?

Post by ergrull0 »

ts-soft wrote:To store, without compressing, you can use this:

Code: Select all

EnableExplicit

UseZipPacker()

Import ""
  PB_Object_IsObject(object, id)
  PB_Packer_Objects
EndImport

#ZIP_CM_DEFAULT   = -1
#ZIP_CM_STORE     = 0

ImportC ""
  zip_set_file_compression(hZip.i, index.q, comp.l, comp_flags.l = 0)
EndImport

Procedure PackerID(id)
  Protected obj, hZip
  obj = PB_Object_IsObject(PB_Packer_Objects, id) 
  If obj
    hZip = PeekI(PeekI(obj + SizeOf(Integer)))
  EndIf
  ProcedureReturn hZip 
EndProcedure

If CreatePack(1, GetTemporaryDirectory() + "test.zip")
  AddPackFile(1, #PB_Compiler_Home + "SDK\Readme.txt", "Readme.txt")
  zip_set_file_compression(PackerID(1), 0, #ZIP_CM_STORE)
  ClosePack(1)
EndIf
Windows x86, x64 and Linux x64 only.
Thanks! Just what I needed. It's working also on snow leopard btw
Post Reply