Core Function BinarySave

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> BinarySave( <binary-array>, <file> ) </pre> === Description === Save a binary variable data to file. === Parameters === ==== <binary-array> ==== The binary variable yo...")
 
m (1 revision)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
BinarySave( <binary-array>, <file> )
+
BinarySave( <binary-array>, <file>, <flag> )
 
</pre>
 
</pre>
  
Line 15: Line 15:
 
==== file ====
 
==== file ====
  
Name of file to save (Will create if it doesnt exist).
+
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 ===
 
=== Return Value ===
Line 26: Line 34:
  
 
This will even accurately save exe files without damage so they can run.
 
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 ===
 
=== Example ===
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$binary = BinaryLoad("Sputnik.exe")
+
$binary = BinaryLoad("Sputnik.exe");
println("Size is : " . BinaryLen($binary) )
+
println("Size is : " . BinaryLen($binary) );
BinarySave($binary, "SputnikTest.exe")
+
BinarySave($binary, "SputnikTest.exe");
 +
</syntaxhighlight>
 +
 
 +
; Example with compression
 +
<syntaxhighlight lang="sputnik">
 +
$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
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Latest revision as of 12:38, 14 June 2015

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