Module: PngCheck

Extended by:
FFI::Library
Defined in:
lib/pngcheck.rb,
lib/pngcheck/recipe.rb,
lib/pngcheck/version.rb

Defined Under Namespace

Classes: CorruptPngError, EmptyPngError, Recipe

Constant Summary collapse

STATUS_OK =
0
STATUS_WARNING =

an error in some circumstances but not in all

1
STATUS_MINOR_ERROR =

minor spec errors (e.g., out-of-range values)

3
STATUS_MAJOR_ERROR =

file corruption, invalid chunk length/layout, etc.

4
STATUS_CRITICAL_ERROR =

unexpected EOF or other file(system) error

5
EMPTY_IMAGE =
"Image is empty"
EXTRA_MESSAGE_SIZE =
1024
VERSION =
"0.3.1"
@@semaphore =
Mutex.new

Class Method Summary collapse

Class Method Details

.analyze_buffer(data) ⇒ Object



70
71
72
73
74
# File 'lib/pngcheck.rb', line 70

def analyze_buffer(data)
  return [STATUS_CRITICAL_ERROR, EMPTY_IMAGE] if data.empty?

  do_analyze_buffer(data)
end

.analyze_file(path) ⇒ Object



56
57
58
59
60
# File 'lib/pngcheck.rb', line 56

def analyze_file(path)
  return [STATUS_CRITICAL_ERROR, EMPTY_IMAGE] if File.zero? path

  do_analyze_file(path)
end

.check_buffer(data) ⇒ Object

Raises:



76
77
78
79
80
81
82
# File 'lib/pngcheck.rb', line 76

def check_buffer(data)
  status, info = analyze_buffer(data)
  raise EmptyPngError.new if info.eql? EMPTY_IMAGE
  raise CorruptPngError.new(info, status) unless status == STATUS_OK

  true
end

.check_file(path) ⇒ Object

Raises:



62
63
64
65
66
67
68
# File 'lib/pngcheck.rb', line 62

def check_file(path)
  status, info = analyze_file(path)
  raise EmptyPngError.new if info.eql? EMPTY_IMAGE
  raise CorruptPngError.new(info, status) unless status == STATUS_OK

  true
end