Sha256: 77c16cc252a29184bcb8d1b3f2abe14d817117e430d35f6a691db0d6bb19fec9

Contents?: true

Size: 534 Bytes

Versions: 3

Compression:

Stored size: 534 Bytes

Contents

#!/usr/bin/ruby -w
# -*- ruby -*-

require 'zlib'
require 'pathname'

module Command
end

module Command::Cacheable
  # A pathname (file) that reads and writes a list of lines, as gzipped
  class GzipPathname < Pathname
    def save_file content
      parent.mkpath unless parent.exist?
      unlink if exist?
      Zlib::GzipWriter.open(to_s) do |gz|
        gz.puts content
      end
    end

    def read_file
      content = nil
      Zlib::GzipReader.open(to_s) do |gz|
        content = gz.readlines
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
command-cacheable-0.2.1 lib/command/cacheable/gzpathname.rb
command-cacheable-0.2.0 lib/command/cacheable/gzpathname.rb
command-cacheable-0.1.0 lib/command/cacheable/gzpathname.rb