1. -- ************************************************************************
  2. -- Script:   GZCOMPRESS
  3. -- Version:  0.2
  4. -- Date:     2009-08-09
  5. -- Author:   Valentin Schmidt
  6. --
  7. -- implements ZLIB compression according to RFC1950 (http://www.faqs.org/rfcs/rfc1950)
  8. -- data is e.g. compatible with PHP's gzcompress()/gzuncompress() functions.
  9. --
  10. -- Requirements:
  11. -- * fileIO xtra
  12. -- * fileIO wrapper functions file_get_bytes/file_put_bytes
  13. --
  14. -- ************************************************************************
  15.  
  16. ----------------------------------------
  17. -- gzcompress data
  18. ----------------------------------------
  19. on gzcompress_bytearray (ba)
  20.   -- or just: ba.compress()
  21.   ret = bytearray()
  22.   ret.writeByteArray(ba)
  23.   ret.compress()
  24.   return ret
  25. end
  26.  
  27. ----------------------------------------
  28. -- gzcompress file
  29. ----------------------------------------
  30. on gzcompress_file(inputFile, outputFile)
  31.   ba = file_get_bytes(inputFile)
  32.   ba.compress()
  33.   file_put_bytes (outputFile, ba)
  34. end
  35.  
  36. ----------------------------------------
  37. -- gzuncompress data
  38. ----------------------------------------
  39. on gzuncompress_bytearray (ba)
  40.   -- or just: ba.uncompress()
  41.   ret = bytearray(ba.length)
  42.   ret.position = 1
  43.   ret.writeByteArray(ba)
  44.   ret.uncompress()
  45.   return ret
  46. end
  47.  
  48. ----------------------------------------
  49. -- gzuncompress file
  50. ----------------------------------------
  51. on gzuncompress_file(inputFile, outputFile, adler32)
  52.   ba = file_get_bytes(inputFile)
  53.   ba.uncompress()
  54.   file_put_bytes (outputFile, ba)
  55. end
  56.  
[raw code]