【问题标题】:XMLHTTPRequest Byte Range RequestXMLHTTPRequest 字节范围请求
【发布时间】:2014-10-08 08:57:00
【问题描述】:

由于我正在通过 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 我想知道如何以字符方式访问请求的文件以构建字符串。这可能是个问题,因为它依赖于字符代码。

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

如何累积接收到的chunk的数据?

我怎样才能为这个请求的数据创建一个字符串甚至 JSON 表示?

【问题讨论】:

    标签: javascript json http byte


    【解决方案1】:
    1. 你不能,除非它是具有固定八位字节与字符比率的字符编码(这对于 JSON 来说不太可能,因为它在大多数情况下是 UTF-8)

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

    3. 您可以尝试跳到根据使用的编码有效的第一个字节序列。 https://www.rfc-editor.org/rfc/rfc3629#section-4 应该有必要的细节。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 2015-04-10
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      相关资源
      最近更新 更多