Packing zip in memory

Post Reply
devtuxtla
Posts: 392
Joined: Tue Jul 29, 2008 1:55 pm

Packing zip in memory

Post 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
Visite Chiapas, el paraiso de México.
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Packing zip in memory

Post 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
Post Reply