/**
 * Copyright (c) 2020, 2021 Oracle and/or its affiliates.  All rights reserved.
 * This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
 */ export class Range { param startByte param endByte param contentLength constructor ( private startByte , private endByte , private contentLength ) { this . startByte = startByte ; this . endByte = endByte ; this . contentLength = contentLength ; } param value return public static parse ( value ) { console . debug ( "Attempting to parse range: %s" , value ) ; value = value . replace ( "bytes" , "" ) . trim ( ) ; const parts = value . split ( "/" ) ; if ( parts . length != 2 ) throw Error ( "Must provide <range>/<length> format for range request: " + value ) ; const byteRangePart = parts [ 0 ] ; const contentLengthPart = parts [ 1 ] ; const contentLength = contentLengthPart === "*" ? null : Number ( contentLengthPart ) ; const byteValues = byteRangePart . split ( "-" , - 1 ) ; if ( byteValues . length != 2 ) { throw new Error ( "Must provide <start>-<end> format for range request: " + value ) ; } const startByte = byteValues [ 0 ] === "" ? null : Number ( byteValues [ 0 ] ) ; const endByte = byteValues [ 1 ] === "" ? null : Number ( byteValues [ 1 ] ) ; if ( startByte == null && endByte == null ) { throw new Error ( "Must provide start/end byte for range request: " + value ) ; } let range = new Range ( startByte , endByte , contentLength ) ; return range ; return ; } }