Page 1 of 1

Packing zip in memory

Posted: Wed Oct 18, 2017 8:45 am
by devtuxtla
Hi FiveWinners

Is there a library that packs in zip format the contents of a vriable in memory?
That is, it does not generate any files to disk in the process of unpacking and unpacking? and that the method returns the packaged variable ...
Anyone know the trick?

Regards

Re: Packing zip in memory

Posted: Tue Oct 24, 2017 2:29 pm
by RAMESHBABU
Hi,

If you are using xHarbour, The following code is from xHarbour Help. May be it is useful to you.

Code: Select all

// The example implements two functions for easiest (un)compression
// since the buffer size required for uncompression is stored in
// the compressed string using HB_CreateLen8().

   PROCEDURE Main
      LOCAL cText := MemoRead( "LargeFile.txt" )
      LOCAL cCompressed, cUncompressed

      cCompressed   := ZipCompress( cText )

      cUnCompressed := ZipUncompress( cCompressed )

      ? "Original    :", Len( cText )
      ? "Compressed  :", Len( cCompressed )
      ? "Uncompressed:", Len( cUncompressed )
      ? cUncompressed == cText
   RETURN


   // The function adds 8 bytes holding the length of the original
   // character string to the compressed string
   FUNCTION ZipCompress( cString )
      LOCAL cCompressed := HB_Compress( cString )

   RETURN HB_CreateLen8( Len( cString ) ) + cCompressed


   // The function extracts the first 8 bytes holding the length
   // of the uncompressed character string from the compressed string
   FUNCTION ZipUncompress( cCompressed )
      LOCAL nBytes := HB_GetLen8( cCompressed )

   RETURN HB_Uncompress( nBytes, SubStr( cCompressed, 9 ) )

 
-Ramesh Babu P