Bread » History » Version 8
Per Amundsen, 02/15/2023 11:08 AM
| 1 | 1 | Per Amundsen | _Added in 1.9.0_ |
|---|---|---|---|
| 2 | |||
| 3 | 6 | Per Amundsen | */bread [-ta] <filename> <S> <N> <&binvar>* |
| 4 | 1 | Per Amundsen | |
| 5 | Reads <N> bytes starting at byte position <S> in the file and stores the result in &binvar. |
||
| 6 | |||
| 7 | *Switches* |
||
| 8 | |||
| 9 | 8 | Per Amundsen | table(ktable). |
| 10 | |*Switch*|*Description*| |
||
| 11 | | -t | reads data until the next [[$crlf]] or [[$feof]]. | |
||
| 12 | | -a | Disables UTF-8 encoding of characters in the range 0-255, as long as the line contains no characters > 255. | |
||
| 13 | 1 | Per Amundsen | |
| 14 | *Parameters* |
||
| 15 | |||
| 16 | 8 | Per Amundsen | table(ktable). |
| 17 | |*Parameter*|*Description*| |
||
| 18 | | <filename> | The binary file to read. | |
||
| 19 | | <S> | The byte position in the file to start reading from. | |
||
| 20 | | <N> | Number of bytes to read. | |
||
| 21 | | <&binvar> | The &binvar to read the data into. | |
||
| 22 | 1 | Per Amundsen | |
| 23 | *Example* |
||
| 24 | |||
| 25 | 2 | Per Amundsen | <pre> |
| 26 | 1 | Per Amundsen | ;noop $example(FileA, FileB) |
| 27 | alias example { |
||
| 28 | ;Read the whole file into a binary variable |
||
| 29 | bread $qt($1) 0 $file($1).size &tempFile |
||
| 30 | |||
| 31 | ;Write the bytes form the binary variable to a file |
||
| 32 | bwrite $qt($2) 0 -1 &tempFile |
||
| 33 | } |
||
| 34 | 2 | Per Amundsen | </pre> |