Sha256: 2b835eff7c1a197c7bbd7e9022335a32862ce03b2ccd8704e647113ffa739758

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

module PNGSuite
  PNG_SUITE_URL = "http://www.schaik.com/pngsuite/PngSuite-2011apr25.tgz"

  class << self
    attr_accessor :dir

    def init dir
      @dir = dir
      if Dir.exist?(dir)
        if Dir[File.join(dir, "*.png")].size > 100
          # already fetched and unpacked
          return
        end
      else
        Dir.mkdir(dir)
      end
      require 'open-uri'
      puts "[.] fetching PNG test-suite from #{PNG_SUITE_URL} .. "
      data = URI.open(PNG_SUITE_URL).read

      fname = File.join(dir, "png_suite.tgz")
      File.binwrite fname, data
      puts "[.] unpacking .. "
      system "tar", "xf", fname, "-C", dir
      raise "cannot unpack #{fname}" unless $?.success?
    end

    def each *prefixes
      Dir[File.join(dir,"*.png")].each do |fname|
        if prefixes.empty?
          yield fname
        elsif prefixes.any?{ |p| p[/[*?\[]/] ? File.fnmatch(p, File.basename(fname)) : File.basename(fname).start_with?(p) }
          yield fname
        end
      end
    end

    def each_good
      Dir[File.join(dir,"[^x]*.png")].each do |fname|
        yield fname
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
zpng-0.4.3 spec/support/png_suite.rb
zpng-0.4.2 spec/support/png_suite.rb
zpng-0.4.1 spec/support/png_suite.rb
zpng-0.4.0 spec/support/png_suite.rb
zpng-0.3.4 spec/support/png_suite.rb
zpng-0.3.3 spec/support/png_suite.rb
zpng-0.3.2 spec/support/png_suite.rb