Maroonbells (talk | contribs) (Created content for empty page) |
Maroonbells (talk | contribs) (Document v7.51 changes) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{mirc title|$compress Identifier}} | {{mirc title|$compress Identifier}} | ||
The '''$compress''' identifier performs compression of a disk file or binary variable. | The '''$compress''' identifier performs compression of a disk file or binary variable. | ||
+ | |||
== Synopsis == | == Synopsis == | ||
− | <pre>$compress( <filename | BinaryVariable> ,[b][lN] | + | <pre>$compress( <filename | BinaryVariable> ,[b][lN][mN] )</pre> |
== Parameters == | == Parameters == | ||
<span style="display: inline-block; width: 50px;">'''Data'''</span>First parameter can be either a disk file (default) or a Binary Variable<br /> | <span style="display: inline-block; width: 50px;">'''Data'''</span>First parameter can be either a disk file (default) or a Binary Variable<br /> | ||
<span style="display: inline-block; width: 50px;">'''b'''</span>Informs that first parameter should be treated as a Binary Variable instead of filename.<br /> | <span style="display: inline-block; width: 50px;">'''b'''</span>Informs that first parameter should be treated as a Binary Variable instead of filename.<br /> | ||
− | <span style="display: inline-block; width: 50px;">'''lN'''</span>Default compression level is 6 | + | <span style="display: inline-block; width: 50px;">'''lN'''</span>Default compression level is 6 within the range 0-9. lN overrides to use compression level N, where N is integer 0-9. (l0 does not compress, is not the same as the absence of the l switch)<br /> |
+ | <span style="display: inline-block; width: 50px;">'''mN'''</span>Default compression method is 2 (zlib). mN overrides to use compression method N, where N = 1 is raw, N = 2 is zlib (the default), and N = 3 is gzip. (0 uses default m2, invalid 4+ uses m3) | ||
== Example == | == Example == | ||
− | There are patterns that often appear near the beginning, but | + | There are patterns that often appear near the beginning, but from observations, it appears you should not assume beyond: |
+ | |||
+ | m1 raw: No guaranteed signature because the data is 'raw'. (m1l0 is the same as the input data)<br /> | ||
+ | m2 Zlib: The 1st byte is $chr(120) (hex 78) small-x.<br /> | ||
+ | m3 gzip: The 1st 4 bytes in hex are: 1F 8B 08 00<br /> | ||
+ | |||
+ | Reminder that decompress works without being informed of the lN compression level. Files compressed with non-default m1 or m3 will fail without being informed of the compression method used to compress that file. | ||
− | Returns 1 if it compressed the file, or 0 if it did not. It will repeatedly process the same file and return 1, even if the attempt to compress an already compressed file slightly increases the | + | Returns 1 if it compressed the file, or 0 if it did not. It will repeatedly process the same file and return 1, even if the attempt to compress an already compressed file slightly increases the filesize. 0 can indicate there's no-such-file, the file wasn't already compressed, or a failure to decompress corrupted data. |
<pre> | <pre> | ||
//noop | $compress(versions.txt) | echo -a test | //noop | $compress(versions.txt) | echo -a test | ||
− | //bset -t &snip 1 $read($mircini,ntw,* | + | //bset -t &snip 1 $read($mircini,ntw,*16777215*) | echo 4 -a / $bvar(&snip,1-) | $compress(&snip,b) | echo 5 -a \ $bvar(&snip,1-) |
− | //bset -t &snip 1 $read($mircini,ntw,* | + | //bset -t &snip 1 $read($mircini,ntw,*16777215*) | echo 4 -a / $bvar(&snip,1-) | noop $compress(&snip,b) | echo 5 -a \ $bvar(&snip,1-) |
</pre> | </pre> | ||
Line 29: | Line 37: | ||
if (!$isfile($2-)) { echo 5 -a filename does not exist: $2- | return } | if (!$isfile($2-)) { echo 5 -a filename does not exist: $2- | return } | ||
bread $qt($2-) 0 1 &snip | bread $qt($2-) 0 1 &snip | ||
− | if ($bvar(&snip,1) != 120) { var %i $compress($2-) | if (%i == 0) echo 5 -a warning failure to compress $1- } | + | if ($bvar(&snip,1) != 120) { var %i $compress($2-) | if (%i == 0) echo 5 -a warning failure to zlib compress $1- } |
dcc send $1 $2- | dcc send $1 $2- | ||
} | } | ||
Line 36: | Line 44: | ||
'''Note:''' Before making a script which automatically compresses all files before sending them and decompressing them when they finish, you should take several issues into account. | '''Note:''' Before making a script which automatically compresses all files before sending them and decompressing them when they finish, you should take several issues into account. | ||
# You shouldn't automatically decompress or compress files without making certain that the same file isn't also being transferred to/from someone else. | # You shouldn't automatically decompress or compress files without making certain that the same file isn't also being transferred to/from someone else. | ||
− | # Besides {{mIRC|ON FILESENT}}, Transfers can also terminate with {{mIRC|ON SENDFAIL}}, clicking to close the send window, using the /close command with the -s switch, mIRC crashing, etc. | + | # Besides {{mIRC|on events/on filesent|ON FILESENT}}, Transfers can also terminate with {{mIRC|on events/on sendfail|ON SENDFAIL}}, clicking to close the send window, using the {{mIRC|/close}} command with the -s switch, mIRC crashing, etc. |
# To make certain all files get safely decompressed, the script should probably work from a file listing that doesn't remove lines until the file has been determined to be decompressed. | # To make certain all files get safely decompressed, the script should probably work from a file listing that doesn't remove lines until the file has been determined to be decompressed. | ||
+ | # Now that $compress supports gzip compression, a script must first determine which method was used to compress the file in order to successfully decompress the file. | ||
== Compatibility == | == Compatibility == | ||
{{mIRC compatibility|6.1}} | {{mIRC compatibility|6.1}} | ||
+ | version 7.51 expanded lN from 1-6 to 0-9, and introduced mN | ||
== See also == | == See also == | ||
* {{mIRC|$decompress}} | * {{mIRC|$decompress}} | ||
− | [[Category: | + | [[Category:mIRC identifiers|compress]] |
Latest revision as of 13:46, 22 October 2017
The $compress identifier performs compression of a disk file or binary variable.
Synopsis[edit]
$compress( <filename | BinaryVariable> ,[b][lN][mN] )
Parameters[edit]
DataFirst parameter can be either a disk file (default) or a Binary Variable
bInforms that first parameter should be treated as a Binary Variable instead of filename.
lNDefault compression level is 6 within the range 0-9. lN overrides to use compression level N, where N is integer 0-9. (l0 does not compress, is not the same as the absence of the l switch)
mNDefault compression method is 2 (zlib). mN overrides to use compression method N, where N = 1 is raw, N = 2 is zlib (the default), and N = 3 is gzip. (0 uses default m2, invalid 4+ uses m3)
Example[edit]
There are patterns that often appear near the beginning, but from observations, it appears you should not assume beyond:
m1 raw: No guaranteed signature because the data is 'raw'. (m1l0 is the same as the input data)
m2 Zlib: The 1st byte is $chr(120) (hex 78) small-x.
m3 gzip: The 1st 4 bytes in hex are: 1F 8B 08 00
Reminder that decompress works without being informed of the lN compression level. Files compressed with non-default m1 or m3 will fail without being informed of the compression method used to compress that file.
Returns 1 if it compressed the file, or 0 if it did not. It will repeatedly process the same file and return 1, even if the attempt to compress an already compressed file slightly increases the filesize. 0 can indicate there's no-such-file, the file wasn't already compressed, or a failure to decompress corrupted data.
//noop | $compress(versions.txt) | echo -a test //bset -t &snip 1 $read($mircini,ntw,*16777215*) | echo 4 -a / $bvar(&snip,1-) | $compress(&snip,b) | echo 5 -a \ $bvar(&snip,1-) //bset -t &snip 1 $read($mircini,ntw,*16777215*) | echo 4 -a / $bvar(&snip,1-) | noop $compress(&snip,b) | echo 5 -a \ $bvar(&snip,1-)
In the above example, the first 2 lines are incorrect usage, and fail to alter the filename or binary variable, nor do they display the following echo. You must use $compress an argument to something else, which should be done in order to determine success or failure.
alias compress-then-send { if (!$comchan($1,1)) { echo 5 -a no shared channels with nick $1 | return } if (!$isfile($2-)) { echo 5 -a filename does not exist: $2- | return } bread $qt($2-) 0 1 &snip if ($bvar(&snip,1) != 120) { var %i $compress($2-) | if (%i == 0) echo 5 -a warning failure to zlib compress $1- } dcc send $1 $2- }
Note: Before making a script which automatically compresses all files before sending them and decompressing them when they finish, you should take several issues into account.
- You shouldn't automatically decompress or compress files without making certain that the same file isn't also being transferred to/from someone else.
- Besides ON FILESENT, Transfers can also terminate with ON SENDFAIL, clicking to close the send window, using the /close command with the -s switch, mIRC crashing, etc.
- To make certain all files get safely decompressed, the script should probably work from a file listing that doesn't remove lines until the file has been determined to be decompressed.
- Now that $compress supports gzip compression, a script must first determine which method was used to compress the file in order to successfully decompress the file.
Compatibility[edit]
Added: mIRC v6.1
Added on: 29 Aug 2003
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
version 7.51 expanded lN from 1-6 to 0-9, and introduced mN