Class: Cloudflare::BinaryBody

Inherits:
Object
  • Object
show all
Defined in:
lib/homura/runtime.rb

Overview

BinaryBody wraps a JS ReadableStream (from R2, fetch, etc.) so it can flow through the Rack/Sinatra body pipeline without being converted to an Opal String (which would mangle the bytes). ‘build_js_response` detects BinaryBody and passes the stream directly to `new Response`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, content_type = "application/octet-stream", cache_control = nil) ⇒ BinaryBody

Returns a new instance of BinaryBody.



710
711
712
713
714
715
716
717
718
# File 'lib/homura/runtime.rb', line 710

def initialize(
  stream,
  content_type = "application/octet-stream",
  cache_control = nil
)
  @stream = stream
  @content_type = content_type
  @cache_control = cache_control
end

Instance Attribute Details

#cache_controlObject (readonly)

Returns the value of attribute cache_control.



708
709
710
# File 'lib/homura/runtime.rb', line 708

def cache_control
  @cache_control
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



708
709
710
# File 'lib/homura/runtime.rb', line 708

def content_type
  @content_type
end

#streamObject (readonly)

Returns the value of attribute stream.



708
709
710
# File 'lib/homura/runtime.rb', line 708

def stream
  @stream
end

Instance Method Details

#closeObject



725
726
# File 'lib/homura/runtime.rb', line 725

def close
end

#eachObject

Rack body contract — yield nothing so Sinatra’s content-length calculation skips this body. The real bytes go through JS.



722
723
# File 'lib/homura/runtime.rb', line 722

def each
end