Core Function BinarySave
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> BinarySave( <binary-array>, <file> ) </pre> === Description === Save a binary variable data to file. === Parameters === ==== <binary-array> ==== The binary variable yo...") |
|||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | BinarySave( <binary-array>, <file> ) | + | BinarySave( <binary-array>, <file>, <flag> ) |
</pre> | </pre> | ||
Line 16: | Line 16: | ||
Name of file to save (Will create if it doesnt exist). | 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 === | === 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 === | ||
Line 33: | Line 43: | ||
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("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 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 10:07, 12 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