From WikiChip
Difference between revisions of "mirc/commands/bread"
m (Bot: Adding a template) |
(→Switches) |
||
(15 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{mirc title|/bread Command}} | ||
The '''/bread command''' can be used to read a certain amount of bytes from a file at a given position and store it in a binary variable. | The '''/bread command''' can be used to read a certain amount of bytes from a file at a given position and store it in a binary variable. | ||
− | + | '''Note''': the beginning of the file is position 0. | |
== Synopsis == | == Synopsis == | ||
− | /bread - | + | /bread -ta <filename> <bytepos> <numbytes> <&bvar> |
== Switches == | == Switches == | ||
− | * '''-t''' - Reads data | + | * '''-t''' - Reads data preceding the first encountered line ending or EOF, interpreting as UTF8 text |
+ | * '''-a''' - Modifier for -t switch, codepoints 128-255 are not encoded to UTF8 if no codepoint above 255 is found | ||
== Parameters == | == Parameters == | ||
− | * '''<filename>''' - The file name to read from. | + | * '''<filename>''' - The file name to read from. Double quotes needed if string contains space |
− | * '''<bytepos>''' - The starting byte position. | + | * '''<bytepos>''' - The starting byte position, '''remember, this starts at 0, not 1'''. |
* '''<numbytes>''' - The length (bytes) to be read. | * '''<numbytes>''' - The length (bytes) to be read. | ||
− | * '''<&bvar>''' - The binary variable to store the data in. | + | * '''<&bvar>''' - The binary variable to store the data in. If &binvar already exists, contents are replaced. |
== Example == | == Example == | ||
− | < | + | <source lang="mIRC">;noop $copyExample(FileA,FileB) |
alias copyExample { | alias copyExample { | ||
;Read the whole file into a binary variable | ;Read the whole file into a binary variable | ||
Line 23: | Line 25: | ||
;Write the bytes form the binary variable to a file | ;Write the bytes form the binary variable to a file | ||
bwrite $qt($2) 0 -1 &tempFile | bwrite $qt($2) 0 -1 &tempFile | ||
− | }</ | + | }</source> |
− | = | + | <source lang="mIRC"> |
− | + | Using -t switch: | |
+ | Line ending is defined as data preceding | ||
+ | |||
+ | //bset &v 1 233 | bwrite -c test.dat 0 &v | bread test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) | ||
+ | result: 233 because no switch used | ||
+ | |||
+ | //bset &v 1 233 | bwrite -c test.dat 0 &v | bread -t test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) | ||
+ | result: 195 169 because -t used without -a interprets as UTF8 encoding of codepoint 233 | ||
+ | |||
+ | //bset &v 1 233 | bwrite -c test.dat 0 &v | bread -ta test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) | ||
+ | result: 233 because -ta used AND data read doesn't contain codepoint 256+ | ||
− | + | //bset &v 1 226 156 148 233 | bwrite -c test.dat 0 &v | bread -ta test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) | |
+ | result: 226 156 148 195 169 because data read contains codepoint 10004 | ||
+ | * If bread's offset changed from 0 to 3, result is 233 because the read portion of the line doesn't contain the codepoint above 255 | ||
+ | </source> | ||
− | < | + | <source lang="mIRC">//bread $qt($mircexe) 0 $file($mircexe).size &v | echo -a $md5(&v,1) is the same as $md5($mircexe,2) if enough memory available for binvar</source> |
+ | == Compatibility == | ||
+ | {{mIRC compatibility|5.3}} | ||
== See also == | == See also == | ||
− | * | + | * {{mIRC|$file}} |
− | * | + | * {{mIRC|/bcopy}} |
− | * | + | * {{mIRC|/breplace}} |
− | * | + | * {{mIRC|/bset}} |
− | * | + | * {{mIRC|/btrunc}} |
− | * | + | * {{mIRC|/bunset}} |
− | {{mIRC | + | * {{mIRC|/bwrite}} |
− | + | * {{mIRC|$bvar}} | |
− | + | * {{mIRC|$bfind}} |
Latest revision as of 21:53, 16 August 2022
Commands & Identifiers
Basics
Events
Matching Tools
Data Storage
Control Structures
GUI Scripting
Sockets
Advanced Scripting
Additional Resources
Security
Other
The /bread command can be used to read a certain amount of bytes from a file at a given position and store it in a binary variable.
Note: the beginning of the file is position 0.
Synopsis[edit]
/bread -ta <filename> <bytepos> <numbytes> <&bvar>
Switches[edit]
- -t - Reads data preceding the first encountered line ending or EOF, interpreting as UTF8 text
- -a - Modifier for -t switch, codepoints 128-255 are not encoded to UTF8 if no codepoint above 255 is found
Parameters[edit]
- <filename> - The file name to read from. Double quotes needed if string contains space
- <bytepos> - The starting byte position, remember, this starts at 0, not 1.
- <numbytes> - The length (bytes) to be read.
- <&bvar> - The binary variable to store the data in. If &binvar already exists, contents are replaced.
Example[edit]
;noop $copyExample(FileA,FileB) alias copyExample { ;Read the whole file into a binary variable bread $qt($1) 0 $file($1).size &tempFile ;Write the bytes form the binary variable to a file bwrite $qt($2) 0 -1 &tempFile }
Using -t switch: Line ending is defined as data preceding //bset &v 1 233 | bwrite -c test.dat 0 &v | bread test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) result: 233 because no switch used //bset &v 1 233 | bwrite -c test.dat 0 &v | bread -t test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) result: 195 169 because -t used without -a interprets as UTF8 encoding of codepoint 233 //bset &v 1 233 | bwrite -c test.dat 0 &v | bread -ta test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) result: 233 because -ta used AND data read doesn't contain codepoint 256+ //bset &v 1 226 156 148 233 | bwrite -c test.dat 0 &v | bread -ta test.dat 0 9 &v2 | echo -a $bvar(&v2,1-) result: 226 156 148 195 169 because data read contains codepoint 10004 * If bread's offset changed from 0 to 3, result is 233 because the read portion of the line doesn't contain the codepoint above 255
//bread $qt($mircexe) 0 $file($mircexe).size &v | echo -a $md5(&v,1) is the same as $md5($mircexe,2) if enough memory available for binvar
Compatibility[edit]
Added: mIRC v5.3
Added on: 13 Dec 1997
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.