Deflate Compress

From SwiftAPI

Jump to: navigation, search


Compress data using the DEFLATE algorithm as described in RFC 1951.

PHP

php.net

$level = 5;
$data = 'AAAAAAAAAAAAAAAA';
$compressed = gzdeflate($data, $level);
// strlen($compressed) == 5
// bin2hex($compressed) == "7374440500"

Ruby

require 'zlib'
 
level = 5
data = 'AAAAAAAAAAAAAAAA'
compressed = Zlib::Deflate.new(level, -Zlib::MAX_WBITS).deflate(data, Zlib::FINISH)
# compressed.length == 5
# compressed.bytes.collect { |b| "%02x" % b }.join == "7374440500"
Personal tools