Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Memo compression
Message
From
21/08/2002 08:41:14
 
 
To
21/08/2002 06:25:40
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00691823
Message ID:
00691867
Views:
25
>Hello all,
>
>I am seeking tips and/or sample code on how to use a compression add-on .DLL such as DynaZip or Xceed to compress the contents of a memo field. I can perform this task by using STRTOFILE(memo_field,lcfile), ZIPping the file, and then using FILETOSTR() to copy the file contents to the memo field. But, I would like to implement a more elegent and speedy solution that does not write to disk. The app would be reading the memo from one table and writing the compressed memo to another.
>
>BTW, I would like to use a DLL interface to avoid having to register the components on client PCs (the client views the registry as sacred ground...).
>
>Thanks.
>
>Dana Daugherty
>CNS, Inc.
>Morristown, TN USA

Dana,

Have you looked at zlib ? That is the FlateDecode used by acrobat for Deflating streams.

binaries: http://prdownloads.sourceforge.net/gnuwin32/zlib-1.1.4-bin.zip?download
doc: http://prdownloads.sourceforge.net/gnuwin32/zlib-1.1.4-doc.zip?download

All you need is the zlib.dll

I now see that the latest zlib.dll is 63k, whereas mine is 52k. In case you have trouble let me know

With the code below I have successfully inflated and deflated acrobat streams


With a bit of luck you have it working in under an hour
Success

Sample
&& once
local Destination
Destination = ('.\zlib.dll')


declare integer compress in (Destination) ;
	string @Dest, integer @DestLen, ;
	string @Source, integer SourceLen

declare integer compress2 in (Destination) ;
	string @Dest, integer @DestLen, ;
	string @Source, integer SourceLen, integer CompressionLevel
	
declare integer uncompress in (Destination) ;
	string @Dest, integer @DestLen, ;
	string @Source, integer SourceLen
&& some sample code I took from a class of mine

*--------------------------------------------------------
&& call with (src, @dest)

hidden function FlateDecode_Decode(Src, Dest)
	
	local DestLen, SrcLen, sts
        && you must allocate the max possible uncompressed length if you do not know the uncompressed length
        && if you do know the uncompressed length (stored it somewhere), then alloc that space

	Dest	= repl(chr(0), 1024*1024) 
	DestLen	= len(Dest)
	SrcLen	= len(Src)
	
	sts =  uncompress(@Dest, @DestLen, @Src, SrcLen)
	
	do case
	case sts >= 0
		Dest = left(Dest, DestLen)
		return (sts == 0)
	otherwise
		Dest = ''
		return FALSE
	endcase

endfunc
*--------------------------------------------------------
#define	Z_NO_COMPRESSION		0
#define	Z_BEST_SPEED			1
#define	Z_BEST_COMPRESSION		9
#define	Z_DEFAULT_COMPRESSION	(-1)

&& call with (src, @dest)

hidden function FlateDecode_Encode(Src, Dest)
		
	local DestLen, SrcLen, sts
	
	SrcLen	= len(Src)
	DestLen	= ceiling(len(Src) + 1.01 + 12)
	Dest	= repl(chr(0), DestLen)
	
	
	sts =  compress2(@Dest, @DestLen, @Src, SrcLen, Z_BEST_COMPRESSION)
	
	do case
	case sts >= 0
		Dest = left(Dest, DestLen)
		return (sts == 0)
	otherwise
		Dest = ''
		return FALSE
	endcase

endfunc
*---------------------------------------------------------------------------
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform