FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Packing zip in memory
Posts: 392
Joined: Tue Jul 29, 2008 01:55 PM
Packing zip in memory
Posted: Wed Oct 18, 2017 08:45 AM

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

Visite Chiapas, el paraiso de México.
Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: Packing zip in memory
Posted: Tue Oct 24, 2017 02:29 PM
Hi,

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

Code (fw): Select all Collapse
// 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

Continue the discussion