LZO/Ruby: 圧縮してみる

きちんと圧縮できてるか不安だったので、ちょっと動作確認。

require 'lzoruby'

open('index.html', 'rb') do |fin|
  open('index.html.lzo', 'wb') do |fout|
    fout << LZO.compress(fin.read)
  end
end

open('index.html.lzo', 'rb') do |fin|
  open('index.html.2', 'wb') do |fout|
    fout << LZO.decompress(fin.read)
  end
end


~/work$ wget http://d.hatena.ne.jp/winebarrel/
--2008-07-29 03:15:57-- http://d.hatena.ne.jp/winebarrel/
Resolving d.hatena.ne.jp... 59.106.108.77
Connecting to d.hatena.ne.jp|59.106.108.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html'

[ <=> ] 85,883 356K/s in 0.2s

2008-07-29 03:15:58 (356 KB/s) - `index.html' saved [85883]

~/work$ ruby foo.rb
~/work$ ll index.html*
-rw-r--r-- 1 sugawara 84K Jul 29 02:33 index.html
-rw-r--r-- 1 sugawara 84K Jul 29 03:16 index.html.2
-rw-r--r-- 1 sugawara 23K Jul 29 03:16 index.html.lzo
~/work$ diff index.html index.html.2

伸長用のバッファのサイズって、アーカイブの8倍で大丈夫かなぁ…