[Groonga-commit] ranguba/chupa-text at f65d983 [master] Support encoded screenshot data

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Thu Jul 6 14:13:36 JST 2017


Kouhei Sutou	2017-07-06 14:13:36 +0900 (Thu, 06 Jul 2017)

  New Revision: f65d9830e99e0864acdf583439e7ed653bc351f3
  https://github.com/ranguba/chupa-text/commit/f65d9830e99e0864acdf583439e7ed653bc351f3

  Message:
    Support encoded screenshot data

  Modified files:
    lib/chupa-text/formatters/hash.rb
    lib/chupa-text/screenshot.rb

  Modified: lib/chupa-text/formatters/hash.rb (+7 -3)
===================================================================
--- lib/chupa-text/formatters/hash.rb    2017-07-06 14:13:19 +0900 (f28bee6)
+++ lib/chupa-text/formatters/hash.rb    2017-07-06 14:13:36 +0900 (4ec27b8)
@@ -28,11 +28,15 @@ module ChupaText
         text = {}
         format_headers(data, text)
         text["body"] = data.body
-        if data.screenshot
+        screenshot = data.screenshot
+        if screenshot
           text["screenshot"] = {
-            "mime-type" => data.screenshot.mime_type,
-            "data" => data.screenshot.data,
+            "mime-type" => screenshot.mime_type,
+            "data" => screenshot.data,
           }
+          if screenshot.encoding
+            text["screenshot"]["encoding"] = screenshot.encoding
+          end
         end
         @texts << text
       end

  Modified: lib/chupa-text/screenshot.rb (+18 -2)
===================================================================
--- lib/chupa-text/screenshot.rb    2017-07-06 14:13:19 +0900 (08ed97a)
+++ lib/chupa-text/screenshot.rb    2017-07-06 14:13:36 +0900 (0429e18)
@@ -20,11 +20,27 @@ module ChupaText
     attr_reader :mime_type
 
     # @return [String] The data of the screenshot.
-    attr_accessor :data
+    attr_reader :data
 
-    def initialize(mime_type, data)
+    # @return [String, nil] The encoding of the screenshot data.
+    #   `nil` means that the data is raw data. It's used for SVG data
+    #   because it's text data. `"base64"` means that the data is encoded
+    #   by Base64. It's used for PNG data because it's binary data.
+    attr_reader :encoding
+
+    def initialize(mime_type, data, encoding=nil)
       @mime_type = mime_type
       @data = data
+      @encoding = encoding
+    end
+
+    def decoded_data
+      case @encoding
+      when "base64"
+        @data.unpack("m*")[0]
+      else
+        @data
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index