Announcement

Collapse
No announcement yet.

Looking for a PB compression or Zip program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looking for a PB compression or Zip program

    I'm looking for a PB compression program which can zip or compress some
    data. Can someone help on this?

    I did a search in PB forums and found zlib but the code is old and cannot run
    with the latest zlib-128.dll

    the link is here :
    https://www.powerbasic.com/support/p...t=28376&page=2

  • #2
    7zip

    I had a requirement to compress a whole folder and its structure and the easy way (windows permissions permitting) is to use 7zip.

    I ShellEx the command line version of 7zip to produce a zip file but it is also possible to produce other formats.

    Comment


    • #3
      7zip is a bit odd, and I might recommend GZIP instead, if you're planning to SHELL out to a program. It's free and unencumbered, although the command-line syntax may take getting used to. It can handle disturbingly large files with no qualms, however.

      Comment


      • #4
        Compression Code Compared

        All code I got here.

        Comment


        • #5
          This works with zlib123.dll/SQLiteningZlib.dll
          You might check Jose Roca site or here to see if he has a more recent solution.
          I do not want to break SQLitening so use this.

          Code:
          http://www.dotysoftware.com/zlib123.zip  500,000,000 byte limit
          
          DECLARE FUNCTION ZlibCompress LIB "zlib123.dll" ALIAS "compress" _
             (compr AS ANY, comprLen AS DWORD, buf AS ANY, BYVAL buflen AS DWORD)AS LONG
          
          DECLARE FUNCTION ZlibUncompress LIB "zlib123.dll" ALIAS "uncompress" _
          (uncompr AS ANY, uncomprLen AS DWORD, compr AS ANY, BYVAL lcompr AS DWORD)AS LONG
          
          FUNCTION PBMAIN AS LONG 'zlibonly.bas 
            ? Uncompress(compress("simple"))
          END FUNCTION
          
          FUNCTION compress (rsTextIn AS STRING) AS STRING
             LOCAL wsTextOut AS STRING, llDo AS LONG,lspIn,lspOut AS STRING PTR
             lspIn = VARPTR(rsTextIn):lspOut = VARPTR(wsTextOut)
             @lspOut = SPACE$(LEN(@lspIn) * 1.2 + 12)
             llDo = LEN(@lspOut)
             ZlibCompress BYVAL STRPTR(@lspOut), llDo, BYVAL STRPTR(@lspIn), LEN(@lspIn)
             @lspOut = MKDWD$(LEN(@lspIn)) & LEFT$(@lspOut, llDo)
             FUNCTION = @lspOut
          END FUNCTION
          
          FUNCTION uncompress(rsTextIn AS STRING) AS STRING
             LOCAL wsTextOut AS STRING, lspIn,lspOut AS STRING PTR
             lspIn = VARPTR(rsTextIn)
             lspOut = VARPTR(wsTextOut)
             @lspOut = SPACE$(CVDWD(@lspIn))
             ZLibUncompress BYVAL STRPTR(@lspOut),LEN(@lspOut),BYVAL STRPTR(@lspIn)+4,LEN(@lspIn)-4
             FUNCTION [email protected]
          END FUNCTION
          https://duckduckgo.com instead of google

          Comment


          • #6
            Thanks so much, Mike

            I have tested your code with several file types and it works very well

            Comment


            • #7
              Compress/Uncompress files using same code

              http://www.dotysoftware.com/zlib123.zip '500,000,000 byte limit
              Code:
              DECLARE FUNCTION ZlibCompress LIB "zlib123.dll" ALIAS "compress" _
                 (compr AS ANY, comprLen AS DWORD, buf AS ANY, BYVAL buflen AS DWORD)AS LONG
               
              DECLARE FUNCTION ZlibUncompress LIB "zlib123.dll" ALIAS "uncompress" _
              (uncompr AS ANY, uncomprLen AS DWORD, compr AS ANY, BYVAL lcompr AS DWORD)AS LONG
              
              FUNCTION PBMAIN AS LONG
               
                LOCAL result AS LONG, s,sCompress,sUncompress,sInFile,sOutFile AS STRING
              
                sInFile  = "InFile.Txt"
                sOutFile = "OutFile.Txt"
              
                'create test file
                OPEN sInFile FOR OUTPUT AS #1
                s = REPEAT$(1000,"This is the data to compress" + $CR)
                PRINT #1, s;
                CLOSE #1
              
                'compress InFile to OutFile
                result = CompressFile(sInFile,sOutFile)
                IF result THEN ? ERROR$(result),,"CompressFile":EXIT FUNCTION
              
                'read outfile into a string named sCompress$
                result = FileToString(sOutFile,sCompress$)
                IF result THEN ? ERROR$(result),,"FileToString":EXIT FUNCTION
              
                'view the string
                 sUncompress$ = UnCompressString(sCompress$)
                 ? sInFile + USING$(" (#, bytes)",LEN(sUnCompress$)) + $CR +_
                  sOutFile+ USING$(" (#, bytes)",LEN(sCompress$))   + $CR +_
                  USING$("#%",(LEN(sUnCompress)/LEN(sCompress)*100))                                
               
              END FUNCTION
              
              FUNCTION CompressString (rsTextIn AS STRING) AS STRING
                 LOCAL wsTextOut AS STRING, llDo AS LONG,lspIn,lspOut AS STRING PTR
                 lspIn = VARPTR(rsTextIn):lspOut = VARPTR(wsTextOut)
                 @lspOut = SPACE$(LEN(@lspIn) * 1.2 + 12)
                 llDo = LEN(@lspOut)
                 ZlibCompress BYVAL STRPTR(@lspOut), llDo, BYVAL STRPTR(@lspIn), LEN(@lspIn)
                 FUNCTION = MKDWD$(LEN(@lspIn)) & LEFT$(@lspOut, llDo)
              END FUNCTION
              
              FUNCTION UnCompressString(rsTextIn AS STRING) AS STRING
                 LOCAL wsTextOut AS STRING, lspIn,lspOut AS STRING PTR
                 lspIn = VARPTR(rsTextIn):lspOut = VARPTR(wsTextOut)
                 @lspOut = SPACE$(CVDWD(@lspIn))
                 ZLibUncompress BYVAL STRPTR(@lspOut),LEN(@lspOut),BYVAL STRPTR(@lspIn)+4,LEN(@lspIn)-4
                 FUNCTION [email protected]
              END FUNCTION
              
              FUNCTION CompressFile(sInputFile AS STRING, sOutputFile AS STRING) AS LONG
                 LOCAL sData AS STRING, hFile, result AS LONG
                 result = FileToString(sInputFile,sData)         'input file to string
                IF result THEN FUNCTION = result:EXIT FUNCTION  'if any error then exit
                 IF ISFILE(sOutputFile) THEN  'need new output file
                  KILL sOutputFile
                  IF ERR THEN
                    FUNCTION = ERR
                    EXIT FUNCTION
                  END IF
                END IF
                sData = CompressString(sData)
                hFile = FREEFILE
                OPEN sOutputFile FOR BINARY AS #hFile
                IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
                IF LEN(sData) THEN PUT$ #hFile,sData
                IF ERR THEN FUNCTION = ERR
                CLOSE #hFile
              END FUNCTION
              
              FUNCTION FileToString(sInputFile AS STRING,sData AS STRING) AS LONG
                LOCAL hFile,FileLen AS LONG 'return 0 on success
                IF ISFALSE(ISFILE(sInputFile)) THEN FUNCTION = 53:EXIT FUNCTION
                hFile = FREEFILE
                OPEN sInputFile FOR BINARY AS #hFile
                IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
                FileLen = LOF(#hFile)
                IF FileLen = 0 THEN
                  FUNCTION = -99
                ELSE
                  GET$ #hFile,FileLen,sData
                  FUNCTION = ERR
                END IF
                CLOSE #hFile
              END FUNCTION
              Last edited by Mike Doty; 22 Jan 2016, 01:48 AM.
              https://duckduckgo.com instead of google

              Comment


              • #8
                Please indicate where it ends or give error message. I can unzip any file type.
                https://duckduckgo.com instead of google

                Comment

                Working...
                X