Skip to content

Commit 234254c

Browse files
Merge pull request #451 from Rdataflow/feat--add_zstd
2 parents 12af432 + 120b145 commit 234254c

File tree

7 files changed

+40
-11
lines changed

7 files changed

+40
-11
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ module.exports = {
4242
'max-classes-per-file': 0,
4343
'max-len': ['error', { code: 130 }],
4444
'import/prefer-default-export': 0,
45-
'import/extensions': ['error', 'always'],
45+
'import/extensions': 0,
46+
'import/no-unresolved': 0,
4647
'prefer-default-export': 0,
4748
'func-names': 0,
4849
'arrow-body-style': 0,

package-lock.json

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"quick-lru": "^6.1.1",
9090
"web-worker": "^1.5.0",
9191
"xml-utils": "^1.10.2",
92-
"zstddec": "^0.1.0"
92+
"zstddec": "^0.2.0-alpha.3"
9393
},
9494
"devDependencies": {
9595
"@babel/core": "^7.8.7",

src/compression/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,11 @@ addDecoder(34887, () => import('./lerc.js')
6161
})
6262
.then((m) => m.default),
6363
);
64+
addDecoder(50000, () => import('./zstd.js')
65+
.then(async (m) => {
66+
await m.zstd.init();
67+
return m;
68+
})
69+
.then((m) => m.default),
70+
);
6471
addDecoder(50001, () => import('./webimage.js').then((m) => m.default), false);

src/compression/zstd.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ZSTDDecoder } from 'zstddec/stream';
2+
import BaseDecoder from './basedecoder.js';
3+
4+
export const zstd = new ZSTDDecoder();
5+
6+
export default class ZstdDecoder extends BaseDecoder {
7+
decodeBlock(buffer) {
8+
return zstd.decode(new Uint8Array(buffer)).buffer;
9+
}
10+
}

test/data/setup_data.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ gdal_translate -of GTiff -co COMPRESS=LERC -co MAX_Z_ERROR=1000 stripped.tiff le
2626
gdal_translate -of GTiff -co COMPRESS=LERC -co MAX_Z_ERROR=1000 -co INTERLEAVE=BAND stripped.tiff lerc_interleave.tiff
2727
gdal_translate -of GTiff -co COMPRESS=LERC_DEFLATE -co MAX_Z_ERROR=1000 stripped.tiff lerc_deflate.tiff
2828
gdal_translate -of GTiff -co COMPRESS=LERC_ZSTD -co MAX_Z_ERROR=1000 stripped.tiff lerc_zstd.tiff
29+
gdal_translate -of GTiff -co COMPRESS=ZSTD stripped.tiff zstd.tiff
2930
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC -co MAX_Z_ERROR=1000 stripped.tiff float32lerc.tiff
3031
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC -co MAX_Z_ERROR=1000 -co INTERLEAVE=BAND stripped.tiff float32lerc_interleave.tiff
3132
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC_DEFLATE -co MAX_Z_ERROR=1000 stripped.tiff float32lerc_deflate.tiff
3233
gdal_translate -of GTiff -ot Float32 -co COMPRESS=LERC_ZSTD -co MAX_Z_ERROR=1000 stripped.tiff float32lerc_zstd.tiff
34+
gdal_translate -of GTiff -ot Float32 -co COMPRESS=ZSTD stripped.tiff float32zstd.tiff
3335

3436
gdal_translate -of COG initial.tiff cog.tiff
3537

test/geotiff.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ describe('GeoTIFF', () => {
298298
await performTiffTests(tiff, 539, 448, 15, Uint16Array);
299299
});
300300

301+
it('should work on Zstandard compressed tiffs', async () => {
302+
const tiff = await GeoTIFF.fromSource(createSource('zstd.tiff'));
303+
await performTiffTests(tiff, 539, 448, 15, Uint16Array);
304+
});
305+
301306
it('should work on Float32 and LERC compressed tiffs', async () => {
302307
const tiff = await GeoTIFF.fromSource(createSource('float32lerc.tiff'));
303308
await performTiffTests(tiff, 539, 448, 15, Float32Array);
@@ -318,6 +323,11 @@ describe('GeoTIFF', () => {
318323
await performTiffTests(tiff, 539, 448, 15, Float32Array);
319324
});
320325

326+
it('should work on Float32 and Zstandard compressed tiffs', async () => {
327+
const tiff = await GeoTIFF.fromSource(createSource('float32zstd.tiff'));
328+
await performTiffTests(tiff, 539, 448, 15, Float32Array);
329+
});
330+
321331
it('should work with worker pool', async () => {
322332
const testPool = new Pool();
323333
const tiff = await GeoTIFF.fromSource(createSource('nasa_raster.tiff'));

0 commit comments

Comments
 (0)