Project

General

Profile

Bwrite » History » Version 6

Per Amundsen, 02/06/2019 08:28 PM

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
-t - Treat <text|%var|&binvar> as plain text.
10 5 Per Amundsen
-a - Disables UTF-8 encoding of characters in the range 0-255, as long as the text contains no characters > 255.
11 4 Per Amundsen
-c - Chops the file at the end of the copied bytes.
12 1 Per Amundsen
13
*Parameters*
14
15
<filename> - File to modify.
16 6 Per Amundsen
<S> - Byte position in the file to start writing to. (zero based)
17 1 Per Amundsen
[N] - Byte count from <text|%var|&binvar> to write.
18 2 Per Amundsen
<text|%var|&binvar> - Text/%variable/&binvar to write to file.
19 1 Per Amundsen
20
*Example*
21
22
<pre>
23
alias example {
24
  ;Write some text to a file at beginning of the file
25
  /bwrite file.txt 0 hello there!
26
27
  ;Read the binary data into binary variable &tempfile
28
  /bread $qt(file.txt) 0 $file(file.txt).size &tempfile
29
30
  ;Print the binary variable data as text, outputs 'Hello there!'
31
  echo -ag $bvar(&tempfile, 1-).text
32
  
33
  ;Replace "there!" with "world!"
34
  /bwrite file.txt 6 world!
35
36
  ;Read the binary data into binary variable &tempfile
37
  /bread $qt(file.txt) 0 $file(file.txt).size &tempfile
38
39
  ;Print the binary variable data as text, outputs 'Hello world!'
40
  echo -ag $bvar(&tempfile, 1-).text
41
}
42
</pre>