Core Function BinarySave
From Sputnik Wiki
(Difference between revisions)
(→Example) |
|||
Line 40: | Line 40: | ||
<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> | </syntaxhighlight> | ||
; Example with compression | ; Example with compression | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $binary = Pack("z0", | + | $binary = Pack("z0", "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("z0", $binaryLoaded) ) ; Prints "Hello World!" 1000 times | + | println( Unpack("z0", $binaryLoaded) ); // Prints "Hello World!" 1000 times |
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 18:09, 19 November 2011
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 doesnt 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("z0", "Hello World!\n" x 1_000); BinarySave($binary, "test.txt", 1); $binaryLoaded = BinaryLoad("test.txt", 1); println( Unpack("z0", $binaryLoaded) ); // Prints "Hello World!" 1000 times