Difference between revisions of "Bread"
m (corrected binary files -link) |
m (posistion --> position) |
||
Line 10: | Line 10: | ||
bread versions.txt 27 100 &binvar | bread versions.txt 27 100 &binvar | ||
This will read in to the binary variable ''&binvar'' from the ''27''th position of ''versions.txt'', the follows ''100'' characters, this will include all [[$crlf]]. | This will read in to the binary variable ''&binvar'' from the ''27''th position of ''versions.txt'', the follows ''100'' characters, this will include all [[$crlf]]. | ||
− | At the time of writing, the 27th | + | At the time of writing, the 27th position is the start of the 3rd line. |
17/02/2006 - mIRC v6.17 '''Line 1''' which is 23 characters | 17/02/2006 - mIRC v6.17 '''Line 1''' which is 23 characters | ||
followed by two $crlf (which is two characters each) | followed by two $crlf (which is two characters each) |
Latest revision as of 19:32, 14 December 2006
The bread command is used to read content from a file in to a binary file.
bread [-t] <filename> <S> <N> <&binvar>
This reads N bytes starting at the Sth byte position in the file and stores the result in the binary variable &binvar.
S is zero-based: the first byte of the file has position 0. To read the whole file, use $file(<filename>).size as value for N.
The -t switch reads data up to the next CR/LF.
Examples
bread versions.txt 27 100 &binvar
This will read in to the binary variable &binvar from the 27th position of versions.txt, the follows 100 characters, this will include all $crlf. At the time of writing, the 27th position is the start of the 3rd line.
17/02/2006 - mIRC v6.17 Line 1 which is 23 characters followed by two $crlf (which is two characters each)
You can view what is in the varible with the following code:
echo -ag $bvar(&binvar,1,100) or echo -ag $bvar(&binvar,1,100).text
The latter will show you the text output as if you was looking at the information in a text editor. The first would show you the each characters ascii code. Looking at the ascii codes can help you see if the line starts with a space or see where new lines are etc.
Note
Note that if you want to read from the start of the file, posistion 0 is the first character in the file.