Core Function BinaryLoad

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "<pre> BinaryLoad( <file> ) </pre> === Description === Create a new binary variable by loading binary data from a file. === Parameters === ==== file ==== Name of file to load...")
 
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
BinaryLoad( <file> )
+
BinaryLoad( <file>, <flag> )
 
</pre>
 
</pre>
  
Line 12: Line 12:
  
 
Name of file to load.
 
Name of file to load.
 +
 +
==== flag ====
 +
 +
Optional; Compression flag.
 +
 +
0 = The file is not compressed
 +
 +
1 = The file is compressed (This must be a specific compression like the one produced by using BinarySave)
  
 
=== Return Value ===
 
=== Return Value ===
Line 17: Line 25:
 
Success: Returns the new binary variable.
 
Success: Returns the new binary variable.
  
Failure: Returns 0.
+
Failure: Returns null.
  
 
=== Remarks ===
 
=== Remarks ===
Line 26: Line 34:
  
 
<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 21:53, 26 June 2015

BinaryLoad( <file>, <flag> )

Contents

Description

Create a new binary variable by loading binary data from a file.

Parameters

file

Name of file to load.

flag

Optional; Compression flag.

0 = The file is not compressed

1 = The file is compressed (This must be a specific compression like the one produced by using BinarySave)

Return Value

Success: Returns the new binary variable.

Failure: Returns null.

Remarks

This will even accurately load exe files so they can be saved again without damage.

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