Project

General

Profile

Actions

Bwrite » History » Revision 5

« Previous | Revision 5/7 (diff) | Next »
Per Amundsen, 11/02/2018 03:45 AM


Added in 1.9.0

/bwrite [-tac] <filename> <S> [N] <text|%var|&binvar>

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.

Switches

-t - Treat <text|%var|&binvar> as plain text.
-a - Disables UTF-8 encoding of characters in the range 0-255, as long as the text contains no characters > 255.
-c - Chops the file at the end of the copied bytes.

Parameters

<filename> - File to modify.
<S> - Byte position in the file to start writing to.
[N] - Byte count from <text|%var|&binvar> to write.
<text|%var|&binvar> - Text/%variable/&binvar to write to file.

Example

alias example {
  ;Write some text to a file at beginning of the file
  /bwrite file.txt 0 hello there!

  ;Read the binary data into binary variable &tempfile
  /bread $qt(file.txt) 0 $file(file.txt).size &tempfile

  ;Print the binary variable data as text, outputs 'Hello there!'
  echo -ag $bvar(&tempfile, 1-).text

  ;Replace "there!" with "world!" 
  /bwrite file.txt 6 world!

  ;Read the binary data into binary variable &tempfile
  /bread $qt(file.txt) 0 $file(file.txt).size &tempfile

  ;Print the binary variable data as text, outputs 'Hello world!'
  echo -ag $bvar(&tempfile, 1-).text
}

Updated by Per Amundsen over 5 years ago · 5 revisions

Also available in: PDF HTML TXT