Bug 1809164 - Let the `NetworkManager` code, in PdfJsNetwork.jsm, return TypedArray data. r=pdfjs-reviewers,calixte

Given that the `PdfDataListener.readData` method, in PdfStreamConverter.jsm, always return TypedArray data we update the `NetworkManager` for consistency.
This is done to allow upcoming changes that will enable transferring, rather than copying, more data within the PDF Viewer.

Differential Revision: https://phabricator.services.mozilla.com/D166439
This commit is contained in:
Jonas Jenwald 2023-01-10 19:08:33 +00:00
Родитель e4595e9483
Коммит a518d71e96
1 изменённых файлов: 9 добавлений и 14 удалений

Просмотреть файл

@ -23,23 +23,18 @@ function log(aMsg) {
Services.console.logStringMessage(msg);
}
function getTypedArray(xhr) {
const data = xhr.response;
if (typeof data !== "string") {
return new Uint8Array(data);
}
return Uint8Array.from(data, ch => ch.charCodeAt(0) & 0xff);
}
var NetworkManager = (function NetworkManagerClosure() {
const OK_RESPONSE = 200;
const PARTIAL_CONTENT_RESPONSE = 206;
function getArrayBuffer(xhr) {
var data = xhr.response;
if (typeof data !== "string") {
return data;
}
var length = data.length;
var array = new Uint8Array(length);
for (var i = 0; i < length; i++) {
array[i] = data.charCodeAt(i) & 0xff;
}
return array.buffer;
}
class NetworkManagerClass {
constructor(url, args) {
this.url = url;
@ -181,7 +176,7 @@ var NetworkManager = (function NetworkManagerClosure() {
return;
}
var chunk = getArrayBuffer(xhr);
const chunk = getTypedArray(xhr);
if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
var rangeHeader = xhr.getResponseHeader("Content-Range");
var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);