Core Function BinarySave

From Sputnik Wiki
Jump to: navigation, search
BinarySave( <binary-array>, <file>, <flag> )

Contents

Description

Save a binary variable data to file.

Parameters

<binary-array>

The binary variable you want saving to file.

file

Name of file to save (Will create if it doesn't exist).

flag

Optional; Compression flag.

0 = Do not compress the file

1 = Compress the file (This will create a gzip stream then use the first 4 bytes to write the size of the binary variable array then it will write all the bytes of the array; You can load the file back into a binary variable by using BinaryLoad command with compression switch on)

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

This will even accurately save exe files without damage so they can run.

Warning - If you use compression on a loaded exe file the newly made exe will not run.

Example

$binary = BinaryLoad("Sputnik.exe");
println("Size is : " . BinaryLen($binary) );
BinarySave($binary, "SputnikTest.exe");
Example with compression
$binary = Pack("A*", "Hello World!\n" x 1_000);
BinarySave($binary, "test.txt", 1);
$binaryLoaded = BinaryLoad("test.txt", 1);
println( Unpack("A*", $binaryLoaded, 3) ); // Prints "Hello World!" 1000 times
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox