-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test naive polyfill for webstream
deflate-raw
needed until nodejs/node#50097 is released
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters