Class: Cloudflare::EmbeddedBinaryBody
- Inherits:
-
Object
- Object
- Cloudflare::EmbeddedBinaryBody
- Defined in:
- lib/homura/runtime.rb
Overview
EmbeddedBinaryBody carries a base64-encoded asset payload produced at build time by ‘compile-assets`, then reconstructs a Uint8Array in the Worker before building the Response stream.
Instance Attribute Summary collapse
-
#body_base64 ⇒ Object
readonly
Returns the value of attribute body_base64.
-
#cache_control ⇒ Object
readonly
Returns the value of attribute cache_control.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
-
#initialize(body_base64, content_type = "application/octet-stream", cache_control = nil) ⇒ EmbeddedBinaryBody
constructor
A new instance of EmbeddedBinaryBody.
- #raw_response(status, headers = {}) ⇒ Object
- #stream ⇒ Object
Constructor Details
#initialize(body_base64, content_type = "application/octet-stream", cache_control = nil) ⇒ EmbeddedBinaryBody
Returns a new instance of EmbeddedBinaryBody.
735 736 737 738 739 740 741 742 743 |
# File 'lib/homura/runtime.rb', line 735 def initialize( body_base64, content_type = "application/octet-stream", cache_control = nil ) @body_base64 = body_base64 || "" @content_type = content_type @cache_control = cache_control end |
Instance Attribute Details
#body_base64 ⇒ Object (readonly)
Returns the value of attribute body_base64.
733 734 735 |
# File 'lib/homura/runtime.rb', line 733 def body_base64 @body_base64 end |
#cache_control ⇒ Object (readonly)
Returns the value of attribute cache_control.
733 734 735 |
# File 'lib/homura/runtime.rb', line 733 def cache_control @cache_control end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
733 734 735 |
# File 'lib/homura/runtime.rb', line 733 def content_type @content_type end |
Instance Method Details
#close ⇒ Object
748 749 |
# File 'lib/homura/runtime.rb', line 748 def close end |
#each ⇒ Object
745 746 |
# File 'lib/homura/runtime.rb', line 745 def each end |
#raw_response(status, headers = {}) ⇒ Object
751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/homura/runtime.rb', line 751 def raw_response(status, headers = {}) js_headers = `({})` headers.each do |k, v| ks = k.to_s vs = v.to_s `#{js_headers}[#{ks}] = #{vs}` end `#{js_headers}['content-type'] = #{@content_type}` if @content_type `#{js_headers}['cache-control'] = #{@cache_control}` if @cache_control RawResponse.new( `new Response(#{stream}, { status: #{status.to_i}, headers: #{js_headers} })` ) end |
#stream ⇒ Object
765 766 767 |
# File 'lib/homura/runtime.rb', line 765 def stream `(function(b64) { return new ReadableStream({ start(controller) { var bin = globalThis.atob(b64); var len = bin.length; var out = new Uint8Array(len); for (var i = 0; i < len; i++) { out[i] = bin.charCodeAt(i) & 0xff; } controller.enqueue(out); controller.close(); } }); })(#{@body_base64})` end |