From 390c92b2dc0c13de2ebf8851d27eab5e008e4e2c Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Fri, 24 Nov 2023 14:06:52 +0100 Subject: [PATCH] fix: datafiles don't load when content-encoding is used (#18) content-length is not set by Cloudflare when content-encoding is used. So no longer depend on content-length, and just read till the end of the file. --- src/EveDataProvider/EveDataProvider.tsx | 3 +-- src/EveDataProvider/esf_pb2.js | 4 ++++ src/EveDataProvider/protobuf.js | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/EveDataProvider/EveDataProvider.tsx b/src/EveDataProvider/EveDataProvider.tsx index e8d3a03..bc39291 100644 --- a/src/EveDataProvider/EveDataProvider.tsx +++ b/src/EveDataProvider/EveDataProvider.tsx @@ -29,9 +29,8 @@ export interface DogmaDataProps { // eslint-disable-next-line @typescript-eslint/no-explicit-any async function fetchDataFile(dataUrl: string, name: string, pb2: any): Promise { const response = await fetch(dataUrl + name + ".pb2"); - const contentLength = response.headers.get("content-length"); const reader = response.body?.getReader(); - const result = await pb2.decode(reader, contentLength); + const result = await pb2.decode(reader, 0xffffffff); return result.entries; } diff --git a/src/EveDataProvider/esf_pb2.js b/src/EveDataProvider/esf_pb2.js index 71369b1..9e8ae12 100644 --- a/src/EveDataProvider/esf_pb2.js +++ b/src/EveDataProvider/esf_pb2.js @@ -29,6 +29,7 @@ export const esf = $root.esf = (() => { if (r.need_data()) { await r.fetch_data(); } + if (r.is_eof()) break; var t = r.uint32(); switch (t >>> 3) { @@ -214,6 +215,7 @@ export const esf = $root.esf = (() => { if (r.need_data()) { await r.fetch_data(); } + if (r.is_eof()) break; var t = r.uint32(); switch (t >>> 3) { @@ -352,6 +354,7 @@ export const esf = $root.esf = (() => { if (r.need_data()) { await r.fetch_data(); } + if (r.is_eof()) break; var t = r.uint32(); switch (t >>> 3) { @@ -472,6 +475,7 @@ export const esf = $root.esf = (() => { if (r.need_data()) { await r.fetch_data(); } + if (r.is_eof()) break; var t = r.uint32(); switch (t >>> 3) { diff --git a/src/EveDataProvider/protobuf.js b/src/EveDataProvider/protobuf.js index 8dc66af..906a9bc 100644 --- a/src/EveDataProvider/protobuf.js +++ b/src/EveDataProvider/protobuf.js @@ -23,6 +23,7 @@ function Reader(reader) { this._buf = new Uint8Array(); this._next_buf = null; this._buf_pos = 0; + this._eof = false; this.pos = 0; this.len = 0; @@ -57,6 +58,7 @@ Reader.prototype.fetch_data = async function fetch_data() { /* If we read nothing, fast-path into an end-of-file marker. */ if (length === 0) { this._next_buf = new Uint8Array(); + this._eof = true; return; } @@ -75,6 +77,10 @@ Reader.prototype.fetch_data = async function fetch_data() { } } +Reader.prototype.is_eof = function is_eof() { + return this._eof && this._buf_pos >= this._buf.length; +} + Reader.prototype.read = function read(len) { if (this._next_buf === null) return this._buf;