module ActiveSupport::Gzip
Active Support Gzip
Удобная оболочка для стандартной библиотеки zlib, позволяющая сжимать и распаковывать строки с помощью gzip.
gzip = ActiveSupport::Gzip.compress('compress me!')
# => "\x1F\x8B\b\x00o\x8D\xCDO\x00\x03K\xCE\xCF-(J-.V\xC8MU\x04\x00R>n\x83\f\x00\x00\x00"
ActiveSupport::Gzip.decompress(gzip)
# => "compress me!"
Открытые методы класса
# File activesupport/lib/active_support/gzip.rb, line 32 def self.compress(source, level = Zlib::DEFAULT_COMPRESSION, strategy = Zlib::DEFAULT_STRATEGY) output = Stream.new gz = Zlib::GzipWriter.new(output, level, strategy) gz.mtime = 0 gz.write(source) gz.close output.string end
Сжимает строку с помощью gzip.
# File activesupport/lib/active_support/gzip.rb, line 27 def self.decompress(source) Zlib::GzipReader.wrap(StringIO.new(source), &:read) end
Распаковывает строку, сжатую с помощью gzip.
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.