Core Function BinarySave
From Sputnik Wiki
(Difference between revisions)
m (1 revision) |
|||
(2 intermediate revisions by one user not shown) | |||
Line 47: | Line 47: | ||
; Example with compression | ; Example with compression | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $binary = Pack(" | + | $binary = Pack("A*", "Hello World!\n" x 1_000); |
BinarySave($binary, "test.txt", 1); | BinarySave($binary, "test.txt", 1); | ||
$binaryLoaded = BinaryLoad("test.txt", 1); | $binaryLoaded = BinaryLoad("test.txt", 1); | ||
− | println( Unpack(" | + | 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