class ContentRangeHeaderValue
cangjie
public class ContentRangeHeaderValue <: Equatable<ContentRangeHeaderValue>功能:表示 HTTP Content-Range 响应标头值(RFC 7233)
支持三种形式:
bytes 12-34/5678:带范围和总长度bytes star/1234:未知范围,仅总长度bytes 12-34/star:带范围,未知总长度
父类型:
- Equatable<ContentRangeHeaderValue>
成员概览
| 成员 | 功能 |
|---|---|
| init(Int64, Int64, Int64) | 构造带范围和总长度的 Content-Range("bytes from-to/length") |
| init(Int64) | 构造仅含总长度的 Content-Range(形如 bytes star/length) |
| init(Int64, Int64) | 构造带范围但总长度未知的 Content-Range(形如 bytes from-to/star) |
| prop unit | 范围单位(默认 "bytes") |
| prop from | 范围起始(None 表示 *) |
| prop to | 范围结束(None 表示 *) |
| prop length | 总长度(None 表示 *) |
| prop hasLength | 是否有总长度 |
| prop hasRange | 是否有具体范围(from 和 to 均存在) |
| func toString() | 序列化为字符串,如 bytes 0-499/1234、bytes star/1234 或 bytes 0-499/star |
| func ==(ContentRangeHeaderValue) | 比较两个 Content-Range 标头值是否相等。 |
| func hashCode() | 返回当前 Content-Range 标头值的哈希值。 |
| func parse(String) | 解析 Content-Range 字符串,格式非法时抛出异常 |
| func tryParse(String) | 尝试解析 Content-Range 字符串,返回 None 表示格式无效 |
init(Int64, Int64, Int64)
cangjie
public init(from: Int64, to: Int64, length: Int64)功能:构造带范围和总长度的 Content-Range("bytes from-to/length")
- length 必须非负;to 必须非负且严格小于 length;from 必须非负且不大于 to
参数:
- from:
Int64- 范围起始位置。 - to:
Int64- 范围结束位置。 - length:
Int64- 资源总长度。
init(Int64)
cangjie
public init(length: Int64)功能:构造仅含总长度的 Content-Range(形如 bytes star/length)
参数:
- length:
Int64- 资源总长度。
init(Int64, Int64)
cangjie
public init(from: Int64, to: Int64)功能:构造带范围但总长度未知的 Content-Range(形如 bytes from-to/star)
参数:
- from:
Int64- 范围起始位置。 - to:
Int64- 范围结束位置。
prop unit
cangjie
public mut prop unit: String功能:范围单位(默认 "bytes")
类型:String
prop from
cangjie
public prop from: ?Int64功能:范围起始(None 表示 *)
类型:?Int64
prop to
cangjie
public prop to: ?Int64功能:范围结束(None 表示 *)
类型:?Int64
prop length
cangjie
public prop length: ?Int64功能:总长度(None 表示 *)
类型:?Int64
prop hasLength
cangjie
public prop hasLength: Bool功能:是否有总长度
类型:Bool
prop hasRange
cangjie
public prop hasRange: Bool功能:是否有具体范围(from 和 to 均存在)
类型:Bool
func toString()
cangjie
public func toString(): String功能:序列化为字符串,如 bytes 0-499/1234、bytes star/1234 或 bytes 0-499/star
返回值:
String- 当前 Content-Range 标头的字符串表示。
func ==(ContentRangeHeaderValue)
cangjie
public operator func ==(other: ContentRangeHeaderValue): Bool功能:比较两个 Content-Range 标头值是否相等。
参数:
- other: ContentRangeHeaderValue - 要比较的 Content-Range 标头值。
返回值:
Bool- 如果两个 Content-Range 标头值相等则返回 true,否则返回 false。
func hashCode()
cangjie
public func hashCode(): Int64功能:返回当前 Content-Range 标头值的哈希值。
返回值:
Int64- 当前 Content-Range 标头值的哈希值。
func parse(String)
cangjie
public static func parse(input: String): ContentRangeHeaderValue功能:解析 Content-Range 字符串,格式非法时抛出异常
参数:
- input:
String- 待解析的 Content-Range 字符串。
返回值:
- ContentRangeHeaderValue - 解析得到的 Content-Range 标头值。
func tryParse(String)
cangjie
public static func tryParse(input: String): ?ContentRangeHeaderValue功能:尝试解析 Content-Range 字符串,返回 None 表示格式无效
参数:
- input:
String- 待解析的 Content-Range 字符串。
返回值:
- ?ContentRangeHeaderValue - 解析成功时返回标头值;失败时返回
None。