Difference between revisions of "Bread"

From Scriptwiki
Jump to: navigation, search
(first version, needs better example)
 
m (posistion --> position)
 
(4 intermediate revisions by 4 users not shown)
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 [[:Category: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.
Line 8: 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 posistion is the start of the 3rd line.
+
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)
 
You can view what is in the varible with the following code:
 
You can view what is in the varible with the following code:
  echo -ag $bvar(&binvar,1,100)
+
  echo -ag [[$bvar]](&binvar,1,100)
 
  ''or''
 
  ''or''
 
  echo -ag $bvar(&binvar,1,100).text
 
  echo -ag $bvar(&binvar,1,100).text
Line 18: Line 20:
  
 
== Note ==
 
== Note ==
Note that if you want to read from the start of the file, posistion S is the first character in the file.
+
Note that if you want to read from the start of the file, posistion 0 is the first character in the file.
  
 
[[Category:Binary Files]]
 
[[Category:Binary Files]]
 
[[Category:Commands]]
 
[[Category:Commands]]

Latest revision as of 20: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.