File: string-util.rb

package info (click to toggle)
samidare 0.0.20040611-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 144 kB
  • ctags: 112
  • sloc: ruby: 1,745; makefile: 53
file content (21 lines) | stat: -rw-r--r-- 313 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'zlib'
require 'stringio'

class String
  def decode_gzip
    Zlib::GzipReader.new(StringIO.new(self)).read || ""
  end

  def encode_gzip
    out = ""
    Zlib::GzipWriter.wrap(StringIO.new(out)) {|gz|
      gz << self
    }
    out
  end

  def decode_deflate
    Zlib::Inflate.inflate(self)
  end
end