M3U8::ByteRange
ByteRange represents a sub-range of a resource.
In HTTP Live Streaming, the EXT-X-BYTERANGE tag (RFC 8216, Section 4.3.2.2)
indicates that a Media Segment is a sub-range of the resource identified by its URI.
Its format is:
#EXT-X-BYTERANGE:<length>[@<start>]
where:
lengthis a decimal integer indicating the length of the sub-range in bytes.start(optional) is a decimal integer indicating the start of the sub-range as a byte offset from the beginning of the resource.
If start is not provided, then the sub-range begins at the next byte following the
sub-range of the previous Media Segment. In that case, a previous Media Segment
MUST appear in the Playlist and be a sub-range of the same media resource; otherwise,
the Media Segment is undefined and the client MUST fail to parse the Playlist.
Note: A Media Segment without an EXT-X-BYTERANGE tag consists of the entire
resource identified by its URI. Use of the EXT-X-BYTERANGE tag requires a
compatibility version number of 4 or greater.
Constructors
Creates a new ByteRange from a string.
Examples:
ByteRange.new("4500@600")
ByteRange.new("4500")
Creates a new ByteRange from a NamedTuple.
Examples:
options = {length: 4500, start: 600}
ByteRange.new(options)
ByteRange.new(length: 4500, start: 600)
Class methods
Parses the given item into a ByteRange.
Examples:
ByteRange.parse(ByteRange.new(length: 4500, start: 600))
ByteRange.parse({length: 4500, start: 600})
ByteRange.parse("4500@600")
ByteRange.parse
Instance methods
Compares this ByteRange with a String.
The ByteRange is equal to the string if their string representations match.
Example:
left = ByteRange.new(length: 4500, start: 600)
right = "4500@600"
left == right # => true
Compares this ByteRange with a NamedTuple.
It creates a new ByteRange from the NamedTuple and compares their string
representations.
Example:
left = ByteRange.new(length: 4500, start: 600)
right = {length: 4500, start: 600}
left == right # => true
Compares this ByteRange with another ByteRange.
Two ByteRanges are equal if their string representations are equal.
Example:
left = ByteRange.new(length: 4500, start: 600)
right = ByteRange.new(length: 4500, start: 600)
left == right # => true
Returns whether the ByteRange is empty.
A ByteRange is considered empty if its length is nil or zero.
Examples:
byterange = ByteRange.new
byterange.empty? # => true
byterange = ByteRange.new(length: 0)
byterange.empty? # => true
byterange.length = 4500
byterange.empty? # => false
The start of the sub-range as a byte offset from the beginning of the resource.
Returns a string representation of the ByteRange.
The representation is the length, followed by the start (if provided)
separated by an @.
Examples:
byterange = ByteRange.new(length: 4500, start: 600)
byterange.to_s # => "4500@600"
byterange = ByteRange.new(length: 4500)
byterange.to_s # => "4500"
byterange = ByteRange.new
byterange.to_s # => ""