Class: Cloudflare::EmbeddedBinaryBody
- Inherits:
-
Object
- Object
- Cloudflare::EmbeddedBinaryBody
- Defined in:
- lib/cloudflare_workers.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.
554 555 556 557 558 |
# File 'lib/cloudflare_workers.rb', line 554 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.
552 553 554 |
# File 'lib/cloudflare_workers.rb', line 552 def body_base64 @body_base64 end |
#cache_control ⇒ Object (readonly)
Returns the value of attribute cache_control.
552 553 554 |
# File 'lib/cloudflare_workers.rb', line 552 def cache_control @cache_control end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
552 553 554 |
# File 'lib/cloudflare_workers.rb', line 552 def content_type @content_type end |
Instance Method Details
#close ⇒ Object
562 |
# File 'lib/cloudflare_workers.rb', line 562 def close; end |
#each ⇒ Object
560 |
# File 'lib/cloudflare_workers.rb', line 560 def each; end |
#raw_response(status, headers = {}) ⇒ Object
564 565 566 567 568 569 570 |
# File 'lib/cloudflare_workers.rb', line 564 def raw_response(status, headers = {}) js_headers = `({})` headers.each { |k, v| ks = k.to_s; vs = v.to_s; `#{js_headers}[#{ks}] = #{vs}` } `#{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
572 573 574 |
# File 'lib/cloudflare_workers.rb', line 572 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 |