Core Function BinaryCompress

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> BinaryCompress( <binary-array> ) </pre> === Description === Compress a binary variables data. === Parameters === ==== binary-array ==== The binary variable to compress...")
 
(Example)
Line 28: Line 28:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary = Pack("z0", ("Hello World!\n" x 1000))
+
$binary = Pack("z0", "Hello World!\n" x 1000);
println("Size uncompressed : " . BinaryLen($binary))
+
println("Size uncompressed : " . BinaryLen($binary));
BinaryCompress($binary)
+
BinaryCompress($binary);
println("Size compressed : " . BinaryLen($binary))
+
println("Size compressed : " . BinaryLen($binary));
BinaryUncompress($binary)
+
BinaryUncompress($binary);
println("Size uncompressed (again) : " . BinaryLen($binary))
+
println("Size uncompressed (again) : " . BinaryLen($binary));
inputC("\nPress any key to see whats inside the binary variable after compress and decompress")
+
inputC("\nPress any key to see whats inside the binary variable after compress and decompress");
println( Unpack("z0", $binary) ) ; Prints "Hello World!" 1000 times
+
println( Unpack("z0", $binary) ); // Prints "Hello World!" 1000 times
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 18:15, 19 November 2011

BinaryCompress( <binary-array> )

Contents

Description

Compress a binary variables data.

Parameters

binary-array

The binary variable to compress.

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

This uses a standard gzip memory stream compression.

This function can greatly reduce the size of binary data however its best used on large amounts of data since its effectiveness is limited on small data.

Example

$binary = Pack("z0", "Hello World!\n" x 1000);
println("Size uncompressed : " . BinaryLen($binary));
BinaryCompress($binary);
println("Size compressed : " . BinaryLen($binary));
BinaryUncompress($binary);
println("Size uncompressed (again) : " . BinaryLen($binary));
inputC("\nPress any key to see whats inside the binary variable after compress and decompress");
println( Unpack("z0", $binary) ); // Prints "Hello World!" 1000 times
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox