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)


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

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.__close__
      end,
      "abort" => proc { |r| @readable.__error__(r) }
    }
  )
end

Instance Attribute Details

#readableObject (readonly)

Returns the value of attribute readable.



83
84
85
# File 'lib/dommy/compression_streams.rb', line 83

def readable
  @readable
end

#writableObject (readonly)

Returns the value of attribute writable.



83
84
85
# File 'lib/dommy/compression_streams.rb', line 83

def writable
  @writable
end

Instance Method Details

#__js_get__(key) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/dommy/compression_streams.rb', line 108

def __js_get__(key)
  case key
  when "readable"
    @readable
  when "writable"
    @writable
  end
end