XMLHTTPRequest字节范围请求

时间:2014-10-08 08:57:00

标签: javascript json http byte

由于我通过XHTTPRequest(由Google Closure XhrIo提供)下载了一个巨大的JSON文件(> 10 MB),我想使用字节范围请求只下载部分数据:

3.12 Range Units

HTTP/1.1 allows a client to request that only part (a range of) the response entity be included within the response. HTTP/1.1 uses range units in the Range (section 14.35) and Content-Range (section 14.16) header fields. An entity can be broken down into subranges according to various structural units.

  range-unit       = bytes-unit | other-range-unit
  bytes-unit       = "bytes"
  other-range-unit = token

The only range unit defined by HTTP/1.1 is "bytes". HTTP/1.1 implementations MAY ignore ranges specified using other units.

因为唯一定义的range-unitbytes我想知道如何以字符形式访问所请求的文件以构建字符串。这可能是一个问题,因为它依赖于char代码。

如何计算所请求文件的字符集的字节范围,以便以字符形式访问文件?

如何累积收到的块的数据?

如何创建此请求数据的字符串甚至JSON表示?

1 个答案:

答案 0 :(得分:0)

1)你不能,除非它是一个具有固定八位字符比特率的字符编码(这对于JSON不太可能,因为在大多数情况下它将是UTF-8)

2)好吧,作为字节数组: - )

3)您可以尝试跳转到根据所使用的编码有效的第一个字节序列。 http://tools.ietf.org/html/rfc3629#section-4应该有必要的细节。

相关问题