home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / FILE / JLPAK10.ZIP / JLPAK.DOC < prev    next >
Encoding:
Text File  |  1990-08-20  |  15.9 KB  |  321 lines

  1.  
  2. JLPAK and JLUNPAK
  3. xxxxxxxxxxxxxxxxx
  4.  
  5. 1  Purpose
  6. ==========
  7.  
  8. These programs use "forward compression" to compress a file for
  9. distribution.  The principle is very simple - we assume an old version of
  10. the file (text or binary) is already held on the receiving system.  The
  11. compression algorithm compares the new version with the old and ships only
  12. instructions to reconstitute the new version using the old version,
  13. resulting in typical compression ratios of between 5 to 1 and 10 to 1,
  14. although where there are almost no changes between the two versions,  a
  15. ratio of almost a thousand to one is possible!
  16.  
  17. JLPAK and JLUNPAK provide the starting point for efficient distribution of
  18. versions of a package when the earlier version is already held.  The normal
  19. procedure would be to pack first with JLPAK,  then use a conventional
  20. packing program like PKPAK,  then convert to ASCII with MKBOO.  The receiver
  21. reverses the process.
  22.  
  23. The term "forward compression" is used for compression based on an
  24. assumption that an earlier version of a file is held at a receiving system.
  25. It is thus mainly intended for regular software or text-file updates.  The
  26. approach has been successfully applied for compression of successive frames
  27. of a television transmission,  but the author is not aware of any existing
  28. general-purpose software package supporting the use of this technique for PC
  29. software distribution.
  30.  
  31. Note that  programs such as PKPAK usually talk about "percentage gains" -
  32. maybe as much as 60% with a following wind,  but often only twenty or thirty
  33. percent.  JLPAK talks about the "compression ratio" - maybe very high,  but
  34. figures of between 5 and 10 occur regularly for practical distribution of
  35. new versions.
  36.  
  37. The present programs,  with sources,  are placed in the public domain in the
  38. hope that faster versions will be produced by others.  The present packages
  39. demonstrate very clearly the viability of the approach,  and the compression
  40. ratios that can easily be achieved.  Free use and development of the
  41. approach is encouraged,  including the production of commercial software
  42. based on these programmes.  All that is asked is acknowledgement of the
  43. contribution of
  44.  
  45.         The IT Institute
  46.         University of Salford
  47.         Salford M5 4WT
  48.         England
  49.  
  50. and free licencing to the IT Institute of any software produced using this
  51. work.  Sources (Microsoft QuickBasic) are provided to encourage further
  52. development.
  53.  
  54. If you find the programs useful,  and particularly if you develop them
  55. further,  please inform the Administrator of the IT Institute at the above
  56. address,  or try E-mail to IT01 @ UK.AC.SALFORD.SYSB.
  57.  
  58. 2  Installation
  59. ===============
  60.  
  61. The package consists of two .EXE files,  JLPAK.EXE and JLUNPAK.EXE,  this
  62. documentation (JLPAK.DOC),  and two .BAS source files JLPAK.BAS and
  63. JLUNPAK.BAS.  The source files are in Microsoft QuickBasic.
  64.  
  65. 3  Invoking JLPAK.EXE
  66. =====================
  67.  
  68. * Command line    * O/M/C  * Use of parameter                              
  69. * parameter       *        *                                                 
  70.  
  71.   ("M" means mandatory,  "O" means optional,  "C" means conditional)        
  72.  
  73.   JLPAK             M        Command name                                   
  74.  
  75.   New file path     M        The path name for the new version (the file    
  76.                              to be compressed) on the sender's system       
  77.  
  78.   Ref file path     M        The path name for the old version (the         
  79.                              reference file which must also exist on the    
  80.                              system of any receiver of the compressed       
  81.                              format file                                    
  82.  
  83.   Verbosity         M        The letters B or P for "Brief" or "Progress"   
  84.                              messages,  and optionally a T for "Trace".     
  85.                              In the case of B,  a one-line "percentage      
  86.                              complete" message is output.  In the case of   
  87.                              P,  a full-screen display showing the state    
  88.                              of the compression and the sort of matches     
  89.                              being found is displayed.  For a full          
  90.                              understanding of this,  the technical          
  91.                              section below needs to be read.  In the case   
  92.                              of T,  a full trace of the matches produced    
  93.                              is output to a separate file.  This is         
  94.                              generally useful only for debugging or         
  95.                              further development work.  Use "B" normally.   
  96.  
  97.   FCM file path     M        The path name for the file (conventionally     
  98.                              ".FCM" for forward compression) that is to     
  99.                              be produced.  This file will normally be       
  100.                              compressed further using,  for example,        
  101.                              PKPAK,  then converted to ASCII using,  for    
  102.                              example,  MKBOO,  then sent to recipients.     
  103.  
  104.   Trace file path   C        This has to be present if "T" is included in   
  105.                              the verbosity,  and specifies the file to      
  106.                              contain the trace information.  If "T" is      
  107.                              not present,  this parameter must be absent.   
  108.  
  109.   Receiver's new    O        If omitted,  JLUNPAK will (by default) place   
  110.   file path                  the unpacked file in the path name used for    
  111.                              "New file path" when JLPAK was invoked.  If    
  112.                              present, then this determines the default      
  113.                              file to be produced by JLUNPAK (see below).    
  114.  
  115.   Receiver's ref    O        If omitted,  JLUNPAK will (by default) use     
  116.   file path                  the path name used for "New file path" when    
  117.                              JLPAK was invoked as the reference file for    
  118.                              unpacking.  If present,  then this             
  119.                              determines the default reference file to be    
  120.                              used by JLUNPAK (see below).                   
  121.  
  122. 4  Invoking JLUNPAK.EXE
  123. =======================
  124.                                                                             
  125. * Command line    * O/M/C  * Use of parameter                              
  126. * parameter       *        *                                                
  127.  
  128.   JLUNPAK           M        Command name                                   
  129.  
  130.   FCM file path     M        The path name for the file containing the      
  131.                              packed version that was produced by JLPAK.     
  132.  
  133.   Verbosity         O        Default is "B",  meaning simple percentage     
  134.                              complete messages on one line.  The other      
  135.                              option is "P",  giving a full-screen display   
  136.                              of progress.  Both "B" and "P" may be          
  137.                              combined with "T",  in which case a trace of   
  138.                              the decompression process is produced in a     
  139.                              separate file.  This is mainly useful for      
  140.                              debugging and further development.             
  141.  
  142.   Trace file path   C        This has to be present if "T" is included in   
  143.                              the verbosity,  and specifies the file to      
  144.                              contain the trace information.  If "T" is      
  145.                              not present,  this parameter must be absent.   
  146.  
  147.   Receiver's new    O        If omitted,  JLUNPAK will (by default) place   
  148.   file path                  the unpacked file in the file determined       
  149.                              when JLPAK was invoked (see above),  and       
  150.                              whose name is carried in the FCM format        
  151.                              file.  If present,  this parameter overrides   
  152.                              the name in the FCM format file.               
  153.  
  154.   Receiver's ref    O        If omitted,  JLUNPAK will (by default) use a   
  155.   file path                  file identified by the FCM format file as      
  156.                              the reference file.  If present,  this         
  157.                              parameter overrides the name in the FCM        
  158.                              format file.                                   
  159.  
  160.   Workfile path     O        If omitted,  JLUNPAK will first create a       
  161.                              file TEMP.TMP in the current directory,        
  162.                              unpacking into that,  then copy that to the    
  163.                              required new file,  then delete TEMP.TMP.      
  164.                              If present,  this parameter specifies the      
  165.                              work file to be used.                          
  166.  
  167. 5  Technical details
  168. ====================
  169.  
  170. 5.1  Overall approach
  171. ---------------------
  172.  
  173. 5.1.1  There are undoubtedly other and perhaps better ways of establishing
  174. the information needed to reconstitute the new file after transmission.
  175. The following approach,  implemented in version 1.0 of the package,  works
  176. adequately,  but I would like to encourage experiments to improve on it,  as
  177. well as simply recoding in assembler or with assembler assistance to speed
  178. up the present package. (JLUNPAK is OK - JLPAK is sometimes a bit too slow,
  179. even on an AT).
  180.  
  181. 5.1.2  Binary and text files are both treated as binary.  End of line is
  182. never significant.
  183.  
  184. 5.1.3  16 byte segments of the new file are taken,  and are matched against
  185. the old file.  There are a number of options:
  186.  
  187.      a)  Type A match:  An identical set of 16 bytes exists somewhere in the
  188.      search region (see below) in the old file;
  189.  
  190.      b)  Type B match:  An identical set of 16 bytes exists somewhere in the
  191.      search region in the old file,  subject to the possible addition of a
  192.      single fixed value (called a differ) to some of the 16 bytes;
  193.  
  194.      c)  Type C match:  Similar to a type B,  but there are two possible
  195.      differes,  one or other of which may need to be added in to each of the
  196.      sixteen bytes in the segment;
  197.  
  198.      d)  Type D1 match: Three differs;
  199.  
  200.      e)  Type D2 match: Four differs;
  201.  
  202.      f)  No match: It was not possible to find a match within the search
  203.      region.
  204.  
  205. 5.1.4  The search region is determined by the "resynch state".  In resynch
  206. state zero (the initial state),  every segment is tested against every
  207. possible set of 16 bytes of the old file within a 1K window.  The window's
  208. position is dependent on the location of earlier matches (it is actually
  209. centred on a position that moves halfway towards the location of each match
  210. that is obtained).
  211.  
  212. 5.1.5  If there are never more than ten no matches between successive
  213. matches,  we remain in resynch state zero,  otherwise we move to resynch
  214. state 1.
  215.  
  216. 5.1.6  In resynch state 1,  we only attempt to match every nth segment
  217. (outputting the rest as "no match" options,  but broaden the search window
  218. to nK.  Thus the search time is not increased.  We maintain a "no match
  219. count" (initially ten),  n is the no match count less nine.  On a failure to
  220. match (of the segements we attempt),  we increment the no match count,  and
  221. hence increase our window but reduce the proportion of segments we try to
  222. match.  As soon as we get a match,  we not only reduce the no match count by
  223. one,  but we also go back to trying every segment until there is a failure
  224. again,  in which case n is applied as above.  If the nomatch count gets down
  225. to ten,  then we reenter resych state zero.  If the nomatch count reaches
  226. twenty,  we go into resynch state two.
  227.  
  228. 5.1.7  In resynch state two,  we maintain n at ten,  ignoring further
  229. failures to match.  On a match,  we revert to resynch state 1,  and again go
  230. back to trying every segment.  Also,  in resynch state 2,  we continuously
  231. recalculate the position of the centre of the window to maintain it in the
  232. right proportional position - that is,  if we are 40% through the new file,
  233. we centre the window 40% through the old file.
  234.  
  235. 5.1.8  The above algorithm represents a compromise between a poor
  236. compression ratio (a lot of "no match" segments output) and an excessive
  237. time spent compressing the file.  It seems to work OK on an AT with the
  238. QuickBasic code.  With assembler assist,  we could probably improve the
  239. algorithm to put more effort into the packing and improve the compression
  240. ratio.  In particular,  more research into appropriate techniques when we
  241. reach resynch state 2 could be valuable.
  242.  
  243. 5.2  The FCM file format
  244. ------------------------
  245.  
  246. 5.2.1  The FCM file format is largely independent of the details of the
  247. heuristic algorithm used to determine matches.  The format is based on the
  248. retention of five pieces of state information,  a pointer,  and four
  249. differs.
  250.  
  251. 5.2.2  The basic structure is
  252.  
  253.      a)  a header (see below);
  254.  
  255.      b)  a series of single-octet coded commands,  each followed by some
  256.      parameter information for the command (frequently a bit-map);
  257.  
  258. 5.2.3  The header contains
  259.  
  260.      a)  The path name to be used for the new file after decompression;
  261.  
  262.      b)  A two-byte checksum (the standard sigma Ai MOD 255 plus sigma iAi
  263.      MOD 255) is used of the new file;  if the results of decompression do
  264.      not produce a matching checksum,  the new file is not written out from
  265.      the work file;
  266.  
  267.      c)  The path name to be used for the reference file;
  268.  
  269.      d)  A two-byte checksum of the reference file;  if the purported
  270.      reference file for decompression does not have the same checksum,  then
  271.      decompression is abandonned.
  272.  
  273. 5.2.4  The coded commands consist of:
  274.  
  275.      a)  Move the pointer; (four codes,  to cope with positive and negative
  276.      movements and one or two following octets with the movement value);
  277.  
  278.      b)  Change one of the four differs; (two codes each,  for positive and
  279.      negative values of 0 to 255,  held in the following octet);
  280.  
  281.      c)  Copy up to 64 segments (of 16 bytes each) from the old file at the
  282.      given pointer position (these commands reflect type A matches);
  283.  
  284.      d)  Copy up to 8 segments (of 16 bytes each), using a given differ
  285.      (four codes,  one for each differ),  with the addition of the differ
  286.      according to the following bit-map where 0 means no addition and 1
  287.      means add;  there will be two following octets for each segment;  this
  288.      corresponds to type B matches;
  289.  
  290.      e)  A similar set of six codes require the use of two out of the four
  291.      differs to be added in,  with the bit-map being variable length (it
  292.      ends when we have got all we need),  a zero bit meaning no addition,  a
  293.      10 meaning the first of the selected pair of differs (selected by the
  294.      code),  and a 11 the second of the selected pair of differs.  Again,
  295.      we cope with up to 8 segments in one command;
  296.  
  297.      f)  A further set of four codes which deal with type D1 and D2 matches
  298.      (three or four differs);  in retrospect,  we could probably have got
  299.      away with treating all three differ cases as four differ cases,  which
  300.      could have given PKPAK more scope for further compression of the FCM
  301.      format file;
  302.  
  303.      g)  A code which specifies the copying of up to 64 16-byte segments
  304.      from the FCM format file itself (no match cases);
  305.  
  306.      h)  A code to flag the discard of parts of the old file for buffer
  307.      management purposes (the software handles arbitrarily large files,
  308.      using 30K buffers);
  309.  
  310.      i)  A code to handle termination,  and any remaining octets after the
  311.      last full 16-byte segment (no attempt is made to match these,  they are
  312.      always sent explicitly).
  313.  
  314. 5.2.5  For further details of formats or operation,  the source code should
  315. be consulted.
  316.  
  317. JL
  318.  
  319. 20 August 1990
  320.  
  321.