Class: Dommy::DecompressionStream

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/compression_streams.rb

Constant Summary collapse

SUPPORTED =
%w[gzip deflate deflate-raw].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, format) ⇒ DecompressionStream

Returns a new instance of DecompressionStream.

Raises:

  • (ArgumentError)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/dommy/compression_streams.rb', line 87

def initialize(window, format)
  raise ArgumentError, "unsupported format #{format.inspect}" unless SUPPORTED.include?(format.to_s)

  @buffer = +""
  decompressor = build_decompressor(format.to_s)

  @readable = ReadableStream.new(window)
  controller = TransformStreamDefaultController.new(@readable)

  @writable = WritableStream.new(
    window,
    {
      "write" => proc { |chunk| @buffer << coerce(chunk) },
      "close" => proc do
        plain = decompressor.call(@buffer)
        controller.enqueue(plain)
        @readable.__internal_close__
      end,
      "abort" => proc { |r| @readable.__internal_error__(r) }
    }
  )
end

Instance Attribute Details

#readableObject (readonly)

Returns the value of attribute readable.



85
86
87
# File 'lib/dommy/compression_streams.rb', line 85

def readable
  @readable
end

#writableObject (readonly)

Returns the value of attribute writable.



85
86
87
# File 'lib/dommy/compression_streams.rb', line 85

def writable
  @writable
end

Instance Method Details

#__js_get__(key) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/dommy/compression_streams.rb', line 110

def __js_get__(key)
  case key
  when "readable"
    @readable
  when "writable"
    @writable
  else
    Bridge::ABSENT
  end
end