From WikiChip
Editing mirc/identifiers/$compress

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 4: Line 4:
  
 
== Synopsis ==
 
== Synopsis ==
<pre>$compress( <filename | BinaryVariable> ,[b][lN][mN] )</pre>
+
<pre>$compress( <filename | BinaryVariable> ,[b][lN] )</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 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;">'''lN'''</span>Default compression level is 6 (slower, smallest output). lN overrides to use compression level N, where N is integer 1-6.
<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 from observations, it appears you should not assume beyond:
+
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.
  
m1 raw: No guaranteed signature because the data is 'raw'. (m1l0 is the same as the input data)<br />
+
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.
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 filesize. 0 can indicate there's no-such-file, the file wasn't already compressed, or a failure to decompress corrupted data.
 
  
 
<pre>
 
<pre>
Line 37: Line 30:
 
   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 zlib compress $1- }
+
   if ($bvar(&snip,1) != 120) { var %i $compress($2-) | if (%i == 0) echo 5 -a warning failure to compress $1- }
 
   dcc send $1 $2-
 
   dcc send $1 $2-
 
}
 
}
Line 46: Line 39:
 
# 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.
 
# 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 ==

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)