Class: Browser::HTTP::Binary
- Includes:
- Enumerable
- Defined in:
- opal/browser/http/binary.rb
Overview
Represents a binary result from a HTTP response.
Instance Attribute Summary collapse
-
#length ⇒ Integer
readonly
The length of the binary.
-
#type ⇒ :string, :buffer
readonly
The type of binary.
Instance Method Summary collapse
-
#[](index) ⇒ Integer
Access a byte from the binary.
-
#each {|byte| ... } ⇒ self
Iterate over each byte in the binary.
-
#initialize(value) ⇒ Binary
constructor
Create a binary from a value.
Constructor Details
Instance Attribute Details
#length ⇒ Integer (readonly)
Returns the length of the binary.
53 54 55 |
# File 'opal/browser/http/binary.rb', line 53 def length @data.length end |
#type ⇒ :string, :buffer (readonly)
Returns the type of binary.
7 8 9 |
# File 'opal/browser/http/binary.rb', line 7 def type @type end |
Instance Method Details
#[](index) ⇒ Integer
Access a byte from the binary.
47 48 49 |
# File 'opal/browser/http/binary.rb', line 47 def [](index) @type == :string ? `#@data.charCodeAt(index) & 0xff` : @data[index] end |
#each {|byte| ... } ⇒ self
Iterate over each byte in the binary.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'opal/browser/http/binary.rb', line 29 def each(&block) return enum_for :each unless block index = 0 length = self.length while index < length block.call(self[index]) index += 1 end self end |