Skip to content

Commit

Permalink
test naive polyfill for webstream deflate-raw
Browse files Browse the repository at this point in the history
needed until nodejs/node#50097 is released
  • Loading branch information
pirxpilot committed Oct 10, 2023
1 parent d3c7be1 commit 6663ff9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/deflate-raw.js
Original file line number Diff line number Diff line change
@@ -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;

}
Binary file added test/fixtures/usa.deflated.kmz
Binary file not shown.
9 changes: 9 additions & 0 deletions test/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 6663ff9

Please sign in to comment.