Bwrite » History » Version 7
Per Amundsen, 02/15/2023 11:15 AM
1 | 1 | Per Amundsen | _Added in 1.9.0_ |
---|---|---|---|
2 | |||
3 | 4 | Per Amundsen | */bwrite [-tac] <filename> <S> [N] <text|%var|&binvar>* |
4 | 1 | Per Amundsen | |
5 | Writes [N] bytes from <text|%var|&binvar> to the file starting at byte position <S> or 0, any existing information at this position is overwritten. |
||
6 | |||
7 | *Switches* |
||
8 | |||
9 | 7 | Per Amundsen | table(ktable). |
10 | |*Switch*|*Description*| |
||
11 | | -t | <notextile>Treat <text|%var|&binvar> as plain text.</notextile> | |
||
12 | | -a | Disables UTF-8 encoding of characters in the range 0-255, as long as the text contains no characters > 255. | |
||
13 | | -c | Chops the file at the end of the copied bytes. | |
||
14 | 1 | Per Amundsen | |
15 | *Parameters* |
||
16 | |||
17 | 7 | Per Amundsen | table(ktable). |
18 | |*Parameter*|*Description*| |
||
19 | | <filename> | File to modify. | |
||
20 | | <S> | Byte position in the file to start writing to. (zero based) | |
||
21 | | [N] | <notextile>Byte count from <text|%var|&binvar> to write.</notextile> | |
||
22 | | <notextile><text|%var|&binvar></notextile> | Text/%variable/&binvar to write to file. | |
||
23 | 1 | Per Amundsen | |
24 | *Example* |
||
25 | |||
26 | <pre> |
||
27 | alias example { |
||
28 | ;Write some text to a file at beginning of the file |
||
29 | /bwrite file.txt 0 hello there! |
||
30 | |||
31 | ;Read the binary data into binary variable &tempfile |
||
32 | /bread $qt(file.txt) 0 $file(file.txt).size &tempfile |
||
33 | |||
34 | ;Print the binary variable data as text, outputs 'Hello there!' |
||
35 | echo -ag $bvar(&tempfile, 1-).text |
||
36 | |||
37 | ;Replace "there!" with "world!" |
||
38 | /bwrite file.txt 6 world! |
||
39 | |||
40 | ;Read the binary data into binary variable &tempfile |
||
41 | /bread $qt(file.txt) 0 $file(file.txt).size &tempfile |
||
42 | |||
43 | ;Print the binary variable data as text, outputs 'Hello world!' |
||
44 | echo -ag $bvar(&tempfile, 1-).text |
||
45 | } |
||
46 | </pre> |