From WikiChip
Difference between revisions of "mirc/identifiers/$compress"
< mirc‎ | identifiers

m
m
Line 36: Line 36:
 
'''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.
  

Revision as of 12:26, 20 June 2017

The $compress identifier performs compression of a disk file or binary variable.

Synopsis

$compress( <filename | BinaryVariable> ,[b][lN] )

Parameters

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 (slower, smallest output). lN overrides to use compression level N, where N is integer 1-6.

Example

There are patterns that often appear near the beginning, but there's no guaranteed signature to be found at the beginning of a compressed file, except the 1st character is $chr(120) small-x.

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 file. 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 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.

  1. You shouldn't automatically decompress or compress files without making certain that the same file isn't also being transferred to/from someone else.
  2. 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.
  3. 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.

Compatibility

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.


See also