geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
859 stars 179 forks source link

Range requests retrieve one extra byte #375

Open andreasg123 opened 1 year ago

andreasg123 commented 1 year ago

Range requests request one extra byte because the end of the range is specified as the byte after the range and not the last byte of the range. I could submit a PR if desired but the fix is trivial.

--- a/src/source/remote.js
+++ b/src/source/remote.js
@@ -55,7 +55,7 @@ class RemoteSource extends BaseSource {
       headers: {
         ...this.headers,
         Range: `bytes=${slices
-          .map(({ offset, length }) => `${offset}-${offset + length}`)
+          .map(({ offset, length }) => `${offset}-${offset + length - 1}`)
           .join(',')
         }`,
       },
@@ -111,7 +111,7 @@ class RemoteSource extends BaseSource {
     const response = await this.client.request({
       headers: {
         ...this.headers,
-        Range: `bytes=${offset}-${offset + length}`,
+        Range: `bytes=${offset}-${offset + length - 1}`,
       },
       signal,
     });