Difference between revisions of "Bread"

From Scriptwiki
Jump to: navigation, search
m
Line 1: Line 1:
The bread command is used to read content from a file in to a [[binary file|Binary Files]]
+
The bread command is used to read content from a file in to a [[Binary Files|binary file]].
 
  <nowiki>bread [-t] <filename> <S> <N> <&binvar></nowiki>
 
  <nowiki>bread [-t] <filename> <S> <N> <&binvar></nowiki>
 
This reads N bytes starting at the Sth byte position in the file and stores the result in the binary variable &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.
 
The -t switch reads data up to the next CR/LF.

Revision as of 16:45, 23 July 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 posistion 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.