Create a basic html output, to validate that we're loading data correctly.
[quanlib.git] / cover.rb
1
2 class Cover
3   def initialize(inputStream, path, mimeType)
4     @data = inputStream.read
5     @path = path
6     @mimeType = mimeType
7   end
8
9   def inspect
10     info = []
11     if nil != @data
12       info.push('size=' + @data.length.to_s)
13     else
14       info.push('empty')
15     end
16     if nil != @path
17       info.push('path="' + @path + '"')
18     end
19     if nil != @mimeType
20       info.push('mimeType="' + @mimeType + '"')
21     end
22     return '(Cover:' + info.join(',') + ')'
23   end
24
25   def to_s
26     return inspect
27   end
28
29   def writeImage(outputDir, baseName)
30     filename = baseName + getExt()
31     open(outputDir + '/' + filename, 'wb') do |fd|
32       fd.write(@data)
33     end
34     return filename, @mimeType
35   end
36
37   protected
38   def getExt
39     pos = @path.rindex('.')
40     if nil == pos
41       return '.img'
42     end
43     return @path.slice(pos, @path.length)
44   end
45 end
46