Skip to content

Commit 6663ff9

Browse files
committed
test naive polyfill for webstream deflate-raw
needed until nodejs/node#50097 is released
1 parent d3c7be1 commit 6663ff9

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

test/deflate-raw.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
if (check()) {
2+
polyfill();
3+
}
4+
5+
/* global DecompressionStream */
6+
function check() {
7+
try {
8+
new DecompressionStream('deflate-raw');
9+
return false;
10+
} catch {
11+
// polyfill needed
12+
return true;
13+
}
14+
}
15+
16+
function polyfill() {
17+
const { createInflateRaw } = require('node:zlib');
18+
const { Duplex } = require('node:stream');
19+
20+
class PolyfilledStream extends DecompressionStream {
21+
constructor(format) {
22+
if (format === 'deflate-raw') {
23+
return Duplex.toWeb(createInflateRaw());
24+
}
25+
super(format);
26+
}
27+
}
28+
29+
globalThis.DecompressionStream = PolyfilledStream;
30+
31+
}

test/fixtures/usa.deflated.kmz

1.41 KB
Binary file not shown.

test/import.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const assert = require('node:assert/strict');
44
const fs = require('node:fs');
55
const path = require('node:path');
66

7+
require('./deflate-raw');
8+
79
const parse = require('..');
810

911
function openAsBlob(name) {
@@ -18,6 +20,13 @@ test('should parse kmz', async function () {
1820
assert.deepEqual(trip, expected);
1921
});
2022

23+
test('should parse deflated kmz', async function () {
24+
const blob = await openAsBlob('/fixtures/usa.deflated.kmz');
25+
const trip = await parse(blob);
26+
const expected = require('./fixtures/usa.json');
27+
assert.deepEqual(trip, expected);
28+
});
29+
2130
test('should raise error on a file that contains invalid KML', async function () {
2231
const stream = await openAsBlob('/fixtures/invalid-kml-inside.kmz');
2332
await assert.rejects(parse(stream), /Unclosed tag/i);

0 commit comments

Comments
 (0)