Skip to content

Commit

Permalink
refactor: use native TextDecoderStream if available
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-ext committed Sep 16, 2024
1 parent 131c53b commit 016b2de
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils/stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://github.com/oven-sh/bun/issues/5648#issuecomment-1824093837
export class TextDecoderStream extends TransformStream<Uint8Array, string> {
class TextDecoderStreamPolyfill extends TransformStream<Uint8Array, string> {
readonly encoding: string;
readonly fatal: boolean;
readonly ignoreBOM: boolean;
Expand Down Expand Up @@ -28,6 +28,10 @@ export class TextDecoderStream extends TransformStream<Uint8Array, string> {
}
}

const TDS = typeof TextDecoderStream !== 'undefined' ? TextDecoderStream : TextDecoderStreamPolyfill;

export { TDS as TextDecoderStream };

export class LineBreakStream extends TransformStream<string, string> {
constructor() {
let current = '';
Expand Down

0 comments on commit 016b2de

Please sign in to comment.