-- ************************************************************************
-- Script: GZCOMPRESS
-- Version: 0.2
-- Date: 2009-08-09
-- Author: Valentin Schmidt
--
-- implements ZLIB compression according to RFC1950 (http://www.faqs.org/rfcs/rfc1950)
-- data is e.g. compatible with PHP's gzcompress()/gzuncompress() functions.
--
-- Requirements:
-- * fileIO xtra
-- * fileIO wrapper functions file_get_bytes/file_put_bytes
--
-- ************************************************************************
----------------------------------------
-- gzcompress data
----------------------------------------
on gzcompress_bytearray (ba)
-- or just: ba.compress()
ret = bytearray()
ret.writeByteArray(ba)
ret.compress()
return ret
end
----------------------------------------
-- gzcompress file
----------------------------------------
on gzcompress_file(inputFile, outputFile)
ba = file_get_bytes(inputFile)
ba.compress()
file_put_bytes (outputFile, ba)
end
----------------------------------------
-- gzuncompress data
----------------------------------------
on gzuncompress_bytearray (ba)
-- or just: ba.uncompress()
ret = bytearray(ba.length)
ret.position = 1
ret.writeByteArray(ba)
ret.uncompress()
return ret
end
----------------------------------------
-- gzuncompress file
----------------------------------------
on gzuncompress_file(inputFile, outputFile, adler32)
ba = file_get_bytes(inputFile)
ba.uncompress()
file_put_bytes (outputFile, ba)
end