From 6663ff9ac4cb96d31deea670399c63050d50fb3e Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Tue, 10 Oct 2023 21:44:08 +0200 Subject: [PATCH] test naive polyfill for webstream `deflate-raw` needed until nodejs/node#50097 is released --- test/deflate-raw.js | 31 +++++++++++++++++++++++++++++++ test/fixtures/usa.deflated.kmz | Bin 0 -> 1439 bytes test/import.js | 9 +++++++++ 3 files changed, 40 insertions(+) create mode 100644 test/deflate-raw.js create mode 100644 test/fixtures/usa.deflated.kmz diff --git a/test/deflate-raw.js b/test/deflate-raw.js new file mode 100644 index 0000000..de6e7b7 --- /dev/null +++ b/test/deflate-raw.js @@ -0,0 +1,31 @@ +if (check()) { + polyfill(); +} + +/* global DecompressionStream */ +function check() { + try { + new DecompressionStream('deflate-raw'); + return false; + } catch { + // polyfill needed + return true; + } +} + +function polyfill() { + const { createInflateRaw } = require('node:zlib'); + const { Duplex } = require('node:stream'); + + class PolyfilledStream extends DecompressionStream { + constructor(format) { + if (format === 'deflate-raw') { + return Duplex.toWeb(createInflateRaw()); + } + super(format); + } + } + + globalThis.DecompressionStream = PolyfilledStream; + +} diff --git a/test/fixtures/usa.deflated.kmz b/test/fixtures/usa.deflated.kmz new file mode 100644 index 0000000000000000000000000000000000000000..8221492715fc7abf139fcf462dfba4523e5ad9e1 GIT binary patch literal 1439 zcmV;Q1z`G6O9KQH0000805?5@N$$x5F#7}m0Dct!00#gZ0CjU=E^BRURa6N811f1k zSQe&4Sao;{009K(0{{R7=mP)%?O0uJ+cp$^@2?;-Y)_IXi4-Mmc8WAj(E?2y#4Gw} z&=PGEmPCW3>UzI^my+$cTf8`K(|urh2uzW@)II0i4{ETeEA+Xp8Z$hbTf6)jW5KnZ z2Q#H+l?Vz|V_1UYAUZpLhS1=pD%x5!)(v3T@LHUYcw;$wC6JF^C}UMKz}@qHNhwUB z<M9uZ0A8+kuF+*3}SaieP0(9|7G_CN^_B;>0yGB`>gpr3n zj4t+11rxk1wJ_%KR<;|rhHjMH`rC~QrF1D9ZiPAbqc92bn6fgql#o48o5Rzba;j`wMdyV9Nn0)}gL4`s^no)6_|Nzpt%hIc0=<;QLafni z)f$0bh!Xw8>*X)#g%*4<1)(1h%W+#DrI9=i@-R(6@gxlhVI&W~nM4kdfhS5WFodws z;<+q`lrWk{Av(NJ1*qvOph#QGghOz_bCn zRTH7DhpyivmLwTHB{Tu{h=nl?9qd^g<>`~dz83?6o3&MrhAs$1gWCq+D1Bqy(Y~7c zUA3!^a0qu7Ix~#yS zi&zi6;u^hE&=h?Ex#uva;R$eqwxHJlxbu`Tmj8p`KCY?~@{OzNRFz7bE}N{Bu1efE zw0BvgH5^Mw!i|y!7d-=5i%(Ll{3xdxBf;F()sxnMt%OE}6s{KVri3b>msNYH3?w9C zPDt0XTJd%v?i$ZM5j|c#DT8cJHtNZeqk7H%wtBd&xKR^RfCHU|mX1S%H}Zih({ttn zXHaoAoIRaZZlSHZRchMx3zw=YSNw3g`3S;RtBHm>fZp=PsbjkXdW1I!dKU^t~-#;tfQl=>JY>bvL$o@&>pzbUu@m%V)r?Rs!u45$di^^xJwE9 z+W{(K>M}pNmE}yJ+Y()Q=)%k`pR^VC(EHbqB_M=YjUt+Mg*9a)q5of>9=JZyER7#Z z4__sKt9rtXS#KKn&DRS2kym!k>qCh=3DHOCT83Tcwb=j>dV!!1Pfq%BkVXOYnPHT8 zG!96fGoG?RO2-rKqapPMj&kPCED2h5}XhzfcUsq;n`VC`OG{H(PXGlAca3eH`~p-z$Z?1t&&onB-|nIz7Opog8&X`orskzq@az1NTw&{MqkNO928N z0~7!N00;m#J%dT^$pbL^1ONbj6#xJS02lxO000010002AfdBvi0CjU=E^BRURa6B4 t11f1kSao;{009K(0{{R7=mP)%P)h{{000000RRC2O#lD@JOuy%000mriv$1w literal 0 HcmV?d00001 diff --git a/test/import.js b/test/import.js index 09d9a1e..3044c7e 100644 --- a/test/import.js +++ b/test/import.js @@ -4,6 +4,8 @@ const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); +require('./deflate-raw'); + const parse = require('..'); function openAsBlob(name) { @@ -18,6 +20,13 @@ test('should parse kmz', async function () { assert.deepEqual(trip, expected); }); +test('should parse deflated kmz', async function () { + const blob = await openAsBlob('/fixtures/usa.deflated.kmz'); + const trip = await parse(blob); + const expected = require('./fixtures/usa.json'); + assert.deepEqual(trip, expected); +}); + test('should raise error on a file that contains invalid KML', async function () { const stream = await openAsBlob('/fixtures/invalid-kml-inside.kmz'); await assert.rejects(parse(stream), /Unclosed tag/i);